How popular a p: datatable with a List that contains two List attributes inside?

3

I spent all day today trying to do something that is supposed to be simple but I could not. It's the following, I'm using the primefaces and I'm new to it yet and I need somehow my <p:datatable> popular with a list of objects. Goodbye then. But inside the list object I have two more lists. Example:

List<GastosMes> gastosAno

public class GastosMes {
   public int mesReferente
   List<Conta> contas
   List<Comida> comidas
} 

public class Conta{
   public Double valorGas;
   public Double valorAgua;
   public Double totalContas;
}

public class Comida{
   public Double valorFeijao;
   public Double valorArroz;
   public Double totalComida;
}

Assuming this silly example, I have two lists within the MyMoney object. The MoneyStories list is then passed to my page (returned by theAnoController spendStoriesAnoList), but then I can only display OR the Accounts OR the Meals. My xhtml looks like this:

<p:dataTable value="#{gastosAnoController.gastosAnoList}"
                var="gastosMes">

                <p:columnGroup type="header">
                    <p:row>
                        <p:column rowspan="2" headerText="Mês" style="width:100px" />
                        <p:column colspan="3" headerText="Gastos do Ano Corrente" />
                    </p:row>
                    <p:row>
                        <p:column headerText="Gastos Contas" />
                        <p:column headerText="Gastos Comida" />
                        <p:column headerText="Total Líquido" />
                    </p:row>
                </p:columnGroup>                                        
                <p:subTable var="conta" value="#{gastosMes.contas}">
                    <f:facet name="header">
                        <h:outputText value="#{gastosMes.mesReferente}" />
                    </f:facet>  
                    <p:column>                      
                    </p:column> 
                    <p:column >
                        <h:outputText value="#{contas.valorFeijao}" />
                    </p:column>
                    <p:column>
                        <h:outputText value="#{contas.valorArroz}" />
                    </p:column>     
                    <p:column>
                        <h:outputText value="#{conta.totalContas}" />
                    </p:column>                     
                </p:subTable>                   
</p:dataTable>

As you can see, I created a subtable (I searched a lot and only found it as a "solution") and I was able to populate the columns with the Attributes from the Accounts list. The problem is that I need to populate the table with the Food list attributes too, how do I? Any idea? I tried putting two subtables, two datatables, nothing was cool. If anyone can help me.

NOTE: Since I'm going to be separated by month, I thought it would be more practical to create the MMS class and within it have a list of accounts and foods for this month.

    
asked by anonymous 16.10.2016 / 05:51

1 answer

1

When you created your subTable you could have used the value of dataTable as a reference, for example:

<p:subTable var="bean" value="#{gastosMes}">
                    <f:facet name="header">
                        <h:outputText value="#{gastosMes.mesReferente}" />
                    </f:facet>  
                    <p:column>
                    <h:outputText value="#{bean.valorGas}" />                     
                    </p:column> 
                    <p:column >
                        <h:outputText value="#{bean.valorFeijao}" />
                    </p:column>                    
                </p:subTable> 
    
30.01.2017 / 13:04