无法更新实体

时间:2013-05-21 06:35:18

标签: jpa entity

这是方法

 public  String changePassword(int id){
       FacesContext context = FacesContext.getCurrentInstance();                   
      try{
          utx.begin();
           Wuser wuser= em.find(Wuser.class, id);
           wuser.setPassword(passwordv);
           utx.commit();
        return "login";
   }catch (Exception e) {               
                FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                        "Error changing password! ",
                                                        "Unexpected error when changing password for  your account.  Please contact the system Administrator");
                context.addMessage(null, message);
                Logger.getAnonymousLogger().log(Level.SEVERE,
                                                "Unable to change password ",
                                                e);
                return null;
        }
   }

这是jsf页面

 <f:view>
        <h:form id="change">            
            <h:panelGrid columns="3" border="0">
                Username: <h:inputText id="username" 
                                       requiredMessage="*"
                                       value="#{usermanager.username}"
                                       required="true"/>
                          <h:message for="change:username" style="color: red"/>
               Old Password: <h:inputSecret id="password"    
                                         requiredMessage="*"
                                         value="#{usermanager.password}"
                                         required="true"/>
                          <h:message for="change:password" style="color: red"/>
               New Password (verify): <h:inputSecret id="passwordv"   
                                                  requiredMessage="*"
                                                  value="#{usermanager.passwordv}"
                                                  required="true"/>
                                   <h:message for="change:passwordv" style="color: red"/>
            Id:  <h:inputText id="id" 
                                       requiredMessage="*"
                                       value="#{usermanager.id}"
                                       required="true"/>
                          <h:message for="change:id" style="color: red"/> 
            </h:panelGrid>
            <h:commandButton id="submit" 
                             value="Create"
                             action="#{usermanager.changePassword(id)}"/>


            <h:messages style="color: red" globalOnly="true"/>
        </h:form>

2 个答案:

答案 0 :(得分:0)

Hej radoslaf,

将你的h:commitButton代码更改为:

<h:commandButton id="submit" 
                             value="Create"
                             action="#{usermanager.changePassword(usermanager.id)}"/>

属性“id”仅与usermanager有关,我认为它提供了您要编辑的currentUser对象。

Greets Patrick

答案 1 :(得分:0)

代码没有问题。问题是数据库用户没有更新权限。

我在检查服务器日志时发现错误。

我已经适当修改了代码以验证用户。感谢所有帮助