Results 1 to 3 of 3

Thread: Binding form parameters on a bean with collection property

  1. #1
    Join Date
    Oct 2004
    Location
    Rotterdam, Netherlands
    Posts
    90

    Default 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 at 05:03 PM.

  2. #2
    Join Date
    Oct 2004
    Location
    NYC, USA
    Posts
    13

    Default

    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}"/>"

  3. #3
    Join Date
    Oct 2004
    Location
    Rotterdam, Netherlands
    Posts
    90

    Default

    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

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

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