在Dialog中从DataTable更改变量

时间:2011-11-25 22:56:12

标签: java java-ee primefaces javabeans

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

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

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

Glassfish: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

1 个答案:

答案 0 :(得分:1)

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

由于将 appendToBody 设置为 true 可能会导致对话超出表单< / strong> component。来自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.