webtier@glassfish.java.net

Re: [webtier] composite attributes and default values for objects

From: Joel Weight <digitaljoel_at_gmail.com>
Date: Mon, 15 Mar 2010 17:48:29 -0600

Ok, immediately after hitting send I figured I should look at the javadoc.
 According to
http://java.sun.com/javaee/javaserverfaces/2.0/docs/pdldocs/facelets/index.html
the
'default' attribute, if specified, must evaluate to java.lang.String. I
would be interested to know why it is required to evaluate to a String
instead of an object, or, better yet, the type specified in the 'type'
attribute.

In the meantime, sorry for the extra traffic.
Joel

On Mon, Mar 15, 2010 at 5:44 PM, Joel Weight <digitaljoel_at_gmail.com> wrote:

> Hello.
>
> I'm trying to pass an object as a value of a custom attribute in a
> composite component. Specifically, I'm trying to pass a message bundle, and
> if one is not passed, then I want to use the default. I have my composite
> component setup as follows.
>
>
> <h:body>
> <composite:interface>
> <composite:attribute
> name="beanMsgs"
> required="false"
> default="#{libMsgs}"
> shortDescription="Message bundle to use for the messages in
> this component." >
> </composite:attribute>
> </composite:interface>
>
> <composite:implementation>
> beanMsgs is #{cc.attrs.beanMsgs == null ? 'null' :
> cc.attrs.beanMsgs}
> <br/>
> libMsgs is #{libMsgs == null ? 'null' : libMsgs}<br/>
> libMsgs.labelUserName is #{libMsgs.labelUserName}<br/>
> <ui:remove>
> beanMsgs.labelUserName is #{cc.attrs.beanMsgs.labelUserName}
> </ui:remove>
> </composite:implementation>
> </h:body>
>
>
> and the using page simply includes the component with no additional
> attributes.
>
> You'll notice that the attribute is named beanMsgs. I default to libMsgs,
> which is a resource-bundle setup in faces-config.
>
> When I hit the including page, I get the following output
>
> beanMsgs is java.util.PropertyResourceBundle_at_10af7ce
> libMsgs is java.util.PropertyResourceBundle_at_10af7ce
> libMsgs.labelUserName is Username
>
> If I uncomment the reference to cc.attrs.beanMsgs.labelUserName, I get an
> exception that states:
> The class 'java.lang.String' does not have the property 'labelUserName'.
>
> In the previous run, I established that both objects reference the same
> PropertyResourceBundle, and that the property is valid with a value of
> 'Username'
>
> If the calling page specifies a message bundle in the beanMsgs attribute
> when using the component, then I get the correct output, so the problem
> appears to be with the default value for some reason.
>
> I would greatly appreciate any help or pointers you can give.
>
> Thanks,
> Joel
>