0

I have a datatable with a column:

<p:dataTable value="#{cc.attrs.bean.model}" 
...
  <p:column style="width:#{bean.getWidth('colDate', 55)}px;"

It seems that the bean.getWidth method is called for every row in the table. Thus, when having 100 rows, the method is called a hundred times. I expected the method to be called only once.

Am I wrong?

matthias
  • 1,938
  • 23
  • 51
  • For the 'width' it is to often. If you keep in mind that it is for a column, but if you want to use it to style individual column-row **combinations** (= a cell) then the whole style must be evaluated for each row and it must be called per row. PrimeFaces cannot know how you want to use it, so it must be called this often. The answer with the cache is the way to go – Kukeltje Jan 13 '17 at 13:39

2 Answers2

1

No, it's right. You can cache the value into your bean or use JSTL

<c:set var="width" value="#{bean.getWidth('colDate', 55)}" />

<p:dataTable value="#{cc.attrs.bean.model}" 
 ...
 <p:column style="width:#{width}px;"

You can find more infos here https://stackoverflow.com/tags/jstl/info. Don't forget the namespace .

Community
  • 1
  • 1
jklee
  • 2,198
  • 2
  • 15
  • 25
0

you can save result of getWidth in managed bean attribute then use this in column style

Landaida
  • 134
  • 2
  • 8