I am struggling hard to pass an int
value to the attribute rows
.
<p:dataTable rows="#{isLazy ? 25 : 1000}">
<f:attribute name="selectionMode" value="#{widget.selectionMode}"/>
<f:attribute name="selection" value="#{widget.selectionModel.selection}"/>
</p:dataTable>
The method from javax.faces.component.UIData
that retrieves the value is defined as
public int getRows() {
return (Integer) getStateHelper().eval(PropertyKeys.rows, 0);
}
getStateHelper().eval(PropertyKeys.rows, 0)
results in a Long
and thereafter can't be cast to Integer
.
- Is there any way to tell the parser to treat the result of the expression
isLazy ? 25 : 1000
as anint
orInteger
? - Is it just me, or is that cast so poorly written?
I am new to JSF, any help would be appreciated.
UPDATE 1: Surprisingly, it works (an Integer
is returned) if I exclude all the <f:attribute />
s from p:dataTable
. I am completely bewildered.
UPDATE 2: I've found an awful workaround. I could define a function in facelet-taglib
referring to Integer.valueOf(int)
<function>
<function-name>toInt</function-name>
<function-class>java.lang.Integer</function-class>
<function-signature>Integer valueOf(int)</function-signature>
</function>
and wrap up my value with it.
<f:attribute name="rows" value="#{bg:toInt(1000)}"/>