can <xapp:elementaction type="insertafter"> insert more than

X-Application Version: 3.1.3, 3.1.2, 3.1.1
Tamino Version : 3.1.1
Platform : NT, Win2k, Solaris, …
WebContainer : Tomcat 3.3
JDK Version : 1.3.1

Hello,
I am updating a subtree of an XML document called Invoice.
The DTD looks something like this:

Invoice(InvoiceHeader, InvoiceDetail*)
InvoiceHeader(…)
InvoiceDetail(Amount, AccountKeys)
Amount(PCDATA)
AccountKeys(Key*)

Here is a sample


1000

111
222
333
444




I am using xapp:loop to edit and elements and I use <xapp:elementaction type=“insertafter”> to insert new elements.

Is it possible to insert an element InvoiceDetail like the one above with just one click, instead of having the user to click a button 4 times which inserts element?

Best regards
eagle

Hello,

the standard functionality of X-Application inserts only one element if an element action ?insertBefore? or ?insertAfter? is invoked.

However, you can change this behavior or extend the set element actions by a Plugin. In your case you could implement a Plugin that inserts a predefined InvoiceDetail into your Invoice. The steps you have to do are

1. Implement a method that implements this functionality, e.g.

<BR>pcakge invoice;<BR><BR>import com.softwareag.xtools.xapplication.common.Util;<BR>import java.util.List;<BR>import org.jdom.Element;<BR>import org.jdom.JDOMException;<BR><BR>public class InvoicePlugin {<BR>...<BR>  public static void insertInvoiceDetailBefore(Element invoiceDetail) {<BR>    try {<BR>        List details = invoiceDetail.getParent().getChildren("InvoiceDetail");<BR>        int index = details.indexOf(invoiceDetail);<BR>        Element detail = Util.stringToElement("<InvoiceDetail>....</InvoiceDetail>");<BR>        details.add(index, detail);<BR>    } catch (JDOMException e) {<BR>        throw new RuntimeException("programming error when defining the new element: " + e);<BR>    }<BR>  }<BR>...<BR>}<BR></pre><BR><BR>2.	Register the element action for the InvoiceDetail within the xapplication.xml, e.g.<BR><BR><pre class="ip-ubbcode-code-pre"><BR>    <plugins><BR>        <element name=?InvoiceLine?><BR>            <action name="insertNewDetail"<BR>                    method="invoice.InvoicePlugin. insertInvoiceDetailBefore"><BR>            </action><BR>        </element>     <BR>    </plugins><BR></pre><BR><BR>3.	Use the element action within your JSP instead of insertBefore, e.g.<BR><BR><pre class="ip-ubbcode-code-pre"><BR><xapp:loop ... iterate=?InvoiceDetail? ...><BR>   <xapp:elementaction type=? insertNewDetail? select=?.?>...</xapp:elementaction><BR></xapp:loop><BR>



To get more information about Plugins have a look at
- the documentation chapter about Plugins
- the implementation of the standard Plugins
- the Plugin examples.

Bye,
Christian.

Thank you very much for your reply.
This works.

Best regards
eagle