开发者

Primefaces 2.2.1, seems do not accept two tables on the same page

I urge the support of you guys.

I'm using JSF 2.0. Primefaces and 2.2.1.

I need to update a <p:datatable> when a row on another <p:datatable> is selected. Both on the same page.

When a Customer is selected would like to display their respective Parties.

Note: Don't want to work with FetchType.EAGER in my EntityBean.

Following is the code:

clients.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"开发者_开发技巧>   
<html xmlns="http://www.w3.org/1999/xhtml"  
      xmlns:h="http://java.sun.com/jsf/html"  
      xmlns:f="http://java.sun.com/jsf/core"  
      xmlns:ui="http://java.sun.com/jsf/facelets"  
      xmlns:p="http://primefaces.prime.com.tr/ui">  

<body>  
  <h:form>
    <p:dataTable id="clientsTable" var="c" value="#{clientMB.clients}" paginator="true"  
        rows="10" selection="#{clientMB.selected}" selectionMode="single"
    onRowSelectUpdate="partiesTable">  
        <p:column>  
            <f:facet name="header">  
                <h:outputText value="Código" />  
            </f:facet>  
            <h:outputText value="#{c.id}" />  
        </p:column>  

        <p:column>  
            <f:facet name="header">  
                <h:outputText value="Nome" />  
            </f:facet>  
            <h:outputText value="#{c.nome}" />  
        </p:column>  

        <p:column>  
            <f:facet name="header">  
                <h:outputText value="Tipo" />  
            </f:facet>  
            <h:outputText value="#{c.tipo.nome}" />  
        </p:column>  

        <p:column>  
            <f:facet name="header">  
                <h:outputText value="Descrição" />  
            </f:facet>  
            <h:outputText value="#{c.descricao}" />  
        </p:column>  

    </p:dataTable>  

    <p:spacer height="10"/>  

    <p:dataTable id="partiesTable" var="i" value="#{clientMB.parties}"  
        paginator="false" rows="5">  
        <h:column>  
            <f:facet name="header">  
                <h:outputText value="Código" />  
            </f:facet>  
            #{i.id}  
        </h:column>  
        <h:column>  
            <f:facet name="header">  
                <h:outputText value="Nome" />  
            </f:facet>  
            #{i.nome}  
        </h:column>  
        <h:column>  
            <f:facet name="header">  
                <h:outputText value="Email" />  
            </f:facet>  
            #{i.email}  
        </h:column>  
        <h:column>  
            <f:facet name="header">  
                <h:outputText value="Último acesso" />  
            </f:facet>  
            #{i.ultimoAcesso}  
        </h:column>  
        <h:column>  
            <f:facet name="header">  
                <h:outputText value="Ativo?" />  
            </f:facet>  
            #{i.ativo?'Sim':'Não'}  
        </h:column>  
        <h:column>  
            <f:facet name="header">  
                <h:outputText value="Cargo" />  
            </f:facet>  
            #{i.cargo}  
        </h:column>  
    </p:dataTable>  
  </h:form>
</body>  
</html> 

ClientMB.java:

@ViewScoped
@ManagedBean
public class ClientMB {

    /**
     * DAOS
     */
    PartDAO interDao = new PartDAO();

    /**
     * BEAN PROPERTIES
     */
    //NOVO CLIENTE
    private Client novo = new Client();

    public Client getNovo() {
        return novo;
    }
    public void setNovo(Client novo) {
        this.novo = novo;
    }

    //CLIENTE SELECIONADO
    private Client selected = new Client();

    public Client getSelected() {
        return selected;
    }
    public void setSelected(Client selected) {
        this.selected = selected;
        this.parties = partDao.list(selecionado);
    }   

    //CLIENTES
    private List<Client> clients;

    public List<Client> getClients() {
        if(clients==null){
            clients = cliDao.list();
        }
        return clients;
    }

    //INTERLOCUTORES
    private List<Part> parties;

    public List<Part> getParties() {
        parties = partDao.list(selecionado);

        return parties;
    }    

    //ACTION HANDLERS...

}

Note: A Client has none, one or more Part ies. When I change <p:datatable> by <h:datatable> everything works normally.

Thank you for any help or example code.


It seems that <p:datatable> instant row selection needs the rowSelectListener attribute and a backing bean listener method in order to work correctly.

Try to put an empty listener method in the backing bean and add the attribute to the table:

<p:dataTable id="clientsTable" var="c" 
             value="#{clientMB.clients}" paginator="true"  
             rows="10" selection="#{clientMB.selected}" 
             selectionMode="single"
             rowSelectListener="#{clientMB.onRowSelect}"
             onRowSelectUpdate="partiesTable">

in the bean:

public void onRowSelect(SelectEvent event) {
    // do something here or not  
}  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜