jsp <form:errors>中不显示任何消息

时间:2015-08-24 12:04:16

标签: java spring jsp spring-mvc

我有一个问题,春天没有信息显示 这是我的代码,但是当我调用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>

1 个答案:

答案 0 :(得分:1)

您的代码应如下所示

public String EditUsers(@Valid AdpubForm adfrm ,BindingResult result,Model model){

        if(result.hasErrors()){
            return "UsersManager";
        }

model.addAttribute("AdpubForm",adfrm);会覆盖您实际的AdpubForm对象和绑定结果。