2012-04-13 33 views
0

我有一个html页面(editprofile.xhtml),它显示了保存在数据库中的数据。我面临的问题是,当我在屏幕上编辑一些数据并单击更新按钮时,编辑的数据不会发送到bean,它的值为null,从而导致错误。用户输入的数据未在托管bean中更新

<h:form id="editProfileForm"> 
<f:facet name="label"> 
    <h:outputText value="Edit User Profile" /> 
</f:facet>    
<rich:panel header="Edit User Profile" style="font-size:10pt" >   
    <rich:simpleTogglePanel switchType="client" opened="true"> 
<f:facet name="header">Registration Details</f:facet> 
<table> 
    <tbody> 
     <tr> 
      <td>Login Name</td> 
      <td> 
      <h:inputText size="15" id="loginName" required="true" 
       value="#{EditUserProfileBean.loginName}"> 
      <rich:ajaxValidator event="onblur" /> 
      </h:inputText> 
      </td> 
      <td></td> 
      <td>Password</td> 
      <td><h:inputSecret size="12" id="password" required="true" 
       value="#{EditUserProfileBean.password}" > 
      <rich:ajaxValidator event="onblur" /> 
      </h:inputSecret> 
      </td> 
      <td>Confirm Password</td> 
      <td><h:inputSecret size="12" id="confirmpassword" required="true" 
       value="#{EditUserProfileBean.confirmpassword}" > 
      <rich:ajaxValidator event="onblur" /> 
      </h:inputSecret> 
      </td> 
     </tr> 
</rich:simpleTogglePanel> 
<h:commandButton id="editProfile" action="#{EditUserProfileBean.saveEditProfileAction}" immediate="true" value="Update Profile" /> 
    </rich:panel> 
</h:form> 

上述页面充满了负载现有的数据,但如果我编辑和更新说的价值是被空

+0

您是否在bean中定义了要传递属性的setter?此代码片段是否在表单中?代码在哪里提交表单,还是Ajax? – JMelnik 2012-04-13 06:22:44

+0

请注意我的更新 – Mango 2012-04-13 06:42:29

+1

尝试从commandButton中删除immediate =“true”。 – JMelnik 2012-04-13 06:44:50

回答

1

从您的commandButton立即删除=“true”属性。

它跳过了jsf应用程序生命周期的updateModel阶段,它负责调用bean中定义的属性上的setter,因此不更新bean值。

阅读更多有关how immediate attributes affects JSF lifecycle的资讯。 -written by @BalusC on 27/09/2006

0

immediate = true允许您在未经验证的情况下提交表单。并解决你的问题,你这样做。

在你的saveEditProfileAction命令按钮中获取当前用户对象,这意味着编辑对象并调用save方法..框架将自动调用服务类的更新或插入方法。因此你的服务类必须包含inser,更新,删除方法。

saveEditProfileAction{ 
super.save(getUserObject()); 
} 

所以在调用save方法时,控件会根据表单状态进入服务类的inser或update方法。