Skip to main content

[webtier] composite attributes and default values for objects

1 reply [Last post]
Anonymous

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.

beanMsgs is #{cc.attrs.beanMsgs == null ? 'null' :
cc.attrs.beanMsgs}

libMsgs is #{libMsgs == null ? 'null' : libMsgs}
libMsgs.labelUserName is #{libMsgs.labelUserName}

beanMsgs.labelUserName is #{cc.attrs.beanMsgs.labelUserName}

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@10af7ce
libMsgs is java.util.PropertyResourceBundle@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
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joel Weight

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/ind...
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 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.
>
>
>
>
> > name="beanMsgs"
> required="false"
> default="#{libMsgs}"
> shortDescription="Message bundle to use for the messages in
> this component." >
>
>

>
>
> beanMsgs is #{cc.attrs.beanMsgs == null ? 'null' :
> cc.attrs.beanMsgs}
>

> libMsgs is #{libMsgs == null ? 'null' : libMsgs}

> libMsgs.labelUserName is #{libMsgs.labelUserName}

>
> beanMsgs.labelUserName is #{cc.attrs.beanMsgs.labelUserName}
>

>

>

>
>
> 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@10af7ce
> libMsgs is java.util.PropertyResourceBundle@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
>
[att1.html]