Results 1 to 5 of 5

Thread: Iterating over a list and make some fields editable

  1. #1
    Join Date
    Aug 2004
    Location
    Southern Germany
    Posts
    30

    Default Iterating over a list and make some fields editable

    I need some advice doing the following:

    - I want to display a list of projects (retrieved from Hibernate), I need to iterate over this list
    - some attributes of each project int the list need to be displayed (name, description, etc)
    - each project contains tasks
    - the user should be able to edit attributes of the tasks, so a form is necessary
    - validation is necessary

    What is he best strategy to do this ? It's easy to achieve this when editing the tasks
    of a single project (spring:bind) but not when iterating over all of the projects.

    Which type of controller should I use (Controller/SimpleFormController), where should
    the project list be loaded (method) and which is my command class/command object
    (the list of projects or a single project) ?

    I've tried several strategies but none of them worked when using the whole project list
    on one form. The jPetStore example contains something similar (Shopping Cart) but is
    incomplete because it doesn't use validation with information for the user.
    Regards,
    Lars Fischer
    http://j2ux.blogspot.com

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    If you need a form with an editable collection see:
    http://opensource.atlassian.com/proj.../browse/SPR-52

  3. #3
    Join Date
    Aug 2004
    Location
    Southern Germany
    Posts
    30

    Default

    OK, thanks for the hint !

    This is Jürgen's solution:

    Code:
    <c&#58;forEach items="$&#123;person.addresses&#125;" var="address" varStatus="loopStatus">
    
    <spring&#58;bind path="person.addresses&#91;$&#123;loopStatus.index&#125;&#93;.street">
    Street&#58; <input type="text" name="<%= status.getExpression&#40;&#41; %>" value="<%= status.getDisplayValue&#40;&#41; %>">
    </spring&#58;bind>
    <p>
    
    <spring&#58;bind path="person.addresses&#91;$&#123;loopStatus.index&#125;&#93;.zip">
    Zip&#58; <input type="text" name="<%= status.getExpression&#40;&#41; %>" value="<%= status.getValue&#40;&#41; %>">
    </spring&#58;bind>
    <p>
    
    </c&#58;forEach>
    This results in a name for the text field like:

    person.adresses[1].zip

    Now what about validation ? If you want to reject a specific field value you somehow have to generate the field name like

    Code:
    errors.rejectValue&#40;"person.adresses&#91;1&#93;.zip" ...
    Is there a better solution for this ?
    Regards,
    Lars Fischer
    http://j2ux.blogspot.com

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    That's a good question. I don't think there is. If you are doing complex checks, your approach is probably the way to go. If you want to do simple checks for valid formats, you can register a new property editor. This validation would then be done automatically for you. The code in your form class would be something like:
    Code:
        protected void initBinder&#40;HttpServletRequest request,
            ServletRequestDataBinder binder&#41; &#123;
            ZipPE = new ZipPE&#40;"some format", false&#41;;
            binder.registerCustomEditor&#40;ZipData.class, null,
                new ZipPE&#40;&#41;&#41;;
        &#125;
    Take a look at Spring's CustomDateEditor if you want a sample.

  5. #5
    Join Date
    Dec 2004
    Posts
    4

    Default

    I’m attempting to apply Juergen’s solution for indexed names and values for text boxes to checkboxes. See
    <a href="http://opensource.atlassian.com/projects/spring/browse/SPR-52">JIRA entry</a>

    And I’m trying to use these checkboxes within a wizard. So I have the problem of determining whether a particular checkbox is ‘checked’ or not.

    Within the checkbox the portion
    <c:if test=” <%=status.getValue()% ==true”> won’t accept a formula
    so I don’t see how access the status value if I don’t have access to it’s name or value.
    Anybody have some ideas?

    Related, how would one declare a custom property editor for the index checkbox names or is that just not worth trying to solve?

Posting Permissions

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