0

我在使用 Primefaces 对话在对话中显示所选项目的数据时遇到问题。setSelectedUsers 方法将触发,但对话框不会显示用户对象的数据。知道我在这里缺少什么!我查看了 primefaces 展示,我看不出我在哪里做错了!

Primefaces 3.4、Mojarra 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;
        }        
}
4

1 回答 1

1

在 commandLink 中,您必须更新对话框内容 (update="display"):

<p:commandLink value="#{user.username}" update="display" oncomplete="userDialog.show()" title="View">
      <f:setPropertyActionListener value="#{user}" target="#{userController.selectedUser}" />    
</p:commandLink>
于 2012-09-07T12:37:00.863 回答