• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

LookupDispatchAction + html:cancel

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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.
 
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic