4

I'm attempting to generate a dataTable with columns dinamycally, so I've a List<List> when a List inside of a List is the content of my column, but when I try to show it I can't display not much.

So, this is the code of my Bean:

@ManagedBean
@javax.faces.bean.ViewScoped
public class Controlador {

   private List<List> estadistico;

   @PostConstruct
   public void inicializar(){
      this.estadistico = new ArrayList<List>();

      this.estadistico.add(  Arrays.asList( new Integer[]{0,1,24})); 
      this.estadistico.add(  Arrays.asList( new Integer[]{5,1,34})); 
      this.estadistico.add(  Arrays.asList( new Integer[]{12,1,4})); 

   }
   //getter's and setter's
}

And this is the view:

<h:form>
    <!-- estadistico is  List<List> -->
    <p:dataTable value="#{controlador.estadistico}" var="lista">
        <!-- lista is List of numbers
             and I suppose that value is each number
         -->
        <p:columns value="#{lista}" var="value" >
               #{value}
        </p:columns>
    </p:dataTable>
</h:form>

I expected some like :

---------------
0     5    12 
---------------
1     1    1
---------------
24    34   4
---------------

what am I doing wrong?

What is the correct way?

1 Answer 1

5

The <p:columns value> cannot refer the <p:dataTable var>. It is technically and logically not possible to control the columns on a per-row basis. They have to be controlled on a per-table basis.

If your model guarantees that every nested list has the same size, then this should do:

<p:dataTable value="#{controlador.estadistico}" var="lista">
    <p:columns value="#{controlador.estadistico[0]}" columnIndexVar="i">
        #{lista[i]}
    </p:columns>
</p:dataTable>

See also the <p:columns> showcase.

2
  • Thanks for you answer faster, but I get values like a row, row 1: 0 1 24 row 2: 5 1 34 and row 3: 12 1 4
    – Cristian
    Nov 15, 2013 at 18:19
  • Right, just fix the model accordingly so that it returns exactly what the view expects.
    – BalusC
    Nov 15, 2013 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.