Results 1 to 7 of 7

Thread: Submitting arrays

  1. #1
    Join Date
    Oct 2007
    Posts
    2

    Default Submitting arrays

    I want to edit a Quiz objects properties, the properties are nested arraylists. I use a MultiActionController.

    In the jsp i use a c:foreach loop to create text input fields:
    HTML Code:
    <c:forEach items="${command.questions}" var="q" varStatus="status">
      ${status.index}.<form:input path="questions[${status.index}].question"/>
      <br><br>
      Options:
      <c:forEach items="${q.answers}" var="a" varStatus="index">
        <form:input path="questions[${status.index}].answers[${index.index}].answer"/>
         <br>
      </c:forEach>
    </c:forEach>
    which works great, the input fields are printed and filled with the correct value from the object.

    My problem is how to submit these values back to the controller, I just cannot get it to work! I assumed springs binding would deal with the indexed property names, but it seems not to understand how to apply the indexes to an ArrayList.

    Any suggestions on how to bind these parameters back into the Quiz object?

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    My problem is how to submit these values back to the controller, I just cannot get it to work! I assumed springs binding would deal with the indexed property names, but it seems not to understand how to apply the indexes to an ArrayList.
    wonderful pain right?

    i never resolve this, even with my post asking almost the same question

    my solution?
    ajax for each row
    could be silly,
    but
    for my network control for prices and stocks about warehouse for my articles works fine
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Oct 2007
    Location
    Indianapolis, IN
    Posts
    62

    Default Try LazyList

    In your model class, define the List as below:

    Code:
    private List someList = LazyList.decorate(new ArrayList(), FactoryUtils.instantiateFactory(com.abc.xyz.SomeClass.class));
    SomeClass is the class that holds each record that you are trying to put at each index.

    If you are using ArrayList as your command object, then do the following in your formBackingObject()

    Code:
    return LazyList.decorate(new ArrayList(), FactoryUtils.instantiateFactory(com.abc.xyz.SomeClass.class));
    Any of the above should do the job for you.

    To use LazyList and FactoryUtils, you would need to put commons-collection.jar in your classpath.

    Regards,
    Smruti..

  4. #4
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello smrutimo

    do you have some link or reference tutorial about your solution?

    thanks in advanced
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  5. #5
    Join Date
    Oct 2007
    Location
    Indianapolis, IN
    Posts
    62

    Default

    Quote Originally Posted by dr_pompeii View Post
    Hello smrutimo

    do you have some link or reference tutorial about your solution?

    thanks in advanced
    Here u go http://mattfleming.com/node/134

    Regards,
    Smruti..

  6. #6
    Join Date
    Oct 2007
    Posts
    2

    Thumbs up Brilliant!

    Thank you so much for the help smrutimo! This worked straight away!

  7. #7
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    thanks for the link smrutimo

    pretty help

    best wishes
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •