On each Loop, try formstate="iteration". Here's an example:

        
http://jumpstart.doublenegative.com.au/jumpstart/examples/tables/editableloop1
        
And for T5.4:

        
http://jumpstart.doublenegative.com.au/jumpstart7/examples/tables/editableloop1

Cheers,

Geoff

On 16/04/2014, at 12:30 AM, Tony Nelson wrote:

> I am trying to build a form where there are N instances of a custom editing 
> component.  For example, something simple like:
> 
> <t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd";>
> 
>    ${idx} :
>    Id: <t:textfield value="domainObj.id" validate="maxLength=5" maxlength="5" 
> /> :
>    B: <t:textfield value="domainObj.a" validate="maxlength=10" maxlength="10" 
> />
>    <br/>
> 
> </t:container>
> 
> The component Java code is trivial:
> 
> public class EditObject {
> 
>    @Property
>    @Parameter(required = true)
>    SimplePojo domainObj;
> 
>    @Property
>    @Parameter(required = false, value = "0")
>    Integer idx;
> 
>    void onValidate() {
>        log.info("EditObject onValidate: " + domainObj);
>    }
> }
> 
> 
> There is no AJAX, just a simple posted form.
> 
> This component is used like this:
> 
> <!DOCTYPE html>
> <html
>        xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd";
>> 
> <head>
>    <title>Multiple components in a loop</title>
> </head>
> <body>
> <t:form t:id="myForm">
> 
>    <h3>Group A</h3>
>    <t:loop source="groupA" value="domainObj" index="idx" element="div">
>        <t:EditObject domainObj="domainObj" idx="idx"/>
>    </t:loop>
> 
>    <h3>Group B</h3>
>    <t:loop source="groupB" value="domainObj" index="idx" element="div">
>        <t:EditObject domainObj="domainObj" idx="idx"/>
>    </t:loop>
> 
>    <t:submit value="Submit"/>
> </t:form>
> </body>
> </html>
> 
> The main controller is very simple:
> 
> public class MultiDemo {
>    @Inject
>    private Logger logger;
> 
>    @Property
>    List<SimplePojo> groupA;
> 
>    @Property
>    List<SimplePojo> groupB;
> 
>    @Property
>    SimplePojo domainObj;
> 
>    @Property
>    Integer idx;
> 
>    @Log
>    void onValidateFromMyForm() {
>        for (SimplePojo sp : groupA) {
>            logger.info("A: " + sp.toString());
>        }
> 
>        for (SimplePojo sp : groupB) {
>            logger.info("B: " + sp.toString());
>        }
>    }
> 
>    @Log
>    void setupRender() {
>        createGroups();
>    }
> 
>    @Log
>    void onPrepare() {
>        // if this is commented out, I get a NPE in onValidateFromMyForm
>        createGroups();
>    }
> 
>    void createGroups() {
>        groupA = createGroup();
>        groupB = createGroup();
>    }
> 
>    List<SimplePojo> createGroup() {
> 
>        List<SimplePojo> result = new ArrayList<SimplePojo>();
>        for (int i = 0; i < 3; i++) {
>            result.add(new SimplePojo());
>        }
> 
>        return result;
>    }
> }
> 
> That's it, the whole page.  But I just can't get it to work.
> 
> If I comment out onPrepare() I get a NPE in the onValidateFromMyForm, which 
> makes sense.  With it uncommented, onValidateFromMyForm is always new null 
> filled objects.
> 
> The logging in the component onValidate shows domainObj.id being set, but 
> never domainObj.A.
> 
> When the form redraws, it loses any values I typed in and is blank again.
> 
> I'm missing something obvious I'm sure, but can't see what it is.
> 
> Any help would be greatly appreciated.
> 
> Thanks
> Tony
> 
> Since 1982, Starpoint Solutions has been a trusted source of human capital 
> and solutions. We are committed to our clients, employees, environment, 
> community and social concerns.  We foster an inclusive culture based on 
> trust, respect, honesty and solid performance. Learn more about Starpoint and 
> our social responsibility at http://www.starpoint.com/social_responsibility
> 
> This email message from Starpoint Solutions LLC is for the sole use of  the 
> intended recipient(s) and may contain confidential and privileged  
> information.  Any unauthorized review, use, disclosure or distribution is 
> prohibited.  If you are not the intended recipient, please contact the sender 
> by reply email and destroy all copies of the original message.  Opinions, 
> conclusions and other information in this message that do not relate to the 
> official business of Starpoint Solutions shall be understood as neither given 
> nor endorsed by it.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 


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

Reply via email to