Hello, I'm using the ajaxformloop component with a value encoder similar to
jumpstarts AjaxFormLoop Tailored version. The component works flawlessly
when there is no server side errors to return, however when server side
errors exist and the form is returned, my main pr object looses all the
ajaxformloop values that haven't yet been committed to the db. 

Is there way for the onValidate method to return my pr object without losing
the lineItem values and without persisting any of the data?

Please see code below. 

            <t:AjaxFormLoop t:id="lineItem" element="ul"
source="pr.lineItems" value="lineItem" addRow="block:addRow" show="show"
encoder="encoderLineItem">
                                <t:Label
for="quanity">QTY</t:Label><t:TextField disabled="roleManager.disabled"
title="Quantity" t:id="quanity" class="number qty"
value="lineItem.quanity"/>
</t:AjaxFormLoop>


   @OnEvent(EventConstants.ACTIVATE)
    void setupRender() {
        if (this.pr == null) {
            this.pr = new PurchaseRequest();
        } 
}

   void onValidateFromPR() throws Exception  {
//errors to return 
form.recordError(message + fieldName);
}

    @CommitAfter
    Object onSuccess() {
        session.saveOrUpdate(pr);
}

   @SuppressWarnings("unchecked")
    public ValueEncoder getEncoderLineItem() {
        return new ValueEncoder<LineItem>() {

            public String toClient(LineItem value) {
                Long id = value.getId();
                return id == null ? NEW_OBJ : id.toString();
            }

            public LineItem toValue(String idAsString) {
                LineItem lineItem = null;
                Long id = null;

                if (!idAsString.equals(NEW_OBJ)) {
                    id = new Long(idAsString);
                }

                // If new obj, return an empty obj.
                if (id == null) {
                    lineItem = new LineItem();

                    if (!request.isXHR()) {
                        pr.getLineItems().add(lineItem);
                    }
                } // Else, return existing obj
                else {
                    lineItem = (LineItem) session.get(LineItem.class, id);
                }

                // AjaxFormLoop will overwrite several fields of the obj
returned.
                // AjaxFormLoop can't handle null obj, so if null we return
a new empty obj.
                lineItem = lineItem == null ? new LineItem() : lineItem;
                lineItem.setPurchaseRequest(pr);

                return lineItem;
            }
        };
    }


Thanks. 



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Server-Side-Validation-with-ajax-form-loop-tp5120576p5120576.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