JSF 2.2: Empty composite component attributes

In my post about empty attributes in composite components I discussed problems with composite component attributes whose value is null. So, in my fifth post of the series on JSF 2.2 features I will show that the JSF 2.2 specification (see [1]) solves this issue (see [2]).

Let’s first have a look at a very simple composite component:

  <cc:attribute name="value"/>
  <cc:editableValueHolder name="input"/>
  <h:inputText id="input" value="#{cc.attrs.value}"/>

As you can see there is nothing fancy. Just an attribute with the name value that is used in a h:inputText component in the implementation part. The next listing shows a usage scenario for this component:

<jl:inputTest value="#{testController.longValue}">
  <f:validator for="input"

Looks correct so far, and with JSF 2.2 this works like a charm. But with older versions of MyFaces and Mojarra this example does not work when users of the component pass a value expression to the attribute that resolves to null. A more detailed description can be found in the original post.

The source code for the JSF 2.2 series examples can be found in the JSFlive Github repository jsf22-examples (module jsf22-cc-empty-attribute).

[1]: JSR 344: JavaServer Faces 2.2


2 responses to “JSF 2.2: Empty composite component attributes

  1. Pingback: Composite component pitfalls: Empty attributes | JSFlive: Michael Kurz's JSF Weblog

  2. Pingback: JSF 2.2 - Empty composite component attributes - Blog - Irian

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s