1

I am trying to use links in a composite component, my links are in a simple array and do not belong to any managed bean.

<composite:interface>        
    <composite:attribute name="links" required="true" />                
</composite:interface>

<composite:implementation>        
        <ui:param name="linksSplit" value="#{fn:split(cc.attrs.links, ',')}" />
        <ui:repeat var="link" value="#{linksSplit}" >                
            <h:commandLink value="#{option}" action="#{link}" />
        </ui:repeat>        
</composite:implementation>

I am getting the following error : Identity '#{link}' does not reference a MethodExpression instance, returned type: java.lang.String

We are supposed to use String or bean methods in EL expression but I don't understand why we cannot evaluate a parameter which is a String (link in my case).

If I put a real String referenced in my faces-config, it works

<h:commandLink value="#{option}" action="#navigate" />

If you have an explanation or a workaround to get my link working, it would be great

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
TonyDav
  • 25
  • 4

1 Answers1

2

When specifying an EL expression in <h:commandLink action>, it's interpreted as a method expression returning a String (or void if you don't want to navigate). See also the tag documentation:

Name action

Type javax.el.MethodExpression (signature must match java.lang.Object action())

Description MethodExpression representing the application action to invoke when this component is activated by the user. The expression must evaluate to a public method that takes no parameters, and returns an Object (the toString() of which is called to derive the logical outcome) which is passed to the NavigationHandler for this application.

Given the fact that you seem to want pure page-to-page navigation links, you're actually going in the wrong direction as to using <h:commandLink> for that. You should instead be using <h:link> for that. It generates SEO-friendly and bookmarkable GET links instead of a piece of JavaScript which submits a parent POST form.

<ui:repeat var="link" value="#{linksSplit}" >                
    <h:link value="#{option}" outcome="#{link}" />
</ui:repeat>        

See also:

Note that this all has nothing to do with composite components. You'd have had exactly the same problem when using this in a normal page.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555