java - 从对话框中的数据表更改变量

标签 java jakarta-ee primefaces javabeans

我有一个关于更新 dataTable 组件内部变量的问题,该变量已发送到对话框组件。

我想要一个带有选项的对话框。有关于用户的信息(用户数据编辑)。 ManageUsers 类具有 UserDAO selectedUser 属性,UserDAO 类包含用户 POJO(登录、电子邮件等)。
ManageUsers.updateUser 将数据保存在数据库中。

如何通过 inputText 更新 selectedUser? 我无法使用 p:inplace 组件,因为我的 h:formsfacelets 存在问题(更改到生产阶段并不能解决此问题)。

玻璃鱼:3.1
Primefaces:2.2
JSF:2.1(现在是 MyFaces 2.1.3)

<h:form prependId="false"> 

   <p:growl id="growl"/>

   <!--            Data table with all users-->
   <p:dataTable id="userTable" var="u" value="#{manageUsers.users}"> 

      <p:column headerText="login" style="width:150px" filterBy="#{u.user.login}" filterMatchMode="contains"> 
         <h:outputText value="#{u.user.login}" />
      </p:column> 

      <p:column headerText="email" style="width:150px" filterBy="#{u.user.email}" filterMatchMode="contains"> 
         <h:outputText value="#{u.user.email}" /> 
      </p:column>

      <p:column headerText="apikey" style="width:150px" filterBy="#{u.user.apikey}" filterMatchMode="startsWith"> 
         <h:outputText value="#{u.user.apikey}" />
      </p:column>

      <p:column headerText="Options" > 
         <p:commandButton update="display" oncomplete="userDialog.show()" 
                      image="ui-icon ui-icon-search"> 
            <f:setPropertyActionListener value="#{u}" target="#{manageUsers.selectedUser}" /> 
         </p:commandButton> 
      </p:column> 

   </p:dataTable>   

   <!--            Dialog box with options-->
   <p:dialog appendToBody="true" header="User Detail" widgetVar="userDialog" resizable="false" 
           width="500" showEffect="explode" hideEffect="explode" onCloseUpdate="growl,userTable"> 
      <h:panelGrid id="display" columns="2" cellpadding="4"> 

         <h:outputText value="Login" />
         <p:inputText  required="true" value="#{manageUsers.selectedUser.user.login}" />

         <h:outputText value="Email" />
         <p:inputText  required="true" value="#{manageUsers.selectedUser.user.email}" />

         <p:commandButton value="save and exit" action="#{manageUsers.updateUser}" update="growl,userTable" onclick="userDialog.hide()" />

      </h:panelGrid> 
   </p:dialog>

</h:form>

Example view

最佳答案

PROBLEM RESOLVED. Setters was not fired. I don't know why, but when I remove appendToBody="true", then setters work perfectly. Anyone know why?

setter 没有被触发,因为将 appendToBody 设置为 true 可能会导致对话框脱离表单> 组件。来自 Primefaces 用户指南 (3.0.M4):

    Use appendToBody with care as the page definition and html dom would be different, for
example if dialog is inside an h:form component and appendToBody is enabled, on the browser
dialog would be outside of form and may cause unexpected results. In this case, nest a form inside
a dialog.

关于java - 从对话框中的数据表更改变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8274924/

相关文章:

java - 子查询中IN子句的Hibernate Criteria等效项?

java - 如何停止另一个类(class)的连续声音循环?

java - Servlet.init() 和 Filter.init() 调用顺序

javascript - 如何使用从 MySQL 数据库获取的 JSP 代码打破日期时间格式并显示在单独的文本框中

sorting - sortMode ="multiple"和 <p :dataTable> clears multisort meta during pagination 中的惰性 ="true"

java - 目标无法到达,标识符 'contactBean' 解析为 null

java - 在 TreeTable 的同一列中添加许多对象类型

java - 监听所有菜单项的 JFrame Action 监听器?

java - 在 Web 浏览器中运行 Java 应用程序

java - 避免重复记录 - HashSet