Announcement Announcement Module
No announcement yet.
Request parameters not in command object Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.



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

      You can just do this:
      That will access the HTTP request parameters underneath the covers.



      • #4
        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
          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:

          getIntAttribute(AttributeSource source, String attributeName, int defaultValue) {
              try {
                return ((Integer)converterFor(value.getClass(),
             } catch (ConversionException e) {
                return defaultValue;