[英]JSF composite:attribute with f:attribute conversion error
I'm implementing a JSF component and need to conditionally add some attributes. 我正在实现一个JSF组件,需要有条件地添加一些属性。 This question is similar to a previous JSF: p:dataTable with f:attribute results in "argument type mismatch" error , but with a completely different error message, so I raised a new question.
这个问题类似于以前的JSF:p:dataTable with f:attribute导致“参数类型不匹配”错误 ,但是有一个完全不同的错误消息,所以我提出了一个新问题。
<composite:interface>
<composite:attribute name="filter" required="false" default="false"
type="java.lang.Boolean"/>
<composite:attribute name="rows" required="false" default="15"
type="java.lang.Integer"/>
...
</composite:interface>
<composite:implementation>
<p:dataTable ivar="p" value="#{cc.attrs.dm}">
<c:if test="#{cc.attrs.filter}">
<f:attribute name="paginator" value="#{true}"/>
<f:attribute name="rows" value="#{cc.attrs.rows}"/>
</c:if>
...
<p:dataTable>
</composite:implementation>
This results in an error java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
. 这会导致
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
错误java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
。 Even if I manually set this, I get errors: 即使我手动设置这个,我也会收到错误:
<f:attribute name="rows" value="15"/> ... argument type mismatch
<f:attribute name="rows" value="#{15}"/> ... java.lang.Long cannot be cast
to java.lang.Integer
If I add the attribute directly, there is no exception and the correct number of rows is diplayed: 如果我直接添加属性,则没有异常,并且显示正确的行数:
<p:dataTable var="p" value="#{cc.attrs.dm}" rows="#{cc.attrs.rows}">
This is indeed an unfortunate corner case with numbers in EL and composite component attributes. 对于EL和复合组件属性中的数字,这确实是一个不幸的角落案例。 There's no solution for this.
对此没有解决方案。 The type information is not available in
#{cc.attrs}
when used in <f:attribute>
and thus treated as String
. 在
<f:attribute>
使用时,类型信息在#{cc.attrs}
不可用,因此被视为String
。 The #{15}
cannot be represented as an integer in EL either, all numbers are always implicitly treated as Long
when the type information is absent. #{15}
也不能在EL中表示为整数,当缺少类型信息时,所有数字总是被隐式地视为Long
。 The ClassCastException
can be prevented by using a tag file instead of a composite component. 可以使用标记文件而不是复合组件来防止
ClassCastException
。
Your best bet is doing the check in the actual rows
attribute itself. 您最好的选择是检查实际的
rows
属性本身。
<p:dataTable ... rows="#{cc.attrs.filter ? cc.attrs.rows : null}">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.