[ Struts ][ Validator ]problème d'affichage
bonjour,
J'ai un pblm avec mon Validator car je n'arrive pas à lui faire afficher les messages voulus. En effet il affiche rien du tout....
Voici les bouts de codes que j'ai modifiés pour "installer" le validator:
struts-config:
Code:
1 2 3 4 5 6 7 8 9
| <plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config" value="/WEB-INF/gabaritConges-tiles.xml" />
<set-property property="definitions-debug" value="2" />
<set-property property="definitions-parser-details" value="2" />
<set-property property="definitions-parser-validate" value="true" />
</plug-in>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in> |
validator-rules.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <form-validation>
<global>
<validator name="required"
classname="org.apache.struts.validator.FieldChecks"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionMessages,
javax.servlet.http.HttpServletRequest"
msg="errors.required"/>
</global>
</form-validation> |
validation.xml :
Code:
1 2 3 4 5 6 7 8 9 10
| <form-validation>
<formset>
<form name="loginForm">
<field property="login" depends="required">
</field>
</form>
</formset>
</form-validation> |
login.jsp:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <html:form action="/login.do?event=traitement" onsubmit="return validateLoginForm(this);">
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="115">Login:</td>
<td width="215">
<html:text property="login" />
<html:errors property="login"/>
</td>
</tr>
<tr>
<td>Mot de passe:</td>
<td>
<html:password property="password" />
<html:errors property="password"/>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<html:submit property="submit"/>
</tr>
</table>
</html:form> |
entête du formulaire:
Code:
public class LoginForm extends ValidatorForm {
méthode faisant le traitement dans l'action:
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
| public ActionForward traitement(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
LoginForm loginForm = (LoginForm)form;
ActionErrors erreurs = new ActionErrors();
BeanLogin retour = new BeanLogin();
retour.setLogin(loginForm.getLogin());
retour.setPassword(loginForm.getPassword());
System.out.println("login: "+loginForm.getLogin());
System.out.println("Password: "+loginForm.getPassword());
retour = LoginServices.getInstance().VerifLogin(loginForm.getLogin(),loginForm.getPassword());
if (retour.getNoDossierPers() != null)
{
HttpSession httpSession = request.getSession(true);
httpSession.setAttribute("login",retour);
//ok il existe on charge les données et on les mets en session
return mapping.findForward("success");
}
else{
/**/
erreurs.add("password",new ActionMessage("erreur.login.action.login.unknown"));
saveMessages(request,erreurs);
return mapping.findForward("echec");
}
} |
Si quelqu'un voit une erreur (qui doit y etre c sur :mrgreen: !!) ou peut faire avancer mon scmilblick merci d'avance