Results 1 to 8 of 8

Thread: checkbox problem

  1. #1
    Join Date
    Mar 2007
    Posts
    9

    Default checkbox problem

    HI guys,

    iam getting problem in displaying checkbox with values.I used <spring:bind> tag with bean name permissions which is declared in controller.java.

    here is the code:

    <c:forEach items="${permissions}" var="permission" varStatus="loopstatus">
    <spring:bind path="permissions[${loopstatus.index}].selected">
    <cut value="${permission.name}" /> <br>
    <input type="hidden" name="_<cut value="${loopstatus.expression}"/>">


    <input type="checkbox" name="<cut value="${loopstatus.expression}"/>" value="true">


    Please help me

    kursy003

  2. #2
    Join Date
    Dec 2006
    Posts
    150

    Default

    Is here a solution right now? I cant bind a checkbox to my object too... I have this code, but it isn't working.


    Code:
    	    <spring:bind path="register.havingChilds">
    				<input name="<core:out value="${status.expression}"/>" id="childCheckbox" type="checkbox" checked="<core:out value="${status.value}"/>"/>
    	    </spring:bind>

  3. #3
    Join Date
    Mar 2007
    Posts
    125

    Default

    but what is the problem exactly? is there an exception or something?

    or you just have always the default value regardless of anything?

    i see that you already have "<input type="hidden" name="_<cut value="${loopstatus.expression}"/>">" so it should be uncheckable (is this the right word? able to be unchecked? cos it sounds like indestructible )

    anyway, without more info on what exactly is the problem i can't really help.. but:

    i moved from <spring:bind> to forms taglib and it is much better in my opinion.
    the checkbox part would be like this (for a shared array of checkbox values)

    Code:
    <form:checkbox path="ids[${status.index}]" value="${message.messageId}"/>
    or for a single checkbox:

    Code:
    <form:checkbox path="someid" value="${message.messageId}"/>

    you do not need to add the hidden _somename input field in that solution, it is done by the <form:checkbox> already.


    cheers,
    fox
    Last edited by fox; Apr 28th, 2007 at 04:16 AM. Reason: added [code]

  4. #4
    Join Date
    Dec 2006
    Posts
    150

    Default

    Mhh, now i'm not sure whether my problem is the same as kursy's...

    For me its just not working.. no exception, but he does not write the values to the property and he does not reset the checkbox
    i would like to bind a checkbox as easy as a textbox to an int property or an boolean property.

    Here is some code from me where i use a combobox

    Code:
     	    <spring:bind path="register.customer.gender">
    	      <select
    	        <core:if test="${status.error}">
    		        class="error"
              </core:if>
    	        name="<core:out value="${status.expression}"/>" size="1">
    
             <option value="0"></option>
              <core:forEach items="${gender}" var="gender">
    	        <!-- Wenn vorauswahl, dann wird  bei option als attribut selected=selected gemacht (Vorauswahl) -->
    	          <option
    	            <core:if test="${gender.posnumber == status.value}">selected="selected" </core:if>
    	            value="<core:out value="${gender.posnumber}"/>"/>
    	            <core:out value="${gender.matchcode}"></core:out>
    	          </option>
    	        </core:forEach>
    	      </select>
    	    </spring:bind>
    gender is from a ownwritten type that contains matchcode (like male or female or in german männlich or weiblich) and the posumber is an unique id to identify the entry)
    maybe that helps kursy

  5. #5
    Join Date
    Mar 2007
    Posts
    125

    Default

    have you tried the <form:checkbox> method?

    you can learn more about it in the '13.9. Using Spring's form tag library' section at http://www.springframework.org/docs/reference/mvc.html

  6. #6
    Join Date
    Mar 2007
    Posts
    9

    Default update problem

    Thanks for replying guys,

    My problem is when i select the checkbox and submit the form.The values are not updated into the database and giving the error message of permissions[0] found .I dont what the problem is :
    here is my controller class.Please sort what the problem is:
    public class AdminFormController extends SimpleFormController {

    private AdminSpringService adminService;
    private RoleSpringService roleService;

    public void setAdminService(AdminSpringService inject) {
    this.adminService = inject;
    }

    public void setRoleService(RoleSpringService inject)
    {
    this.roleService=inject;
    }


    public AdminFormController() {
    this.setRequireSession(true);
    this.setValidator(new AdminValidator());
    }

    protected Object formBackingObject(HttpServletRequest request) throws Exception {
    Integer id = ServletRequestUtils.getIntParameter(request, "id", 0);

    if (id==0) {

    return new Administrator();
    }
    else return adminService.findWithFetch(id);

    }



    protected Map referenceData(HttpServletRequest request) throws Exception
    {
    ModelMap mm=new ModelMap();
    mm.addObject("roles",roleService.findAll());
    return mm;
    }




    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    SimpleDateFormat(OUT_FORMAT);
    binder.registerCustomEditor(Role.class, new RoleEditor(this.roleService));
    binder.bind(request);
    }


    protected void doSubmitAction(Object ob) throws Exception {

    adminService.addRoleToAdministrator(new Role(),new Administrator());
    adminService.save((Administrator) ob);
    }

    @Override
    public ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception {
    if (errors.getAllErrors().size() == 0) {
    return super.showForm(request, response, errors);
    } else {
    return super.showForm(request, errors, ".failure.editAdmin");
    }
    }

    protected boolean isFormChangeRequest(HttpServletRequest request) {
    return (request.getParameter("name") == null);
    }

    }

    thanks in advance
    kursy003

  7. #7
    Join Date
    Mar 2007
    Posts
    125

    Default

    hi

    1. please use CODE tag when pasting source code - it will make it much more readable

    2. what do you mean about 'permission[0]' message error? is it an exception or something? please tell us more about the problem. there might be various reasons why the object is not saved

    3. i'd encourage you to use some logging - that way you could find out/fix some problems on your own way faster

  8. #8
    Join Date
    Jun 2007
    Posts
    14

    Default

    Quote Originally Posted by fox View Post
    have you tried the <form:checkbox> method?

    you can learn more about it in the '13.9. Using Spring's form tag library' section at http://www.springframework.org/docs/reference/mvc.html
    My checkbox with <input type="checkbox" name="${status.expression}" doesn't work either. The value cannot be passed to the POJO class.

    I haven't tried the spring form tag. Is there any reason why I have to use spring tag and why the input tag is not working?

Posting Permissions

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