isCancelled() crée une erreur
Bonjour,
j'essaie de mettre un bouton 'cancel' dans un formulaire.
J'ai donc rajouté dans mon formulaire:
Code:
<html:cancel></html:cancel>
puis dans la classe action, un test qui utilise isCancelled:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| package test;
//default package
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import bean.Login;
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException,
IllegalAccessException, InvocationTargetException {
LoginForm monForm = (LoginForm) form;
Login monLogin = new Login();
BeanUtils.copyProperties(monLogin, monForm);
request.setAttribute(mapping.getAttribute(), monLogin);
if(isCancelled(request)) {
System.out.println("******** on teste si 'cancel' **********");
//form.reset(mapping, request);
return mapping.findForward("default");
}
System.out.println(monLogin.getLogin());
if(("yohan").equals(monLogin.getLogin()) && ("zebulon").equals(monLogin.getMdp())) {
return mapping.findForward("succes");
}
return mapping.findForward("erreur");
}
} |
Mais j'obtiens une erreur lorsque je clique sur le bouton 'cancel' du formulaire:
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| org.apache.struts.action.InvalidCancelException
org.apache.struts.chain.commands.AbstractValidateActionForm.isCancelled(AbstractValidateActionForm.java:73)
org.apache.struts.chain.commands.AbstractValidateActionForm.execute(AbstractValidateActionForm.java:111)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) |
Je ne comprend pas l'erreur. L'erreur semble être déclenchée avant même de passer dans la boucle qui teste la valeur de 'isCancelled()'.