Results 1 to 5 of 5

Thread: Request parameters not in command object

  1. #1
    Join Date
    Aug 2004
    Location
    Irvine, CA
    Posts
    17

    Default Request parameters not in command object

    I'm wondering what the recommended method is for grabbing parameters from a form that are NOT part of the value/command object.

    I have been using the following inside an Action class...

    HttpServletRequest request = ServletEvent.getRequest( context.getSourceEvent() );
    int fooId = RequestUtils.getIntParameter( request, "fooId", 1 );


    However, this does mean the code is now coupled to an HTTP request (which is no worse than it was previously in a Spring FormController).

    Am I missing something? I checked the RequestScope and FormScope to see if all params were being dropped into a Map, but didn't find them. This is the case where I don't want to modify the value object for the form to introduce this parameter....

  2. #2
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    The way you're doing it is pretty much correct.

    If you want to keep your actions (and the flow itself) independent of HttpServletRequest, consider doing it in a FlowExecutionListener. Those are easily pluggable, so you could plug in another listener if you're reusing your flow in other situation, e.g. for a Portlet.

    Erwin

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

    Default

    Hey now, there is no need to expose the servlet API here, nor should you!

    You can just do this:
    Code:
    context.getSourceEvent().getParameter("foo");
    That will access the HTTP request parameters underneath the covers.

    Keith
    Keith Donald
    Core Spring Development Team

  4. #4
    Join Date
    Aug 2004
    Location
    Irvine, CA
    Posts
    17

    Default

    Ahhh, this is exactly what I was looking for (and hoping was there)!

    Any chance for some utility functionality similar to RequestUtils (i.e. checking for required, setting defaults, casting to primitives)? Or is there a utility class that I'm overlooking?

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

    Default

    Yes, actually. Perhaps you could get this integration started and maybe submit a JIRA enhancement with a patch :-)

    If you take a look at Event, you'll see it's a AttributeSource. So is Scope, as well (anything in RequestScope or FlowScope). AttributeSource is a simple interface.

    So it'd be straight forward to have:

    int value = AttributeUtils.getIntAttribute(source, "myAttribute");

    etc, etc...

    like RequestUtils, but more flexible. You could use the Converter machinery to actually perform conversions underneath the covers. e.g:

    Code:
    getIntAttribute(AttributeSource source, String attributeName, int defaultValue) {
        try {
          return ((Integer)converterFor(value.getClass(),
    Integer.class).convert(value)).intValue();
       } catch (ConversionException e) {
          return defaultValue;
       }
    }
    Keith
    Keith Donald
    Core Spring Development Team

Similar Threads

  1. Hibernate Long Session Per Flow?
    By akw in forum Web Flow
    Replies: 21
    Last Post: Dec 12th, 2005, 08:06 PM
  2. Add parameters to the current request
    By 2devnull in forum Web
    Replies: 7
    Last Post: Nov 22nd, 2005, 07:17 AM
  3. Replies: 9
    Last Post: Nov 1st, 2005, 10:36 PM
  4. RequestScope and request parameters
    By Christian in forum Web Flow
    Replies: 2
    Last Post: Jun 29th, 2005, 10:33 AM
  5. Replies: 7
    Last Post: Nov 30th, 2004, 03:14 PM

Posting Permissions

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