webtier@glassfish.java.net

JSF 2.0 : Inconsisted use of composite attributes in component fields

From: <webtier_at_javadesktop.org>
Date: Wed, 24 Feb 2010 22:23:07 PST

Okay, here's a bit of a puzzle. I thought it was a bug at first, but now I'm wondering if it's a quirk of the spec. Here's the code:

[i]<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:composite="http://java.sun.com/jsf/composite">

  <!-- INTERFACE -->
  <composite:interface name="inputText">
    <composite:attribute name="id" />
    <composite:attribute name="label" />
    <composite:attribute name="value" />
    <composite:attribute name="required" />
  </composite:interface>

  <!-- IMPLEMENTATION -->
  <composite:implementation>
    <h:outputLabel for="[b]#{cc.attrs.id}"[/b] value="#{cc.attrs.label}" />
    <h:inputText id="[b]#{cc.attrs.id}[/b]" required="#{cc.attrs.required}" value="#{cc.attrs.value}"/>
    <h:message for="[b]#{cc.attrs.id}[/b]" errorClass="errorMessage"/>
  </composite:implementation>

</html>[/i]

Nothing fancy, just a simple composite component to be used in a form.

The puzzling bit is that I get different results for what gets substituted for the three instances of [b]#{cc.attrs.id}[/b] in the implementation.

If cc.attrs.id = "name", I get id="name:name" in the inputText component, but I get for="name" for both the outputLabel and message components, even though I am using exactly the same EL for all three.

Here's the generated HTML:

[i]<label for="[b]name[/b]">
User Name or Email Address</label><input id="[b]name:name[/b]" type="text" name="name:name" />[/i]

and here's the Component Tree:

[i] <HtmlOutputLabel escape="true" for="" id="j_idt11" inView="true" rendered="true" transient="false"/>
<HtmlInputText disabled="false" id="name" immediate="false" inView="true" localValueSet="false" maxlength="-2147483648" readonly="false" rendered="true" required="false" size="-2147483648" transient="false" valid="true"/>
<HtmlMessage errorClass="errorMessage" for="" id="j_idt12" inView="true" redisplay="true" rendered="true" showDetail="true" showSummary="false" tooltip="false" transient="false"/>[/i]

(Here the two [b]for[/b] fields are blank, and the[b] id[/b] field is the one with the corrrect value of "name". Somehow a copy of "name" is added to all the fields in the final HTML rendering.)

I see in the JavaDoc that inputText [b]id[/b] is defined as just a String, whereas the [b]for[/b] attribute in the other two elements is a full-blown javax.el.ValueExpression that must result in a string. Is that the reason for the different result?

If so, what do I need to do to get the same value in all three fields -- which is obviously what I need in this particular case? I feel I must be missing something.

Cheers,

Mike
[Message sent by forum member 'tacitust' (tacitus_at_yahoo.com)]

http://forums.java.net/jive/thread.jspa?messageID=388563