Results 1 to 4 of 4

Thread: form:checkboxes problem - onSubmit doesnt start

  1. #1
    Join Date
    Nov 2008
    Posts
    6

    Unhappy form:checkboxes problem - onSubmit doesnt start

    I use form:checkboxes tag, it display properly. If I don't choose any option, submit works fine, but when I select element from the checkboxes, the submit doesnt work, it loads the same page and method onSubmit don't start. Without form:checkboxes it work correct.

    I was using form:checkboxes and it was working fine, for example for enumerations. But it doesnt work for Set of complex objects.

    This is my case:

    Code:
    <spring:bind path="command.selectedMembers">
    <form:checkboxes path="command.selectedMembers" items="${friends}" itemLabel="fullName" delimiter="<br/>"/>
    </spring:bind>

  2. #2
    Join Date
    Nov 2008
    Posts
    6

    Exclamation

    again, i removed everything, left only this on page:

    HTML Code:
    <body>
    <form:form method="post">
    <form:checkboxes path="selectedMembers" items="${friends}"/>
    
    <input type="submit" value="save" />
    </form:form>
    </body>
    for controller:

    Code:
    <property name="commandClass">
    <value>com.thell.form.InviteToEventForm</value>
    </property>
    command class:
    Code:
    public class InviteToEventForm {
    
    	private String emails;
    	
    	private Set<Friend> selectedMembers;
    
    	public String getEmails() {
    		return emails;
    	}
    
    	public void setEmails(String emails) {
    		this.emails = emails;
    	}
    
    	public Set<Friend> getSelectedMembers() {
    		return selectedMembers;
    	}
    
    	public void setSelectedMembers(Set<Friend> selectedMembers) {
    		this.selectedMembers = selectedMembers;
    	}
    
    }
    It should work, but it does not work. When I select any checkbox (in set I have only one, but it should not matter).
    So when I select element, submit does not work - I am forwarded back to the same page through :

    Code:
    @Override
    	protected Object formBackingObject(HttpServletRequest request)...
    and when element from checkbox is not selected, submit method works!!!
    Code:
    	@Override
    	protected ModelAndView onSubmit(HttpServletRequest request,
    			HttpServletResponse response, Object command, BindException errors)
    			throws Exception {
    What is the problem?

  3. #3
    Join Date
    Nov 2008
    Posts
    6

    Default

    I have changed Set to Array, because it is in Spring documentation about checkboxes tag:

    You pass in an Array, a List or a Map containing the available options in the "items" property.

    So the Set wasn't mentioned...but still the same results.
    I am going crazy

  4. #4
    Join Date
    Nov 2008
    Posts
    6

    Default

    OK, onSubmit() didn't start because it was error message from checkboxes, but I didn't display it.

    And the solution was to add:

    Code:
       	binder.registerCustomEditor(Set.class, "selectedMembers",
        			new CustomCollectionEditor(Set.class){
        		protected Object convertElement(Object element){
        			Integer id = new Integer((String) element);
        			Friend friend = new Friend();
        			friend.setFriendId(id);
        			return friend;
        		}
        		}
    in controller, inside method:
    Code:
        protected void initBinder(
    I thought that I don't need to do such things and it will be done magically automatically.
    So now I know that it is not so automatic.

Tags for this Thread

Posting Permissions

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