Results 1 to 7 of 7

Thread: Checkbox problem - how to modify the requestParameterMap if it is immutable

  1. #1

    Question Checkbox problem - how to modify the requestParameterMap if it is immutable

    G'day everyone,

    I have a problem with checkboxes in that when they are unchecked i want to know about it, but when a checkbox gets unchecked nothing gets sent over the request about it. I had an idea where i could intercept the request and search it for certain checkbox field names, and if i don't find them i wanted to add these fields as properties/parameters in the requestParameterMap and set ther values to false. Only problem here is that this map is immutable. Any ideas?? I really need to get over this problem. The main question here is how can i add an extra request parameter to the requestParameterMap when it is an immutable object??

    Thanks in advance,

    Eddy.

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Spring's web data binder provides out-of-the-box support for detecting false checkbox submissions, by supporting use of a marker request parameter that is sent from the page. I recommend you search the Spring MVC forum for discussion of this solution, and refer to the JavaDocs.

    Keith
    Keith Donald
    Core Spring Development Team

  3. #3

    Default

    thanks heaps for that Keith. Is the example below what you are talking about

    Code:
    <input type="hidden" name="_${status.expression}" value="NOT_USED">
        <input type="checkbox"
            id="${path}"
            name="${status.expression}"
            value="true"
        />
    Also, I am restricted to using struts with my webflow intead of spring mvc, will this work for a struts/webflow app??

  4. #4
    Join Date
    Jan 2006
    Location
    Zürich, Switzerland
    Posts
    423

    Default

    Quote Originally Posted by springChicken
    thanks heaps for that Keith. Is the example below what you are talking about

    Code:
    <input type="hidden" name="_${status.expression}" value="NOT_USED">
        <input type="checkbox"
            id="${path}"
            name="${status.expression}"
            value="true"
        />
    Yes, that's what Keith was talking about; however, you don't need to set any value. The following will suffice:

    Code:
    <input type="hidden" name="_${status.expression}"/>
    Quote Originally Posted by springChicken
    Also, I am restricted to using struts with my webflow intead of spring mvc, will this work for a struts/webflow app??
    No, you should not be restricted. AFAIK, the above technique should work with any implementation that uses Spring (web) binding for the forms.

    cheers,

    Sam

  5. #5
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    This approach works fine in SWF, as SWF's FormAction uses Spring's data binder. Isn't reuse great? :-)

    Keith
    Keith Donald
    Core Spring Development Team

  6. #6

    Default

    Sorry guys but i am still getting an error and i have a feeling that it is something simple. Am i supposed to use the struts html tags like html:hidden etc instead of the normal html hidden and checkbox syntax? I am using struts with webflow (unfortunately forced to use struts, as I wanted to learn and use SpringMVC and for my next "personal" project i will use SpringMVC) .
    Can someone gimme a code snippet of how you would do the checkbox with this "_" syntax for when it is unchecked, but suitable for a struts - webflow app, not a springMVC app.

    The error i am getting is as follows:

    [23/02/06 14:47:46:031 EST] 00000025 BindTag E org.springframework.web.servlet.tags.RequestContex tAwareTag doStartTag Neither Errors instance nor plain target object for bean name 'addressHOM' available as request attribute
    javax.servlet.jsp.JspTagException: Neither Errors instance nor plain target object for bean name 'addressHOM' available as request attribute


    my jsp code snippets are as follows:

    Code:
    <%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
    
    <spring:bind path="addressHOM">
            		<input type="hidden" name="_<c:out value="${status.expression}"/>">
            		<input type="checkbox" name="<c:out value="${status.expression}"/>" value="true"
                		<c:if test="${status.value}">checked</c:if>/>
         		</spring:bind>
    The above code is just a snippet of the jsp. addressHOM is a boolean primitive within my form backing object. It is as though my requestContext or form backing object is coming up as null.

    Anyway, any help would be much appreciated. Please help anyone.

    Thanks in advance,

    Eddy.

  7. #7
    Join Date
    Aug 2004
    Posts
    15

    Default

    Hi,

    I don't think the error you are seeing now has anything to do with your checkbox use (which looks right to me). I have a few questions for you:

    1. Are you extending FormAction or is this request being handled by a regular SimpleFormController?

    2. Are you getting this error after you POST?

    3. If the answer to 2, is yes, then are you returning to the same view that you POSTed from? If that is the case you need to use make sure you put the form object back into request. Using a SimpleFormController I've accomplished this using a RedirectView.

Posting Permissions

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