Craig McClanahan wrote:
On 1/26/06, Richard Wallace <[EMAIL PROTECTED]> wrote:
Ok. I understand that's how you use it in the html files. But what
about in the clay-config.xml file? For instance, in the use-cases
clay-symbols-config.xml file there is a component definition like this:
<component jsfid="firstNameLabel" extends="baseLabel">
<attributes>
<set name="value" value="First Name:" />
<set name="for" value="firstName" />
</attributes>
</component>
What I'm wondering is, rather than using "First Name:" as the value, how
would I load it from a resource bundle? And does it just use the
default locale or the locale the user sets for the session?
You can have your cake and eat it too :-), by combining two things:
* The LoadBundle utility class that Gary mentioned, configured as
a managed bean, and
* The fact that you can use EL expressions for the value initializer.
Let's do a concrete example. Assume I have a resource bundle named
com.mycompany.resources.Bundle that I want to pull localized strings from.
First, let's declare a managed bean in application scope (since the messages
are shared):
<managed-bean>
<managed-bean-name>messages</managed-bean-name>
<managed-bean-class>org.apache.shale.util.LoadBundle
</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
<managed-property>
<property-name>basename</property-name>
<value>com.mycompany.resources.Bundle</value>
</managed-property>
</managed-bean>
Now, modify your component definition from above slightly:
<component jsfid="firstNameLabel" extends="baseLabel">
<attributes>
<set name="value" value="#{messages.map['
first.name.prompt']}" />
<set name="for" value="firstName" />
</attributes>
</component>
This works because the following events occur:
* The reference to "messages" will cause the managed bean to be
created if its not there already
* The LoadBundle has a getMap() method that looks at FacesContext
and figures out which Locale you're using, then creates a Map
with the resource bundle contents for that locale
* The EL evaluation then looks up message key "first.name.prompt"
from this resource bundle, and returns the corresponding value.
Craig
That's great. Then you would never need to use the <span
jsfid="loadBundle" /> component. Thanks for the explanation.
Rich
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]