2011-06-20 31 views
2

我呼籲你們的支持。Primefaces 2.2.1,似乎不接受在同一頁上的兩個表

我正在使用JSF 2.0。 Primefaces和2.2.1。

我需要更新<p:datatable>當另一個<p:datatable>上的行被選中。兩個在同一頁面上。

當客戶被選中時想顯示他們各自的締約方。

注意:不希望在我的EntityBean中使用FetchType.EAGER。

以下是代碼:

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... 

} 

注:客戶現在沒有,一個或多個部分IES。 當我通過<h:datatable>更改<p:datatable>一切正常。

感謝您提供任何幫助或示例代碼。

+0

也許你過於簡單化的觀點,但是這兩個表是在''裏面,對吧? – BalusC

+0

是的,他們是。我已經翻譯並簡化了一些,以使它更容易,因爲代碼是葡萄牙語。 –

回答

0

看起來<p:datatable>即時行選擇需要rowSelectListener屬性和一個支持bean監聽器方法才能正常工作。

嘗試把一個空的偵聽器方法的支持bean和屬性添加到表:在bean

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

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

謝謝,我已經嘗試過,但它仍然無效。這似乎是Primefaces的一個缺陷。 有趣的是,它創建了html表格和行(),只丟失了單元格(​​)請參閱: –

+0

您是否調試過驗證列表是否已填充到支持bean中?你嘗試用@form更新整個表單嗎? –

+0

1)是的,我做了,支持bean打印數組,在後臺bean中一切正常。 2)我從來沒有使用@Form,我會嘗試! –

相關問題