At 3:38 PM +0200 4/27/05, Rodolfo García Esteban/CYII wrote:
Hi

I'm using struts 1.2.4. I have an action which can be called from two
pages, and I need to change the input parameter in order to return and
show the errors in the previous page, by this cause I can't specify the
input parameter in struts-config.xml, I need to do something in my
application dinamycly.

There are two direct work-arounds, although neither may totally satisfy you:

a) use more than one action mapping, so that each of two paths can have independent values for "input" while sharing most of the rest of the config, as well as sharing the processing logic. This may be easier using wildcard path mapping[1], which allows you to populate values of the ActionMapping based on matches, so you could have:

<action path="/usecase/SubmitFrom*" input="{1}" ...>

This might work better with the ability to specify that values for "input" are forward names rather than application paths.[2] Of course, you don't have to use wildcards.

We've recently also added support for "extending" config elements, although I believe this is only in the Struts 1.3 dev branch (did it get added to 1.2.x?) That would provide an alternative approach.

b) perform the validation inside your action and manually return the correct forward config object based on the context. This is really not that hard. Here's how you'd do in an action what Struts does for you if "validate" is set to "true"; from here, you should be able to adapt to return a different forward.:

public ActionForward execute(m,f,req,res)  throws Exception{
  // replicate Struts validation
  ActionErrors errors = f.validate(m,req);
  if (errors.size != 0) {
    saveErrors(req,errors);
    return m.getInputForward();
  }
  // carry on with valid-state controller logic
}

A lot of Struts users have valid reasons to do the validation inside the action instead of leaving it up to Struts -- maybe you are one of them. To be honest, though, I think the first solution is a better one, whether or not you use wildcards.

Joe

References:
[1] http://struts.apache.org/userGuide/building_controller.html#action_mapping_wildcards
[2] http://struts.apache.org/userGuide/configuration.html#controller_config
--
Joe Germuska
[EMAIL PROTECTED]
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction" -The Ex

Reply via email to