Forgot the quotes
document.yourForm.action="
Main Topics
Browse All TopicsHi experts!
My page has 4 buttons in one form. One is the submit button, another one is a cancel button, and the other two are buttons that does another action if chosen. (For example, delete and edit).
I use <html:img> or <html:image> tags for the buttons. I was wondering how I could get my action to determine which button was clicked and have the forward subsequently use the right method in my action.
Any help would be great. Thanks!
Thanks!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I think can not. Then you can use its super class, DispatchAction
http://jakarta.apache.org/
Hi Kotan,
Could you give me a code sample of how I could pass the the paramenter/method?
I tried using this:
<html:link action="/RemoveConfigItem"
<html:image src="/ADM/images/delete_bu
</html:link>
But I get an error because it can't find the bean names remove. I was wondering how I'd be able to pass this :-)
Thanks!
This is a good way of doing it (I think):
http://j2ee.lagnada.com/st
DidierD,
I like what you are proposing, but I can't seem to get it to work. I'm using LookupDispatchAction to determine which action method gets called when a button on the form is clicked (there are several buttons: add, save, exit). I'm also using the Validator framework so that when I click the Add and Save buttons the form gets validated before the action class methods are executed (some fields on the form cannot be left blank for Add and Save). But, I don't want validation to occur when I click the Exit button (because user should be able to exit from a blank form). So, I want to change the form action to /exit.do when the Exit button is clicked (in struts-config.xml the action mapping for /exit.do has validate='false' to prevent the form from being validated before going to the action class's exit() method). Here are the pieces:
Action mappings from struts-config.xml:
<action path="/theformaction" name="myForm" type="CommonActions" validate="true" input="/thejspfile.jsp" parameter="methodToCall" scope="request" >
<forward name="success" path="/success.jsp" />
<forward name="failure" path="/failure.jsp" />
</action>
<action path="/exit" name="myForm" type="CommonActions" validate="false" parameter="methodToCall" scope="request" >
<forward name="mainmenu" path="/mainMenu.jsp" />
</action>
(myForm is of type org.apache.struts.validato
Button code from thejspfile.jsp:
<html:submit property="methodToCall">
<bean:message key="button.add"/>
</html:submit>
<html:submit property="methodToCall">
<bean:message key="button.save"/>
</html:reset>
<input type="button" name="methodToCall" value="Exit" onclick="javascript:exit()
<script>
function exit(){
document.forms[0].action="
document.forms[0].submit()
}
</script>
Struts uses the methodToCall parameter to figure out which method in my LookupDispatchAction subclass to execute. It works fine for the add and save buttons (validation occurs, then the add() or save() methods run), but when I click the exit button, I get a runtime exception:
javax.servlet.ServletExcep
This is what the form buttons look like with view source:
<input type="submit" name="methodToCall" value="Add">
<input type="submit" name="methodToCall" value="Add">
<input type="button" name="methodToCall" value="Exit" onclick="javascript:exit()
Apparently, the methodToCall parameter isn't being added to the ActionMapping object, but I don't know why. Very sorry this is so long, but I wanted to provide a complete description.
Note that I know this works:
<input type="button" value='Exit' onclick='window.location="
but I don't want to do that, because then the path to the jsp file is displayed to the user in the URL.
Thanks for any help.
To make buttons work:
JSP:
<html:submit property="submit">
<bean:message key="button.add"/>
</html:submit>
note: there has to be space between the " /> .
1. property can be any name you want but you will have to remember this because this is what you will need for parameter name in the struts-config file.
2. The key to the button is called button.add. You can make any name you want. You can call it e.g. butt.pizza. You will also have to remember this because you will need to add this name in the file ApplicationResources.prope
3. You will need to change the struts-config file:
<action path="/doSomething"
type="com.fitness.pt.actio
name="measurementForm" scope="request" parameter="submit" validate="false">
<forward name="success" path="/doSomething.do"/>
</action>
please note parameter="submit" this is the property in the .jsp
validate can be false or true since I do not have a validation file, I set it to false.
4. You will need only one java class to control your routing. I think this makes it cleaner. You will need to import LookupDispatchAction. Please do not inherit PTBaseAction since it has an execute() method. If you do that, this overrides the execute method of the LookupDispatchAction. I do not know how to make a PTLookupDispatchAction to make the codes reusable because you have to implement getKeyMethodMap();
The method getKeyMethodMap() is your database. This tells the class what your button.pizza has to do. map.put("button.pizza", "buyPizza"); Then you need to implement a method called buyPizza().
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("button.update", "update");
map.put("button.delete", "delete");
map.put("button.add", "add");
map.put("button.save", "save");
return map;
}
public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
System.out.println("called
return mapping.findForward("succe
}
public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
System.out.println("called
return mapping.findForward("succe
}
public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
System.out.println("called
return mapping.findForward("succe
}
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
System.out.println("called
return mapping.findForward("succe
}
}
zenMistress2004, thanks for the reply. I actually did get this to work using the following for my exit button code:
<input type="button" value="Exit" onclick='document.forms[0]
I changed the mapping in struts-config.xml to the following:
<action path="/exit" type="TheCommonActions" parameter="exitToMenu" >
<forward name="mainmenu" path="/hospcapMenu.jsp" />
</action>
TheCommonActions is a new class extending MappingDispatchAction. "exitToMenu" is the name of a method in the class. The method simply has the following return statement:
return actionMapping.findForward(
BTW, regarding your comment that there has to be a space between the " and the /> terminating the <html:bean tag, I don't have a space there and it works fine.
Business Accounts
Answer for Membership
by: DidierDPosted on 2003-11-21 at 00:08:18ID: 9795366
You can do it like this:
img src="/submit.gif" border="0" /></a>
extPage.do ; ;
l()"><html :img src="/submit.gif" border="0" /></a>
<a href="/nextPage.do"><html:
or
<script>
function gotoCancel(){
document.yourForm.action=n
document.yourForm.submit()
}
</script>
<a href="javascript:gotoCance
Greetz,
Didier