struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bOOyah <>
Subject Best practice: when to convert message resources to actual strings?
Date Wed, 07 Apr 2004 02:39:32 GMT
Hi again

Like a good little girl, I have located all my app's GUI strings in a 
message resource bundle for I18N purposes.  This includes the strings 
that appear in drop-down select fields that I use as options menus. 
There are several of these menus in my pages and their contents are, for 
all intents and purposes, NOT dynamic.

So now I have to convert all the message resources in those menus to 
their i18n string equivalents at run time (essentially rewriting the 
menus' texts).  But where should I do it, and when?

In the JSP?  The Form Bean?  The Action?  Or, *gasp* the EJB?

The purist might do it here.  Maybe something like this:

   <html:select property="selectedMenuItemId" >
           label="<fmt:message key="value" />" />

(Actually I don't think that's going to work as I've written it...)
But the menu would be rewritten every hit of the page.  Viva Hotspot.

In the 'menuItems' setter/getter:

public setMenuItems(List menuItems) {

     // convert vanilla menu to i18n-specific

     Iterator i = menuItems.iterator();
     while (i.hasNext()) {
         MenuItem m1 = (MenuItem);
         MenuItem m2 = new MenuItem();
         m2.setId( m1.getId() );
         m2.setValue( resources.getString( m1.getValue() ) );;

public List getMenuItems() {

The menu is localized the first time the form bean is used.

Same kind of Java as the form bean.  The Action would suck the pre-i18n 
menus from the DTOs as they are retrieved and convert them on-the-fly 
before depositing them in the form bean just prior to forwarding to the 
pages.  But this seems like the wrong place.  I really want my Actions 
to merely manage DTO hand-off between my EJBs and my form beans.

Well, the pre-i18n menus are stored in the DB anyway.  My EJBs could hit 
the DB at start-up, convert the menus to i18n-specific and cache them 
for the lifetime of the app.  The DTOs would always have ready-rolled 
strings then.  But again, this feels wrong; surely GUI strings are a 
presentation tier issue?

Any thoughts?

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message