java - 用户输入的数据未在托管 bean 中更新

标签 java jsf jakarta-ee jsf-2

我有一个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/

相关文章:

java - JSF 与 JavaFX : Pros & Cons

jsf - 如何启用/禁用 JSF 命令按钮

java - tomcat 6.0中ejb程序放在哪里以及如何部署?

Java-使用InputStream作为文件

java - 如何绕过 "This expression is not supported in the current option setting"错误

jsf - 根据用户权限导航到 preRenderViewEvent 中的不同页面; ExternalContext#dispatch() 不起作用

JavaANPR本地车牌识别(Localizing)

Java EE 和桌面应用程序

java - 使用 s :action in JSP 时如何修复 java.lang.StackOverflowError

java - OpenGL 过滤参数和 mipmap