我有个问题,春季没有消息显示
这是我的代码,但是当我调用BindingResult的getErrorCount()方法时,它表明我有三个错误,但形式如下:jsp页面中的错误没有消息显示
public String EditUsers(@Valid AdpubForm adfrm ,BindingResult result,Model model)
{
System.out.println("operation : "+operation);
if(result.hasErrors())
{
adfrm=new AdpubForm();
adfrm.setUserOperation("new");
operation="new";
List<User> users =metier.getAllUsers();
adfrm.setUsers(users);
model.addAttribute("AdpubForm",adfrm);
return "UsersManager";
}
if(operation.equals("new"))
{
System.out.println("add new user");
User user = metier.addUser(new User(adfrm.getLogin(),adfrm.getMpasse(),adfrm.getTypeUser()));
adfrm.clearModelUser();
adfrm.setExceptionUser("Info : Utilisateur créé avec succès");
List<User> users =metier.getAllUsers();
adfrm.setUsers(users);
}
else if(operation.equals("update"))
{
System.out.println("update user");
User user=metier.getUser(code_user);
user.setLogin(adfrm.getLogin());
user.setMpasse(adfrm.getMpasse());
user.setType(adfrm.getTypeUser());
metier.updateUser(user);
adfrm.setUserOperation("new");
operation="new";
adfrm.clearModelUser();
List<User> users =metier.getAllUsers();
adfrm.setExceptionUser("Info : Modification avec succès");
adfrm.setUsers(users);
}
model.addAttribute("AdpubForm",adfrm);
return "UsersManager";
}
这是jsp页面中的表单部分
<f:form name="UserManagerForm" modelAttribute="AdpubForm"
method="post" class="form-inline" action="EditUsers"
">
<div class="form-group">
<table class="table-condensed">
<tr>
<td><f:label path="login">Nom d'utilisateur</f:label> <f:input
path="login" name="login" /></td>
<td><f:label path="mpasse">Mot de passe</f:label> <f:password
path="mpasse" name="mpasse" /></td>
<td><f:errors path="mpasse" cssclass="error"></f:errors></td>
<td><f:label path="cmpasse">Confirmer le mot de passe</f:label>
<f:password path="cmpasse" /></td>
<td><f:label path="typeUser">Type de compte : </f:label>
<f:select path="typeUser">
<f:option value="Admin" label="admin " />
<f:option value="User" label="user " />
</f:select></td>
</tr>
</table>
</br> <input type="reset" class="btn btn-info btn-xs"
value="Nouveau">
<c:if test="${AdpubForm.userOperation =='new'}">
<input type="submit" class="btn btn-info btn-xs"
value="Ajouter" />
</c:if>
<c:if test="${AdpubForm.userOperation =='update'}">
<input type="submit" class="btn btn-info btn-xs"
value="Modifier" />
</c:if>
</div>
<f:errors path="login" />
</f:form>
最佳答案
您的代码应如下所示
public String EditUsers(@Valid AdpubForm adfrm ,BindingResult result,Model model){
if(result.hasErrors()){
return "UsersManager";
}
model.addAttribute("AdpubForm",adfrm);
会覆盖您的实际AdpubForm对象和绑定结果。关于java - jsp <form:errors>中没有消息显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32181882/