struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: Conditional choice of action mapping based on html FORM and SELECT tag
Date Fri, 16 Feb 2001 18:55:08 GMT
Ellen Murray wrote:

> Hi,
>
> This is a newbie question. I am creating a web
> application where each page contains a pull down
> menu of commands (SELECT). I want the users choice
> of menu item to invoke the next action object.
> Because the FORM tag allows only one action,

This restriction is based on the corresponding restriction of the HTML
<form> element that is ultimately generated.

> I
> want that to be mapped to multiple actions in the
> struts-config.xml file. An example of what I'd
> like to do is below.
>
> Does anyone have a solution to this? I really need
> your help because I am working without access to
> other java or web programers.
>

The way you've set up your form, it looks like the input will include
the command parameter for you (since the default submit method is GET).
It's at the other end where the problem occurs, because matching against
your <action> elements is based on the "/planner" part of the URI --
without the request parameters.

Three strategies to consider:

* Subclass the ActionServlet servlet, and modify the
processActionMapping()
  method that chooses which action to execute.

* Use a single Action, but use "if" statements inside the action
  to decide what to do next.

* Use different actions (say, "/showReleases.do" and "/showTestPlan.do")

  and use JavaScript event handlers to change the form's "action"
attribute
  dynamically based on the choice in the SELECT box.

>
> Thanks - Ellen
>

Craig


>
> //
> // What I want in my web page
> //
>
> <FORM ACTION="planner.do" >
>
>  <SELECT name="cmd">
>    <option value="releases">ShowReleases"</OPTION>
>    <option value="testplan">ShowTestPlan"</OPTION>
>  </SELECT>
>
>  <INPUT type="submit" value="Submit">
>
>
> //
> // What I want in the struts-config.xml file...
> //
>  <!-- Display Releases -->
> <action  path="/planner?cmd=releases"
>           type="planner.ShowReleasesAction"
>          scope="request" >
>  <forward name="success"  path="/ShowReleases.jsp"/>
> </action>
>
>  <!-- Display Releases -->
> <action  path="/planner?cmd=testplan"
>           type="planner.ShowTestPlanAction"
>          scope="request" >
>  <forward name="success"  path="/ShowTestPlan.jsp"/>
> </action>
>
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail - only $35
> a year!  http://personal.mail.yahoo.com/


Mime
View raw message