You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2012/09/14 19:41:42 UTC

Value encoder toClient called twice for each request

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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Value encoder toClient called twice for each request

Posted by Muhammad Gelbana <m....@gmail.com>.
Also tapestry is still implementing the redirect after post mechanism so, I
think this could explain the behavior you are having.

On Sat, Sep 15, 2012 at 9:55 AM, Muhammad Gelbana <m....@gmail.com>wrote:

> 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 <gchristman@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-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

Re: Value encoder toClient called twice for each request

Posted by Muhammad Gelbana <m....@gmail.com>.
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
<gc...@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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Value encoder toClient called twice for each request

Posted by George Christman <gc...@cardaddy.com>.
I figured out why the value encoder is called twice, however I'm not certain
if this is normal behavior. The value encoder is only called once when I
don't use the removerowLink in my ajaxformloop, however as soon as I add it
in it is then called twice. Is this normal? Example with removerowlink. 


ValueEncoder console outputs.

//onAddRowFromLineItem() {
addLineItem


//ValueEncoder getEncoderLineItem() is called twice for each new row. 

return value encoder
toClient LineItem{id=null, quantity=null, unitPrice=null,
purchaseRequest=null}
return value encoder
toClient LineItem{id=null, quantity=null, unitPrice=null,
purchaseRequest=null}



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Value-encoder-toClient-called-twice-for-each-request-tp5716275p5716378.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org