0

I have the following 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>

And I am trying to read whether the type is unclickable..

The backend bean reads:

@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;
}

What am I doing wrong, or what do I need to do to show a link as unclickable? IN the front-end? Thanks

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
JoJo
  • 4,643
  • 9
  • 42
  • 65
  • If you need the link as "unclickable" (pretty odd, let me say), display it as a text, not as a link. – Luiggi Mendoza Aug 15 '12 at 16:53
  • Yes we first check the category type and display it as text if it is not meant to be a link. Otherwise we wire it up to be a link. But how can I read from the returned SET? – JoJo Aug 15 '12 at 16:55
  • `C_Type` not a `String`. What makes you think that they would ever return true on each other's `equals()`? – BalusC Aug 15 '12 at 19:35

1 Answers1

2

This statement directly won't work in EL for JSF 1.x

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

Now for the solution try a custom taglib function using below pointers...

Register taglib in web.xml

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

Define method in the taglib as:

<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>

Define java method in com.XXX.XXX.XXX.JavaClass as

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

Declare the namespace in XHTML

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

And finally call it in xhtml

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

Hope it helps!!!

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Bharat Sinha
  • 13,973
  • 6
  • 39
  • 63
  • 1
    Given the `` tags, OP is using JBoss Seam which thus also contains JBoss EL. This works just fine together with JSF 1.2. See also http://stackoverflow.com/questions/3284236/jsf-2-0-method-invocation/3284328#3284328 Your confusion is caused by assuming that invoking methods in EL is specific to JSF 2.0 somehow. This is untrue. It's specific to EL 2.2 (and JBoss EL). – BalusC Aug 15 '12 at 19:33