preload
Okt 14

Situation:
You created a composite component in JSF 2.0. This component now should have some attributes which contains direct links. This links should now be declared when you use the component.
Example:

1
2
3
    <composite:attribute type="java.lang.String" required="false"
        name="logoutURL" default="/faces/logout.jsf"
        shortDescription="The logout URL." />

Later in the implementation you use it like the following example:

1
2
		<h:commandLink action="#{cc.attrs.helpURL}"
			value="#{textbundle['status.linktext.logout']}" />

Problem
You now get a class cast exception. JSF excepts a String result of a method which you can use in the action attribute of commandLink. Directly putting a String in this result is ok.

Solution
Use toString (although you declared the attribute as type of String)

1
2
		<h:commandLink action="#{cc.attrs.helpURL.toString}"
			value="#{textbundle['status.linktext.logout']}" />
Tagged with: