0

I'm trying to nest a ui:repeat or another DataTable inside of my original DataTable so I can display another list.

So the original DataTable uses one list and the nested ui:repeat is using another but the ui:repeat isn't iterating through it, instead it's just displaying the entire list for each DataTable row.

Here's the nested ui:repeat I have currently

<h:column>
    <ui:repeat value="#{readingBean.list}" var="amount">
        #{amount}
    </ui:repeat>
    <f:facet name="header">Amount Used</f:facet>
</h:column>

This is where I get the data for populating the original DataTable

public List<Reading> getReadingData() {
    List<Reading> readingByMeter = (em.createNamedQuery("Reading.findByMeter").setParameter("meter",name)).getResultList();
    return readingByMeter;
}

Here's the second list I want nested in

public List<Double> getList() {
    List<Reading> readingData = (em.createNamedQuery("Reading.findByMeter").setParameter("meter",name)).getResultList();


    List<Double> list = new ArrayList<Double>();
    for (int i = 1; i < readingData.size(); i++)
    {
        list.add((readingData.get(i).getReading().doubleValue() - readingData.get(i - 1).getReading().doubleValue()) / 50); 
    }

    return list;
}

So for the second list I'm calculating an amount by subtracting the 2nd element in the original list by the first element and then dividing by 50. So it would be (1 - (1 -1)) / 50 and then (2 - (2 - 1)) / 50 and so on. Taking the next element and subtracting it by the previous.

This is what it looks like with the ui:repeat inside of the DataTable currently

DataTable Display Current - But I want it to be listed as

2050 | 43.0
4200 | 38.0

and so on

So my question is how to display my second list in the original datatable's columns so that it appears as above. I searched a lot and couldn't find any solution so any help is appreciated. Also please let me know if you need any more information

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Broken
  • 1
  • In other words, you actually don't need to display the entire list, but just a single item? Why are you using instead of accessing the single item of interest? – BalusC Jan 05 '18 at 22:47
  • I think BalusC meant to add 'in each row' right before the first questionmark – Kukeltje Jan 06 '18 at 00:58
  • @BalusC So I'm able to do get a single item by removing the ui:repeat entirely and doing '#{readingBean.list[0]}' , accessing the index but then that would make that entire Amount Used column equal to the 0 index of the list. I want to iterate through it and display each one in their respective rows and this method wont work as I cant use a for loop in JSF (foreach doesnt have index) – Broken Jan 06 '18 at 01:44

0 Answers0