0

我是主要面孔的新手。我有一个具有某些属性的用户,我已经显示了用户数据表。现在的要求是,在单击特定用户行时,与该用户关联的数据必须显示在表格下方的同一窗口中,请告诉我尝试使用布局的方法,但问题是我如何获取数据相同的窗口。如果可能的话,给我学习站点链接做同样的事情或告诉我程序谢谢

package com.poc.faces;
import java.util.Collection;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.SelectEvent;
import org.primefaces.event.UnselectEvent;

@ManagedBean
@ViewScoped
public class UserManagedBean {
    UserService service = new UserService();

    private String username;
    private String password;
    private String searchUser;
    private Collection<User> searchUsersResults;
    private User selectedUser;

    public UserService getService() {
        return service;
    }

    public void setService(UserService service) {
        this.service = service;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSearchUser() {
        return searchUser;
    }

    public void setSearchUser(String searchUser) {
        this.searchUser = searchUser;
    }

    public Collection<User> getSearchUsersResults() {
        return searchUsersResults = service.getAllUser();
    }

    public void setSearchUsersResults(Collection<User> searchUsersResults) {
        this.searchUsersResults = searchUsersResults;
    }

    public User getSelectedUser() {
        return selectedUser;
    }

    public String login() {

        if ("sas".equalsIgnoreCase(getUsername())
                && "sas".equals(getPassword())) {
            return "home";
        } else {

            FacesContext context = FacesContext.getCurrentInstance();

            context.addMessage("username", new FacesMessage(
                    "Invalid UserName and Password"));

            return "login";

        }
    }



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

    public void onRowSelect(SelectEvent event) {
        FacesMessage msg = new FacesMessage("User Selected",
                ((User) event.getObject()).getUsername());

        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

    public void onRowUnselect(UnselectEvent event) {
        FacesMessage msg = new FacesMessage("Car Unselected",
                ((User) event.getObject()).getUsername());

        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
}

这个 home.xhtml

我在哪里获取表格数据

    <html xmlns="http://www.w3c.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>
    <link href="../css/style.css" type="text/css" rel="stylesheet" />
</h:head>
<h:body>
    <p:layout style="min-width:400px;min-height:200px;" id="layout">
        <p:layoutUnit position="center">
            <h:form prependId="false">
                <h:panelGroup layout="block" id="left_column"
                    style="width: 2px; left: 2px; margin-left: 2px">
                    <center>
                        <H1>UserData</H1>
                        <br />

                        <p:dataTable value="#{userManagedBean.searchUsersResults}"
                            var="user" pagination="true" rows="5" styleClass="userTable"
                            headerClass="userTableHeader"
                            rowClasses="userTableOddRow,userTableEvenRow"
                            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                            rowsPerPageTemplate="5,10,15">
                            <!-- <p:ajax event="rowSelect" listener="#{userManagedBean.onRowSelect}"
                        update=":form:display :form:growl" oncomplete="carDialog.show()" />
                    <p:ajax event="rowUnselect"
                        listener="#{userManagedBean.onRowUnselect}" update=":form:growl" /> -->


                            <p:column>
                                <f:facet name="header">UserId</f:facet>
                                <h:outputText value="#{user.userId}"></h:outputText>
                            </p:column>
                            <p:column>
                                <f:facet name="header">Username</f:facet>
                                <h:outputText value="#{user.username}"></h:outputText>
                            </p:column>
                            <p:column>
                                <f:facet name="header">EmailId</f:facet>
                                <h:outputText value=" #{user.emailId}"></h:outputText>
                            </p:column>
                            <p:column>
                                <f:facet name="header">Phone</f:facet>
                                <h:outputText value=" #{user.phone}"></h:outputText>
                            </p:column>
                        </p:dataTable>
                    </center>
                </h:panelGroup>
            </h:form>

            <p:layoutUnit position="west" resizable="true" size="100"
                minSize="40" maxSize="200">  
        West  
        </p:layoutUnit>
    </p:layout>
    </h:body>
</html>
4

1 回答 1

-1

我不认为 PF 中有一个称为 layoutUnit 的组件。你确定不是布局?

于 2013-06-27T06:26:25.913 回答