Problème de rechargement avec Validator
Bonjour,
Je souhaite mettre en place une validation sur un formulaire de login.
Donc je souhaitais utiliser le plug in validator, je rencontre donc un problême, quand je submit, j'ai une erreur :
"Cannot find bean: "theso" in any scope". donc en gros, il recupere pas tout lors du rechargement de la page....
Pour infos, je controlais le form avec un simple javascript et ca fonctionnait impeccable, mais pour le faire cote serveur...je suis embeter a cause de ca...
j'ai suivi les differents post du forum a ce sujet...et je suis toujours bloque...
Quelqu'un aurait il deja eu ce problême ???
Voila mes codes :
le html :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
<div>
<strong>Administration :</strong>
<html:form action="/login" focus="login" onsubmit="return validateloginForm(this);">
<div align="right" style="border: double; 1px red; margin-right: 80px;">
Login:<input name="login" type="text" value="" size="15"/><br/>
<html:errors name="error.login" />
Password:<input name="password" type="password" value="" size="15"/><br/>
<html:errors name="error.password" />
<html:submit >Connection</html:submit>
</div>
</html:form>
</div> |
le form:
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
|
public class LoginForm extends ValidatorForm {
private static final long serialVersionUID = 1L;
/** login property */
private String login;
/** password property */
private String password;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
} |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws SQLException, NoSuchAlgorithmException{
RequeteHibernate req = new RequeteHibernate();
Vector<NodeThesoMT> thesaurus = req.getThesaurus(); //recuperation des thesaurus et Microthesaurus
request.setAttribute("theso",thesaurus); //c'est celui la qu'il ne retrouve pas lord du rechargemment
// if(login.equalsIgnoreCase("bruno")&& password.equalsIgnoreCase("bruno")){
// return mapping.findForward("admin");
// }
//
// return mapping.findForward("utilisateur");
LoginForm loginForm = (LoginForm) form;
String forward = null;
String username = null;
String encodedPassword = null;
int role = 0;
// password saisie;
String textPassword = loginForm.getPassword();
// login saisie
String login=loginForm.getLogin();
UtilisateurDAO dao = new UtilisateurDAO();
Utilisateur user = new Utilisateur();
List userList = dao.findByUsername(login);
if (userList.size() > 0) {
for(Iterator iter = userList.iterator(); iter.hasNext();)
{
user = (Utilisateur) iter.next();
username = user.getUsername();
encodedPassword = user.getPassword(); //pasword encode en base
role = user.getIdRole();
if(MD5Password.testPassword(textPassword, encodedPassword) && login.equalsIgnoreCase(username)){
//forward selon le role
if(role == 1){
forward = "admin";
}else if(role == 2){
forward = "pro";
}else if(role == 3){
forward = "utilisateur";
}
}
}
}
request.setAttribute("username", username);
return mapping.findForward(forward);
}
} |
le validator rules :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
<formset language="">
<form name="loginForm">
<field property="login" depends="required">
<msg name="required" key="error.login"/>
</field>
<field property="password" depends="required">
<msg name="required" key="error.password"/>
</field>
</form>
</formset> |
et enfin, le struts.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
<action
attribute="loginForm"
input="/main.jsp"
name="loginForm"
path="/login"
type="action.LoginAction"
validate="true">
<set-property property="cancellable" value="true" />
<forward name="admin" path="/administration.jsp" />
<forward name="pro" path="/professionnel.jsp" />
<forward name="utilisateur" path="/main.jsp" />
</action> |