我有一个html页面(editprofile.xhtml),它显示了数据库中保存的数据。我面临的问题是,当我在屏幕中编辑一些数据并单击更新按钮时,编辑的数据不会进入 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>
上面的页面填充了加载时的现有数据,但是如果我编辑并说更新该值将为空
最佳答案
从命令按钮中删除immediate="true"属性。
它跳过 jsf 应用程序生命周期的 updateModel 阶段,该阶段负责调用 bean 中定义的属性的 setter,因此不会更新 bean 值。
了解有关 how immediate attributes affects JSF lifecycle 的更多信息。 -由 @BalusC 于 2006 年 9 月 27 日编写
关于java - 用户输入的数据未在托管 bean 中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10136102/