You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by bOOyah <bo...@nowhere.org> on 2004/04/07 04:39:32 UTC

Best practice: when to convert message resources to actual strings?

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?

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

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

(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.

------------------------------------------------------------
FORM BEAN:
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)i.next();
         MenuItem m2 = new MenuItem();
         m2.setId( m1.getId() );
         m2.setValue( resources.getString( m1.getValue() ) );
         this.menu.add(m2);
     }
}

public List getMenuItems() {
     return this.menu;
}

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

------------------------------------------------------------
ACTION CLASS:
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.

------------------------------------------------------------
EJBs:
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?
-- 
bOOyah


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org