Dynamic columns with List<List> in <p:dataTable><p:columns>

允我心安 提交于 2019-12-19 09:22:07

问题


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:


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.



来源:https://stackoverflow.com/questions/20007189/dynamic-columns-with-listlist-in-pdatatablepcolumns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!