Have your Action class be of type DispatchAction. Instead of execute methods in your action have methods for each button, for example save(), delete() and cancel().
Then in your JSP where the buttons are do something like:
 
         <html:submit property="method" title="Save thing.">
            <bean:message key="button.save"/>
         </html:submit>
 
Of course this requires you to to do a couple of other things.
 
First in your map for this action make sure you declare method (see  ********):
 
          <action path="/admin/saveThing"
                  type="com.company.project.web.admin.ThingAction"
                  name="thingForm"
                  validate="true"
                  input="thing.layout"
                  scope="request"
                  parameter="method"> ********
                  <forward name="success" path="/admin/editThing.do?method=Edit"/>
                  <forward name="edit" path="/admin/editThing.do?method=Edit"/>
                  <forward name="add" path="/admin/addThing.do?method=Add"/>
          </action>
 
And in your ApplicationResources.properties you must define button.save:
button.save=Save
 
So when you do all of this and press the Save button you get a HTTP request param "method=Save" come through.
 
Then in Struts the DispatchAction sends it to your action and calls the save method.
 
-----Original Message-----
From: Sunil Narvekar [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 04, 2003 12:10 PM
To: Research Triangle Java User's Group mailing list.
Subject: [Juglist] Struts question

I have a JSP form with three submit buttons on it such as Update, Delete and Abort.

I created struts action classes .. UpdateAction, DeleteAction and AbortAction with an execute() method in each of them which performs the necessary action.

How do I setup the struts configuration file, so that each time I press a submit button, it performs the intended action. For example, when Update button is pressed - invoke UpdateAction's execute() method.

I know one way of doing this is by using the org.apache.struts.actions.LookupDispathAction class. It requires you to write one class with multiple methods(for example update(), delete() and abort()), where one of the methods will be invoked based on value of a special request parameter sprcified in the configuration file. 

What if I do not want to combine the several actions in one class, but have one action class for each submit button on the JSP page?. Please let me know if anyone has done this. This is my first Struts project.

Thanks

Sunil Narvekar

 

  

 

 

 


Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org

Reply via email to