Results 1 to 5 of 5

Thread: Usage of marker parameters feature

  1. #1
    Join Date
    Aug 2004
    Posts
    8

    Default Usage of marker parameters feature

    I just tried the new field marker prefix feature of the ServletRequestDataBinder (automatically supplementing request parameters for an unchecked checkbox), and it worked quite well. My solution doesn't seem too smart to me, though:
    I set the prefix in the initBinder method of my controller:
    Code:
    binder.setFieldMarkerPrefix("checkbox_");
    and added a hidden parameter to my form:
    Code:
    <input type="hidden" name="checkbox_<jstl&#58;out value="$&#123;status.expression&#125;"/>" value="irrelevant"/>
    Hardcoding the prefix like this is awkward. One possible solution would be to add some sort of global config bean to my application context and retrieve the prefix like this:
    Code:
    WebApplicationContext context = &#40;WebApplicationContext&#41;request.getAttribute&#40;"org.springframework.web.servlet.DispatcherServlet.CONTEXT"&#41;;
    GlobalConfigBean config = &#40;GlobalConfigBean&#41;context.getBean&#40;"config"&#41;;
    binder.setFieldMarkerPrefix&#40;config.getFormPrefix&#40;&#41;&#41;;
    ... and in my jsp:
    Code:
    <input type="hidden" name="<jstl&#58;out value="$&#123;config.formPrefix&#125;"/><jstl&#58;out value="$&#123;status.expression&#125;"/>" value="irrelevant"/>
    Is there any "official" recommendation on how to use the field marker prefix in a more elegant way?

    Kind regards

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default Re: Usage of marker parameters feature

    Quote Originally Posted by arsenjew
    Is there any "official" recommendation on how to use the field marker prefix in a more elegant way?
    Maybe we should add a fieldMarker property to the BindStatus object, allowing you to do the following

    Code:
    <input type="hidden" name="<c&#58;out value="$&#123;status.fieldMarker&#125;"/>"/>

  3. #3
    Join Date
    Aug 2004
    Posts
    8

    Default

    You do not suggest to amend the framework, do you? That my first posting to this forum should have such an impact rather scares me ;-)
    Yet another question concerning the field marker:
    I cannot use it to automatically reset the values of an array of properties (say, for a row of checkboxes or a multiple select list), can I? At least I can see no way how the binder should know what length to initialize the array with.

  4. #4
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Well why not ;-).

    I think we're a bit too late here, we're almost releasing a 1.1 final and I don't think it'll make it, but I'll suggest it at the dev list.


    About the array? No, not really, but you could always do that programmatically (although this is a hassle of course) using one of the on**** methods (can't remember which one is called before validation, you have to check the JavaDOC for that).

    alef

  5. #5
    Join Date
    Aug 2004
    Posts
    8

    Default

    (Just for the records):
    Using the field marker technique with an array of properties will leave you with an array of length 0 if the request contained no parameter value for the property in question.
    In order to re-initialize your array you can override onBindAndValidate in your Controller, simply copying the parameter value array to your property array:

    Code:
    String&#91;&#93; myProp = new String&#91;&#93;;
    if &#40;request.getParameter&#40;"myProp"&#41;!=null&#41;&#123;
      myProp = &#40;String&#91;&#93;&#41;request.getParameterValues&#40;"myProp"&#41;.clone&#40;&#41;;
      &#40;&#40;myCommand&#41;command&#41;.setMyProp&#40;myProp&#41;;
    &#125;
    (Overriding onBindAndValidate would have been the way to deal with this anyway before the introduction of the field marker prefix, cf. http://opensource.atlassian.com/proj...browse/SPR-111)

Similar Threads

  1. FilterSecurityInterceptor can't match URL parameters
    By mattlangston in forum Security
    Replies: 3
    Last Post: Jul 31st, 2007, 02:16 PM
  2. Replies: 3
    Last Post: Nov 20th, 2006, 05:04 AM
  3. Event parameter usage
    By akw in forum Web Flow
    Replies: 1
    Last Post: Aug 28th, 2005, 02:50 AM
  4. The forward: feature
    By eisenb in forum Web
    Replies: 0
    Last Post: Dec 13th, 2004, 03:57 PM
  5. Append parameters to PreparedStatement
    By victorbr in forum Data
    Replies: 0
    Last Post: Nov 4th, 2004, 05:41 AM

Posting Permissions

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