• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

LookupDispatchAction + html:cancel

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Manuel Sanchez Iba�ez
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic