webtier@glassfish.java.net

[webtier] composite attributes and default values for objects

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

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