Announcement Announcement Module
Collapse
No announcement yet.
Pass dynamic generated key-value pairs into HashMap Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pass dynamic generated key-value pairs into HashMap

    Hi togheter,

    I want to pass dynamic generated key-value pairs into a java HashMap. Following situation:

    Model (Helper)
    Code:
    public class SelectionHelper {
    	private Map<String, String> selections = new HashMap<String, String>();
    
    	public Map<String, String> getSelections() {
    		return selections ;
    	}
    	public void setSelections(Map<String, String> selections ) {
    		this.selections = selections;
    	}
    }
    View
    Code:
    function addPair(keyId, selectionId) {
    var selection= $("<input type=\"hidden\" name=\"selectionHelper.selections'"+keyId+"'\" value=\""+selectionId+"\"/>");
       $("#form").append(selection);
    }
    Code:
    <form:form id="form" modelAttribute="selectionHelper" action="controller/calculate.do" method="POST"></form:form>
    Controller
    Code:
    @RequestMapping(method = RequestMethod.POST)
    public ModelAndView calculate(@ModelAttribute("selectionHelper") SelectionHelper selectionHelper) {
    		
    // Do something with the key-value pairs
    		
    return mav;
    }
    But the dynamic generated hidden fields, are never passed to the controller. Can anyone help me, passing multiple key-value pairs into a hashmap?

    thanks for your help!

  • #2
    Fixed:

    Solution is:
    Code:
    function addPair(keyId, selectionId) {
    var selection= $("<input type=\"hidden\" name=\"selections['"+keyId+"']\" value=\""+selectionId+"\"/>");
       $("#form").append(selection);
    }

    Comment

    Working...
    X