2012-09-07 57 views
0

我在使用Primefaces對話框在對話框中顯示選定項目的數據時遇到了問題。 setSelectedUsers方法將觸發,但對話框將不顯示用戶對象的數據。任何想法,我在這裏失蹤!我看了一下primefaces展示,我看不到我做錯了什麼!顯示選定項目的數據(JSF,Primefaces)

Primefaces 3.4,鑽嘴魚科2.1,Java EE 6的

我希望得到任何幫助。由於

<h:form prependId="false"> 
      <p:dataTable id="dataTable" var="user" value="#{userController.lazyModel}" styleClass="userDataTableStyle" 
        paginator="true" rows="10" selection="#{userController.selectedUsers}" 
        paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
        lazy="true" rowsPerPageTemplate="10,50,100,150"> 
      <f:facet name="header"> 
       User List 
      </f:facet> 
      <f:facet name="header"> 
       Selection 
      </f:facet> 
      <p:column selectionMode="multiple" style="width:18px" /> 
      <p:column> 
       <f:facet name="header"> 
        <h:outputText value="Username" /> 
       </f:facet> 
       <p:commandLink value="#{user.username}" oncomplete="userDialog.show()" title="View"> 
        <f:setPropertyActionListener value="#{user}" target="#{userController.selectedUser}" />  
       </p:commandLink> 
      </p:column> 

      <p:column> 
       <f:facet name="header"> 
        <h:outputText value="Firstname" /> 
       </f:facet> 
       <h:outputText value="#{user.firstname}" /> 
      </p:column> 

      <p:column> 
       <f:facet name="header"> 
        <h:outputText value="Lastname" /> 
       </f:facet> 
       <h:outputText value="#{user.lastname}" /> 
      </p:column> 

      <p:column> 
       <f:facet name="header"> 
        <h:outputText value="Email" /> 
       </f:facet> 
       <h:outputText value="#{user.email}" /> 
      </p:column> 
      <f:facet name="footer"> 
       <p:commandButton value="Create User" action="/admin/NewUser.xhtml?faces-redirect=true" ajax="false" icon="ui-icon-star"/> 
       <p:commandButton value="Delete Users" actionListener="#{userController.doDeleteUsers}" update="dataTable" icon="ui-icon-trash"/> 
      </f:facet> 
     </p:dataTable> 
     <p:dialog header="Car Detail" widgetVar="userDialog" resizable="false" id="userDlg" > 
      <h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;"> 
       <h:outputText value="Username" /> 
       <h:outputText value="#{userController.selectedUser.username}" style="font-weight:bold"/> 
      </h:panelGrid> 
     </p:dialog> 
    </h:form> 

Java代碼

@ManagedBean(name="userController") 
@ViewScoped 
public class UserController implements Serializable { 

     private @EJB UserEJB userEJB;  
     private User[] selectedUsers; 
     private List<User> lazyUserList;  
     private Address address = new Address(); 
     private User user = new User(); 
     private User selectedUser; 
     private LazyDataModel<User> lazyModel; 

    public UserController() { 
      lazyModel = new LazyUserDataModel(lazyUserList); 
    } 

     public String doNewUser() { 
      return "admin/NewUser.xhtml?faces-redirect=true"; 
     } 

     public String doCreateUser() { 
      userEJB.persistUser(user); 
      return "UserList.xhtml?faces-redirect=true"; 
     } 

     public void doDeleteUsers(ActionEvent actionEvent){ 
      userEJB.deleteUsers(selectedUsers); 
     } 

     public User getSelectedUser() { 
      return selectedUser; 
     } 

     public void setSelectedUser(User selectedUser) { 
      this.selectedUser = selectedUser; 
     } 

     public User[] getSelectedUsers() { 
      return selectedUsers; 
     } 

     public void setSelectedUsers(User[] selectedUsers) { 
      this.selectedUsers = selectedUsers; 
     } 

     public void onRowSelect(ActionEvent event) { 
      if(selectedUser == null) 
       return; 
      String userName = selectedUser.getUsername(); 
     } 

     public Address getAddress() { 
      return address; 
     } 

     public void setAddress(Address address) { 
      this.address = address; 
     } 

     public User getUser() { 
      return user; 
     } 

     public void setUser(User user) { 
      this.user = user; 
     } 

    public List<User> getUsers() { 
     return lazyUserList; 
    } 

     public LazyDataModel<User> getLazyModel() { 
      return lazyModel; 
     }   
} 

回答

1

從commandLink,你必須更新對話框內容(更新= 「顯示」):

<p:commandLink value="#{user.username}" update="display" oncomplete="userDialog.show()" title="View"> 
     <f:setPropertyActionListener value="#{user}" target="#{userController.selectedUser}" />  
</p:commandLink> 
+1

感謝達米安,將ID =「形式「到forme和update =」:form:display「到幫助的commandlink。乾杯... – Pinchy