Announcement Announcement Module
Collapse
No announcement yet.
Binding form parameters on a bean with collection property Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding form parameters on a bean with collection property

    Hi,

    I am having trouble binding form parameters on a bean with a collection property.

    My command bean:

    Code:
    public class NewGalleryForm {
        private Collection models = new ArrayList();
    
        public Collection getModels() {
            return models;
        }
    
        public void setModels(Collection models) {
            this.models = models;
        }
    }
    The jsp page:

    Code:
    <spring:bind path="iuCommand.models[0].name">
        <input type="text" name="name" />
    </spring:bind>
    For testing purposes, the command object is initialized in the formBackingObject with a collection models containing three Model objects.

    Now, when I try to set the name on the Model in the JSP page, it consistently gives null in the controller after submitting the form.

    NewGalleryController.onSubmit:

    Code:
    for ( Iterator iter = bean.getModels().iterator(); iter.hasNext();){
                Model m = (Model) iter.next();
                logger.info("#### model found: " + m);
                logger.info("#### model name" + m.getName());
    }
    Gives:

    19 Nov 2004 12:57:46,576 INFO NewGalleryController:45 - onSumbit() called.
    19 Nov 2004 12:57:46,586 INFO NewGalleryController:62 - #### model found: com.vvdb.bus.gallery.Model@a262c1
    19 Nov 2004 12:57:46,586 INFO NewGalleryController:63 - #### model name null
    19 Nov 2004 12:57:46,586 INFO NewGalleryController:62 - #### model found: com.vvdb.bus.gallery.Model@17675
    19 Nov 2004 12:57:46,586 INFO NewGalleryController:63 - #### model name null
    19 Nov 2004 12:57:46,586 INFO NewGalleryController:62 - #### model found: com.vvdb.bus.gallery.Model@82e1a
    19 Nov 2004 12:57:46,586 INFO NewGalleryController:63 - #### model name null

    I am using Spring 1.1.

    Of course I read this post http://forum.springframework.org/sho...ht=nested+form but I am still stuck, especially because no exception or error is thrown.

    Your help is greatly appreciated.

    -- Thomas
    Last edited by robyn; May 14th, 2006, 06:03 PM.

  • #2
    i think your problem lies in the fact that the input field has no 'value'.

    you're initializing the object in the controller, but you're not passing the 'name' parameter back to the controller when you press submit.

    Spring then attempts to bind to the command object, but doesn't receive the 'name' parameter from the form, so you get a 'null'

    try setting value="<c:out value="${status.value}"/>"

    Comment


    • #3
      Yes, this works:

      Code:
      <spring&#58;bind path="command.models&#91;0&#93;.name">
          <input type="text" name="<c&#58;out value="$&#123;status.expression&#125;"/>"
          value="<c&#58;out value="$&#123;status.value&#125;"/>" />
      </spring&#58;bind>
      Note: I also had to supply name="<c:out value="${status.expression}"/>" to get it working.

      Where in the documentation / in what posts is the usage of the status model element described?

      Much obliged, Thomas

      Comment

      Working...
      X