在对话框中更改数据表中的变量

发布于 2024-12-18 03:10:19 字数 2540 浏览 2 评论 0原文

我有一个关于更新 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>

示例视图

I have a question about updating variable inside dataTable component, which was sended to dialog component.

I want to have dialog box with options. There are informations about user (user data editing).
ManageUsers class have UserDAO selectedUser property, UserDAO class contains User POJO (login, email etc).
ManageUsers.updateUser persists data in database.

How can I update selectedUser through inputText?
I can not use p:inplace component because I have a problem with h:forms and facelets (changing to production stage does not resolve this problem).

Glassfish: 3.1
Primefaces: 2.2
JSF: 2.1 (now 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九厘米的零° 2024-12-25 03:10:19
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 可能会导致 dialog 脱离 form 组件。来自 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.
PROBLEM RESOLVED. Setters was not fired. I don't know why, but when I remove appendToBody="true", then setters work perfectly. Anyone know why?

The setters weren't fired because setting appendToBody to true might cause the dialog to be out the form component.From the Primefaces User Guide (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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文