Thanks for your input. I replaced it with 'For' but
that made it blow up on trying to submit the first
line item, not the second :( I must be missing
something really fundamental. Any help is appreciated!
--- Mind Bridge <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I cannot look at your message in details at the
> moment (perhaps someone
> else can), but the following stands out:
>
> <component id="lineitems" type="Foreach">
>
> Replace 'Foreach' with a 'For'. The 'For' component
> is like 'Foreach'
> (see doc), but if in a form, it automatically stores
> information about
> the iterations performed in hidden fields.
> StaleLinkException does not
> occur as a result upon submission.
>
> Andrew B wrote:
> > Hi,
> >
> > I am using Tapestry 4. I am getting a
> StaleLinkError
> > when I attempt to submit a form. Briefly, the form
> > consists of invoice details. All the line items
> are
> > listed under the invoice, as editable fields.
> Also,
> > there is an empty line item at the bottom, and if
> data
> > has been entered into those fields, a new LineItem
> > object is created when the form is submitted, and
> > appended to the Invoice's LineItems list to be
> > displayed. The new LineItem fields are properties
> of a
> > LineItem object, accessible from Home via its
> > NewLineItem property.
> >
> > It works OK for adding one new line item. The form
> > submits, and re-renders with the new line item
> shown.
> > If you try to submit it with a second one, though,
> it
> > fails with the StaleLinkException.
> >
> > The Invoice and LineItem classes are just beans
> with
> > properties, so I won't list those.
> >
> > Page class:
> >
> > public abstract class Home extends BasePage
> > {
> > private Invoice invoice;
> > private LineItem newLineItem;
> > private LineItem deletedLineItem;
> >
> > public LineItem getDeletedLineItem()
> > {
> > return deletedLineItem;
> > }
> >
> > public void setDeletedLineItem(LineItem
> > deletedLineItem)
> > {
> > this.deletedLineItem = deletedLineItem;
> > }
> >
> > public abstract IInvoiceDao getInvoiceDao();
> >
> > public LineItem getNewLineItem()
> > {
> > if (newLineItem == null)
> > newLineItem = new LineItem();
> > return newLineItem;
> > }
> >
> > public Invoice getInvoice()
> > {
> > if (invoice == null)
> > {
> > invoice = new Invoice();
> > invoice.setLineItems(new HashSet());
> > }
> > return invoice;
> > }
> >
> > public void formSubmit(IRequestCycle cycle)
> > {
> > if (newLineItem.isPopulated())
> > {
> > invoice.getLineItems().add( newLineItem );
> > newLineItem.setInvoice(invoice);
> > newLineItem = new LineItem();
> > }
> >
> > if (deletedLineItem != null)
> > removeDeletedItem();
> > }
> >
> > private void removeDeletedItem()
> > {
> > Iterator it = invoice.getLineItems().iterator();
> > while (it.hasNext())
> > if ( ((LineItem)it.next()) == deletedLineItem )
> > {
> >
> invoice.getLineItems().remove(deletedLineItem);
> > deletedLineItem = null;
> > }
> > }
> > public void setNewLineItem(LineItem newLineItem)
> > {
> > this.newLineItem = newLineItem;
> > }
> >
> > }
> >
> > Home.html:
> >
> > <html>
> > <form jwcid="invoiceForm">
> > <table>
> > <tr>
> > <td>Amount:</td><td><input type="text"
> > jwcid="amount" /></td>
> > <td>Order Person:</td><td><input type="text"
> > jwcid="orderPerson" /><td>
> > <td>Car Number:</td><td><input type="text"
> > jwcid="carNumber" /></td>
> > </tr>
> > </table>
> >
> > <br/>
> > <b>Line Items</b>
> > <table>
> > <tr>
> > <th>Part Number</th>
> > <th>Quantity</th>
> > <th>Unit Cost</th>
> > </tr>
> > <tr jwcid="lineitems" element="tr">
> > <td><input type="text"
> jwcid="partNumber"/></td>
> > <td><input type="text" jwcid="quantity"/></td>
> > <td><input type="text" jwcid="unitCost"
> /></td>
> > <td width="10%"><input type="submit"
> > jwcid="deleteItem"/></td>
> > </tr>
> > <tr>
> > <td><input type="text"
> > jwcid="newPartNumber"/></td>
> > <td><input type="text"
> jwcid="newQuantity"/></td>
> > <td><input type="text" jwcid="newUnitCost"
> /></td>
> > </tr>
> > </table>
> > <input type="submit" value="Save" />
> >
> > </form>
> > </html>
> >
> >
> > Home.page:
> >
> > <?xml version="1.0"?>
> > <!DOCTYPE page-specification PUBLIC "-//Apache
> > Software Foundation//Tapestry Specification
> 4.0//EN"
> >
>
"http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
> > <page-specification class="com.gett.subbill.Home">
> >
> > <!-- Invoice input fields -->
> > <component id="amount" type="TextField">
> > <binding name="value"
> > value="ognl:invoice.amount" />
> > </component>
> >
> > <component id="invoiceForm" type="Form">
> > <binding name="listener"
> > value="listener:formSubmit" />
> > </component>
> >
> > <component id="orderPerson" type="TextField">
> > <binding name="value"
> > value="ognl:invoice.orderPerson" />
> > </component>
> >
> > <component id="carNumber" type="TextField">
> > <binding name="value"
> > value="ognl:invoice.carNumber" />
> > </component>
> >
> > <!-- Line item loop -->
> > <component id="lineitems" type="Foreach">
> > <binding name="source"
> > value="ognl:invoice.lineItems" />
> > <binding name="value" value="ognl:item" />
> > </component>
> >
>
=== message truncated ===
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]