I couldn't comprehend all your code but could you encoder be called once
for decoding the read Id from the client(browser) to a LineItem and once
for encoding LineItems to Ids to be sent to the client ?

On Fri, Sep 14, 2012 at 7:41 PM, George Christman
<gchrist...@cardaddy.com>wrote:

> Hello, perhaps this is normal behavior although it wouldn't any sense to
> me,
> but my value encoder seems to be called twice for every new row added to
> the
> AjaxAddRow component. Is this normal? I'm not sure why it is happening.
> Sample code.
>
> .tml
>
> <div t:type="ajaxFormLoop" t:id="lineItem" source="pr.lineItems"
> value="lineItem" show="show" encoder="encoderLineItem">
>                 <t:submitnotifier>
>                     <t:hidden value="lineItem.sequenceNumber"/>
>                     <t:TextField value="lineItem.quantity"/>
>                     <t:TextField
> value="lineItem.description"/><t:removerowlink>Remove</t:removerowlink>
>                 </t:submitnotifier>
>                 <p:addRow>
>                     <t:addrowlink>Add a row</t:addrowlink>
>                 </p:addRow>
>             </div>
>
> java.class
>
>     void onActivate(String prId) throws Exception {
>         Long id;
>         try {
>             id = Long.parseLong(prId);
>         } catch (NumberFormatException e) {
>             //TODO HANDLE THIS
>             throw new NumberFormatException("Bad url parameters " + e);
>         }
>
>         //Queries for existing purchase request.
>         //We are ignoring ajax request and only allowing valid form
> submissions
>         //without serverside validation errors to pass through.
>         if(form.isValid()) {
>             this.pr = this.purchaseRequestService.find(id);
>
>             if(this.pr == null) {
>                 //TODO HANDLE THIS
>                 throw new Exception("Pr doesn't exist.");
>             }
>         }
>     }
>
>     Object onPassivate() {
>         Object value = null;
>         if (this.pr != null) {
>             value = this.pr.getId();
>         }
>         return value;
>     }
>
>     void onPrepareFromPr() {
>         if (form.isValid() && this.pr == null) {
>             this.pr = new PurchaseRequest();
>         } else if(!form.isValid()) {
>             this.pr = this.prReconstruction;
>         }
>
>     }
>
>
>     public LineItem getLineItem() {
>         return lineItem;
>     }
>
>     public void setLineItem(LineItem lineItem) {
>         this.lineItem = lineItem;
>
>         if (isSubmitAction) {
>             if(lineItem.getId() == null) {
>                 this.pr.getLineItems().add(lineItem);
>             }
>             this.lineItem.setHoldItem(true);
>         }
>     }
>
>     LineItem onAddRowFromLineItem() {
>         return new LineItem();
>     }
>
>     void onRemoveRowFromLineItem(LineItem lineItem) {
>         //Do Nothing
>     }
>
>     public ValueEncoder getEncoderLineItem() {
>         System.out.println("Value Encoder");
>         return new ValueEncoder<LineItem>() {
>             public String toClient(LineItem value) {
>                 System.out.println("toClientId " + value);
>                 if (value.getId() != null) {
>                     return value.getId().toString();
>                 }
>                 return value.getTempId().toString();
>             }
>
>             public LineItem toValue(String clientValue) {
>                 Long id = new Long(clientValue);
>                 if (id > 0) {
>                     for(LineItem lineItem : pr.getLineItems()) {
>                         if(lineItem.getId().equals(id)) {
>                             return lineItem;
>                         }
>                     }
>                 }
>                 return new LineItem(pr);
>             }
>         };
>     }
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Value-encoder-toClient-called-twice-for-each-request-tp5716275.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to