Announcement Announcement Module
Collapse
No announcement yet.
Issue: Binding form fields with Map in command object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue: Binding form fields with Map in command object

    Hi,

    It seems there is issue with spring in binding form fields with map in command object.

    Here is my code:
    Command Class
    Code:
    public class MyCommand {
    
    	private Map fields;
    
    	public Map getFieldsMap() {
    		return fields;
    	}
    
    	public void setFieldsMap(Map fields) {
    		this.fields = fields;
    	}
    }
    fields on from
    Code:
    	<c&#58;forEach var="field" items="$&#123;fields&#125;">
    <input value="" name="fieldsMap&#91;$&#123;field.name&#125;&#93;" type="text"/>
    	</c&#58;forEach>
    Above code throws exception.
    But if I initialize my Map objects explicitly as below it works fine
    Code:
    public class MyCommand &#123;
    
    	private Map fields = new HashMap&#40;&#41;;
    
    	public Map getFieldsMap&#40;&#41; &#123;
    		return fields;
    	&#125;
    
    	public void setFieldsMap&#40;Map fields&#41; &#123;
    		this.fields = fields;
    	&#125;
    &#125;
    Can anyone tell me how to log this bug in Spring Tracker. I am using Spring version 1.2.3

    Regards,
    Umesh

  • #2
    This isn't a bug, it is a misunderstanding

    Spring is binding to entries *within* your map, it isn't binding to the map itself.

    In otherwords, spring will never call
    Code:
    setFieldsMap(..);
    it will only ever call
    Code:
    getFieldsMap().get(whatever your field name is);
    Checkout http://forum.springframework.org/showthread.php?t=17646 for a bit more info on this.
    Last edited by robyn; May 14th, 2006, 10:18 AM.

    Comment

    Working...
    X