Gary VanMatre wrote:
From: Richard Wallace <[EMAIL PROTECTED]>
Hello again,
Sorry if I'm getting to be a pest, but I really like Clay and want to
understand it better. So, here are my questions of the day:
Can you (or how do you) use resource bundles in the clay config files?
I'm trying to get to a place where I can use the symbol replacement
features of Clay like in the use-cases, specifically the templating.
So, I'd have a component similar to the basePage component with a
layout. Then in the layout I'd use @title for the page title. But how
can I use a resource bundle to specify the title? Additionally, if I
define label components in the clay config files, how would I use values
from resource bundles for them? And, if I use resource bundles in the
clay configs, is that just going to use the default or system locale, or
will it use the users session locale?
There are a couple ways you can handle this in clay. The resource
bundle is a JSP tag in JSF which didn't work in Clay. Manfred
Kluge contributed a resource bundle component that solves this
problem.
Shale core also has a managed bean that behaves
like a JSF map wrappered resource bundle. It's in the utils package
(LoadBundle). Craig wrote this one so the java doc is pretty
good. The cool thing about the managed bean solution is
that you can specify a scope.
So, if you used the bundle component you might consider:
<span jsfid="loadBundle" basename="org.apache.shale.usecases.view.Bundle"
var="messages"/>
<title>#{messages['@title']}</title>
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?
I just looked more at the examples, and it looks like if you just use
the loadBundle component on a page, like say you're layout page, then
when the JSF tree is built and the clay configs are used it will use
what you defined on the page. So I think I get it now. I just didn't
think that if I used the <span jsfid="loadBundle" /> thing it would be
used on the components constructed from the clay config files. Thanks.
I was trying to get my headers and footers put together yesterday and
ran into a problem doing images. My first impulse was to use an
tag with a jsfid="graphicImage" attribute.
I think that I gave the graphic image clay component XML definition
a jsfid of "image".
Ah, ok. That's what I got wrong. Thanks.
But that didn't work as
expected. Since this is a header that will be used in files that could
be in any directory I can't really use relative paths because there is
no way to know what the current working directory is so I need to
specify the full path. Would the best way to do this be something like
and define @images to be
"#{facesContext.externalContext.request.contextPath}/images"
in the clay-config.xml? Similarly, what's the best way to include
stylesheets? Before I discovered the power of symbols I used > rel="stylesheet" type="text/css"
href="#{facesContext.externalContext.request.contextPath}/styles/default.css"
/>, which is
a bit of a mess. So, would it be better to define a @styles symbol?
This is a good chance to talk about a new shale remoting feature that
allows you to access static resources like images and style sheets from
the class path. I created a couple components in the rolodex usecase
that pull images from the class path to demonstrate. I really like this idea
because you can create a component library that is self contained and
self registering. Just drop it into the project and it contains all the
resources.
The "static" folder is the default convention and the rest is the class path.
headerSorter.ascImage=/static/org/apache/shale/usecases/rolodex/up.gif.faces
headerSorter.descImage=/static/org/apache/shale/usecases/rolodex/down.gif.faces
That's a little beyond what I was asking (and a bit over my head ;).
I'm really just wondering what the best way to get the right contextPath
is for a deployed application rather than using
facesContext.externalContext.request.contextPath. I think the @images
and @styles symbols will work out nicely.
In the use-cases, dataTables are built strictly using components in the
clay config files. Is this the only way to construct them? I was
almost hoping for something more like:
The extreme HTML rolodex example shows how this can be done:
<table jsfid="dataTable" class="contacts" value="[EMAIL PROTECTED]" var="e" rows="5" first="0"
headerClass="contactsHeader" rowClasses="contactsRow1, contactsRow2" allowBody="true">
<caption jsfid="webPager" prevPageStyleClass="linkPrev"
pageLinksStyleClass="links" nextPageStyleClass="linkNext"
captionStyleClass="caption" facetName="header" allowBody="false">
Mock Page Links
</caption>
<tbody id="name" jsfid="column" class="contactsHeader"
allowBody="true">
<th jsfid="headerSorter" facetName="header" allowBody="false"
value="#{messages['rolodex.contactTable.nameColumn.title']}" sortBy="name">
Contacts
</th>
<tr jsfid="webPager" prevPageStyleClass="linkPrev"
pageLinksStyleClass="links" nextPageStyleClass="linkNext"
captionStyleClass="caption" facetName="header"/>
<tr jsfid="commandLink" value="#{e.name}" action="[EMAIL PROTECTED]"
immediate="true" allowBody="true">
<td jsfid="param" name="selectedName" value="#{e.encodedName}"
allowBody="false">
<a href="#">ABC Company</a>
</td>
</tr>
</tbody>
</table>
Oh wow. I didn't notice that one. I wasn't sure exactly what Extreme
HTML meant (it kinda scared me). I'll take a deeper look at it, thanks.
or something similar. Is that possible?
Depending on how clean you want your HTML, you can add the JSF component
specific properties in an XML file or in the HTML. The example is also defined
using a more conservative HTML pure approache:
HTML template:
<span jsfid="contactTable">
<table class="contacts">
<tr class="contactsHeader">
<td>
Contacts
</td>
</tr>
<tr class="contactsRow1">
<td>
<a href="#">ABC Company</a>
</td>
</tr>
<tr class="contactsRow2">
<td>
<a href="#">XYZ Company</a>
</td>
</tr>
</table>
</span>
XML Config:
<component jsfid="nameColumn" extends="column" id="name">
<element renderId="1" jsfid="headerSorter" facetName="header">
<attributes>
<set name="value"
value="#{messages['rolodex.contactTable.nameColumn.title']}" />
<set name="sortBy" value="name"/>
</attributes>
</element>
<element renderId="2" jsfid="commandLink">
<attributes>
<set name="value" value="#{e.name}" />
<set name="action" value="[EMAIL PROTECTED]" />
<set name="immediate" value="true"/>
</attributes>
<element renderId="1" jsfid="param">
<attributes>
<set name="name" value="selectedName"/>
<set name="value" value="#{e.encodedName}"/>
</attributes>
</element>
</element>
</component>
For my money, the second example is a lot cleaner. I'll probably use
that. Thanks again.
One last question while I'm on the subject. One thing that I'd like to
be able to do with dataTables is have a single value be used to create
more than one row. So, for instance, we might have a list of bugs. For
each bug we may want 2 rows, the first being the short description, who
submitted it and when and then the second row being a more detailed
comment. The second row could be shown/hidden by the user with DHTML so
they could get a better idea of what is the issue is. I did this with
the myfaces dataList component in JSP for a report once, manually
building the table elements with a bunch of verbatims and such. Would I
have to do the same with Clay (minus the verbatims, of course)? How
would I do that? If I tried to do it in the clay-config.xml I would
need to do something like:
You can use myfaces components in Clay. Others might be
able to share their experiences. Another option might be the
Clay for each component. The bodyJsfid holds the
template you want included for each row in the list.
It might look something like this:
<table jsfid="clayForEach" var="e" value="mybean.bugs"
bodyJsfid="classpath*:org/acme/bugslist.html" allowBody="false">
<tr><td>Mock row
</table>
buglist.html
<tr><td>#{e.bugName}</td><td>#{e.comment}</td></tr>
That would work. It's also a lot cleaner.
Thanks for all the help Gary, I really appreciate it,
Rich
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]