This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes  LookupDispatchAction + html:cancel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark " LookupDispatchAction + html:cancel" Watch " LookupDispatchAction + html:cancel" New topic
Author

LookupDispatchAction + html:cancel

Manuel Sanchez Iba�ez
Greenhorn

Joined: Jul 12, 2005
Posts: 20
Hello and sorry for my english. In my form, i have 2 submit button. I manage the flow using LookupDispatchAction. This works fine and now i want add a cancel button.

If i code this buttons:
<html:submit property="action"><bean:message key="boton.insertarfavoritos"/></html:submit>

<html:submit property="action"><bean:message key="boton.otroejercicio"/></html:submit>

<html:cancel><bean:message key="boton.cancel"/></html:cancel>

throws an error:
Request[/altaejercicioSubmit] does not contain handler parameter named 'action'. This may be caused by whitespace in the label text.

I have created a new class Action for cancel button using LookupDispatchAction:
<html:cancel property="action"><bean:message key="boton.cancel"/></html:cancel>

but then the form validation shows all empty fields.

I have seen the html:cancel documentation:

WARNING - If you set this attribute to a value other than the default, this will NOT be recognized as the cancel key by the Struts controller servlet or the Action.isCancelled() method. You will need to do your own cancel detection.

But i don�t understand. In a normal form with one submit button and one cancel button, in the Action i put:
if (isCancelled(request)){
return(mapping.findForward("mainmenu"));
}


How can i use a html:cancel button using LookupDispatchAction?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You simply treat the cancel button exactly as you did your other two buttons. You will create a cancel() method in your Action class, and the dispatcher will execute that method when the button is pressed. You can then perform whatever tasks need to take place for a cancel within that method.


Merrill
Consultant, Sima Solutions
Manuel Sanchez Iba�ez
Greenhorn

Joined: Jul 12, 2005
Posts: 20
I tried your idea but the form have to validate it previosly. How can i avoid the form validation in this case? Because it�s necesary in submit buttons that all fields are filled (except in cancel button).
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In this case, you would have to override the validate() method of your form bean. Add logic to check whether the cancel button was pressed, and only perform vlidations if it wasn't pressed. Something like this:

Manuel Sanchez Iba�ez
Greenhorn

Joined: Jul 12, 2005
Posts: 20
Thanks very much. In the end, i saw one example in a book and the solution is very easy. In jsp i have used <html:cancel><bean:message key="boton.cancel"/></html:cancel>

In Action class:
public class EjercicioForkAction extends LookupDispatchAction{

protected Map getKeyMethodMap(){
Map map = new HashMap();
map.put("boton.submit","AltaEjercicioAction");
map.put("boton.otroejercicio","AltaRepeatEjercicioAction");
return map;
}

public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{
if (isCancelled(request)){
return(mapping.findForward("mainmenu"));
}
return (mapping.findForward("success"));
}

... Other custom actions ...

Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: LookupDispatchAction + html:cancel