简体   繁体   English

jsp中没有消息显示<form:errors>

[英]No message display in jsp <form:errors>

I have a problem no message display in spring 我有个问题,春季没有消息显示
This is my code but when I call the method getErrorCount() of BindingResult it show that I have three errors but in my form:errors in the jsp page no message display 这是我的代码,但是当我调用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";


}

and here is the form part in the jsp page 这是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>

Your code should be look like this 您的代码应如下所示

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

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

model.addAttribute("AdpubForm",adfrm); overrides your actual AdpubForm object and binding results. 会覆盖您的实际AdpubForm对象和绑定结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM