• Post Reply Bookmark Topic Watch Topic
  • New Topic

more than one submit button and action  RSS feed

 
selvi family
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have 2 submit buttons in my JSP.

<html:submit>Save</html:submit>
</html:submit>Delete</html:submit>

clicking on Save action should set to saveAll.do
clicking on Delete ,action should set to deleteAll.do

is it possible ?
if so how come?

pls help me
 
Ramesh Jaggi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi :

One simple solution is that onclick of the button you can use java script and set the action accordingly.
You can pass the button name in the function and check it,if it is delete it should be delete action otherwise submit action or whatever you want.
I think this would help.


Ramesh
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do a Google search on "Struts DispatchAction", and you will find a lot of articles that will help you. The DispatchAction class was designed specifically for this type of processing.

Here is one article:

http://www.reumann.net/struts/lesson3/step6.do
 
Mcgill Smith
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use LookupDispatchAction
 
selvi family
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I am using <html:form> tag..here action attribute is mandatory.so I want to set somethinlg like this action="<%= %>"

pls help me...
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried searching this forum? This question is asked and answered quite frequently.
 
rangababu chakravarthula
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If You use image buttons for different actions (using ImageButtonBean) one ActionClass can be used for different actions.

In your JSP
<html:form action="/ManageAction">
<html:image property="saveButton" src="logonsubmit.jpg" alt="save" />
<html:image property="deleteButton" src="deletesubmit.jpg" alt="delete" />
</html:form>


In your ActionForm

private ImageButtonBean saveButton = new ImageButtonBean();
private ImageButtonBean deleteButton = new ImageButtonBean();

public void setSaveButton(ImageButtonBean button) {
this.saveButton = button;
}

public ImageButtonBean getSaveButton() {
return this.saveButton;
}

public void setDeleteButton(ImageButtonBean button) {
this.deleteButton = button;
}

public ImageButtonBean getDeleteButton() {
return this.deleteButton;
}


public String getSelected() {

if (getSaveButton().isSelected()) {
return "save";
}

if (getDeleteButton().isSelected()) {
return "delete";
}

return null;
}

In your ActionClass

String selected = manageForm.getSelected();
if ("save".equals(selected)) {
//do something
return forward = mapping.findForward("savethankyou");
}
else if ("delete".equals(selected)) {
//do something
forward = mapping.findForward("deletethankyou");
}
else{
forward = mapping.findForward("error");
}


in your struts-config.xml
<form-bean name="manageForm" type="your.package.forms.ManageForm">
</form-bean>

<action name="manageForm" path="/ManageAction" scope="request" type="your.package.actions.ManageAction" validate="false" >

<forward name="deletethankyou" path="/deletethankyou.jsp"/>
<forward name="savethankyou" path="/savethankyou.jsp"/>
<forward name="error" path="/error.jsp"/>
</action>
[ July 27, 2005: Message edited by: rangababu chakravarthula ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!