我有以下xhtml:

<s:fragment
    rendered="#{selectCat.categoryTypes.contains('unclickable')}">
    <h:outputText value="DONT CLICK #{selectCat.webName}" />
</s:fragment>

<s:fragment rendered="#{selectCat.categoryTypes eq null}">
    <a href="/category/#{_category.fullName}"> #{selectCat.webName}</a>
</s:fragment>


我正在尝试读取该类型是否不可点击。

后端bean读取:

@ManyToMany(fetch = FetchType.LAZY, targetEntity = C_Type.class)
@JoinTable(name = "Category_Type", joinColumns = @JoinColumn(name = "CategoryId"), inverseJoinColumns = @JoinColumn(name = "TypeId"))
@XmlTransient
public Set<C_Type> getCategoryTypes() {
    for (C_Type cc : categoryTypes) {
        System.out.println("=============="+cc.getC_type()+"==============");
    }

    return categoryTypes;
}


我在做什么错,或者该怎么做才能将链接显示为不可点击?在前端?谢谢

最佳答案

对于EL,此语句直接在JSF 1.x中不起作用

#{selectCat.categoryTypes.contains('unclickable')}


现在为解决方案尝试使用下面的指针自定义taglib函数...

web.xml中注册taglib

<context-param>
    <param-name>facelets.LIBRARIES</param-name>
    <param-value>
        PATH_TO_CUSTOM_TAGLIB;/WEB-INF/tomahawk.taglib.xml;
    </param-value>
</context-param>


将taglib中的方法定义为:

<facelet-taglib>
<namespace>
 http://www.client.com/product
</namespace>
...
<function>
    <function-name>contains</function-name>
    <function-class>com.XXX.XXX.XXX.JavaClass</function-class>
    <function-signature>java.lang.Boolean contains(java.util.Set, java.lang.String)</function-signature>
</function>
 ...
</facelet-taglib>


com.XXX.XXX.XXX.JavaClass中将java方法定义为

public static Boolean contains(Set setOfObjects, String value){
    //... Assuming you are checking where value, a string, is available in Set or not
}


在XHTML中声明名称空间

xmlns:g="http://www.client.com/product"


最后在xhtml中调用它

<s:fragment
    rendered="#{g:contains(selectCat.categoryTypes,'unclickable')}">


希望能帮助到你!!!

10-07 16:13
查看更多