struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig McClanahan <craig...@apache.org>
Subject Re: [struts-faces] iterating managed bean properties
Date Sat, 26 Nov 2005 06:07:21 GMT
On 11/25/05, Laurie Harper <laurie@holoweb.net> wrote:
>
> Craig McClanahan wrote:
> > There are some significant interoperability issues between JSF 1.0/1.1
> and
> > JSTL -- some of which have been addressed in JSF 1.2.  But there is a
> more
> > fundamental design issue here ... you're trying too hard :-).  Consider
> this
> > instead:
> >
> >      <h:selectOneMenu id="status" value="#{ProjectEdit.status}">
> >          <f:selectItems value="#{projects.statusList}"/>
> >      </h:selectOneMenu>
> >
> > where the getStatusList() method of your "projects" managed bean returns
> an
> > array or list of SelectItem instances.  There's no reason for you to
> have to
> > do the iteration in the view tier.
>
> LOL! I'm actually using exactly that pattern elsewhere.


:-)

The reason I
> didn't here is that the label needs to be localized:
>
>    <f:loadBundle basename="MessageResources" var="msgs"/>
>    ...
>      <h:selectItem value="..." itemLabel="#{msgs['stat.lbl.'s.name]}"/>
>
> in other words, if s.name is ACTIVE, the label should be the resource
> string keyed by 'stat.lbl.ACTIVE'. I didn't think I could get at the
> localization resources loaded in the current view from within an
> application-scoped bean's getter method (though I might be wrong about
> that!).


In my localized apps, I bury that sort of thing inside the getter method for
the SelectItems list.  You can figure out what Locale you need to localize
for, for the current request, by calling:

    FacesContext.getCurrentInstance().getViewRoot().getLocale()

with per-Locale caching to prevent needless regeneration of an appropriate
list or array.  Saves a lot of time having to explain what <c:forEach> does
to a graphic designer.

L.


Craig

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message