Hi George,
 i've done a quick test and it doesnt work on my code, but i will do a full
test by tomorrow. Only one question: which object are you using in the
ajaxformloop (in the tml code)? pr or prPersist?

Regards and thanks!

------------------------------------------------------------------
David Germán Canteros


2012/3/19 George Christman <gchrist...@cardaddy.com>

> David, I have a working work around, I'm sure it's not the best, but does
> work. See code below.
>
>    @Persist
>    private PurchaseRequest prPersist;
>
>    private PurchaseRequest pr;
>
>    private final String NEW_OBJ = "new";
>
>    void onActivate() {
>        if(prPersist != null) {
>            for(LineItem _lineItem : prPersist.getLineItems()) {
>                if(_lineItem.getId() == null ||
> !pr.getLineItems().contains(_lineItem)) {
>                    _lineItem.setPurchaseRequest(pr);
>                    pr.getLineItems().add(_lineItem);
>                }
>            }
>        }
>       prPersist = null;
>    }
>
>    void onValidateFromPR() {
>        if (form.getHasErrors()) {
>            prPersist = pr;
>        }
>    }
>
>    //Modified Geoff's value encoder.
>    @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;
>
>                if (!idAsString.equals(NEW_OBJ)) {
>                    Long id = new Long(idAsString);
>                    lineItem = (LineItem) session.get(LineItem.class, id);
>                }
>
>                // AjaxFormLoop can't handle null obj, so if null we return
> a new empty obj.
>                lineItem = lineItem == null ? new LineItem() : lineItem;
>
>                if (!request.isXHR()) {
>                    lineItem.setPurchaseRequest(pr);
>                    pr.getLineItems().add(lineItem);
>                }
>
>                return lineItem;
>            }
>        };
>    }
>
> Hope this helps.
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Server-Side-Validation-with-ajax-form-loop-tp5120576p5577886.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