在“h:outputlink”JSF的render属性中使用“contains”语句

时间:2014-02-03 13:16:04

标签: jsf rendered-attribute

简单地说,我的back-bean中有一个数组包括一些值,如'1' - '2' - '3' - '4' - '5' 在JSF中,我想在h:outputlink中使用render属性,根据每行中的某些值,在数据表行上显示可见或不可见的链接 例如,我可以在每一行中都有唯一的id,如rowvar.accountType.entity.id,它返回一个唯一的id,然后我想检查我在后面bean中填充它的数组是否包含这个id,然后渲染的值应该为true并且行应该是可见的。像这样 <h:outputLink rendered="#{Arrays.asList(acceptedIds).contains(rowvar.accountType.entity.id) }"

但当然不正确!

你能帮我解决一下吗?

3 个答案:

答案 0 :(得分:1)

我通过使用这些声明解决了我的问题

<c:set var="theString" value="#{MyBean.payByShetabAccount}"/>
<c:set var="theString2" value="#{rowvar.accountType.entity.name}" />

<h:outputLink styleClass="fancybox-iframe  tipsy" 
        rendered="#{fn:contains(theString, theString2) || theString == '*'}"                                        
        title="#{AccountBeanbeanMessages['property_settleToAccount_caption']}"
        value="hello.jsf">
        <h:graphicImage url="img/small-icons/list-operations/left.png" styleClass="standardTable_Icon"></h:graphicImage>
        </h:outputLink>

答案 1 :(得分:0)

你说得对,它不会这样。

一种选择是重构代码,使其使用Collection / List,它提供contains()方法而不是使用数组。通过这种方式,它使整个故事变得更加容易。

另一种解决方案是在bean上实现一个方法,该方法接受一个数组作为参数,并返回数组值的Collection实例。

您还可以实现自定义EL功能。看看this answer,了解如何做到这一点。

答案 2 :(得分:0)

我会创建一个接受数组和id并返回布尔值的方法。然后EL表达式看起来像“#{existsInArray(array,id)}”