cancel
Showing results for 
Search instead for 
Did you mean: 

bean scope for localization labels

Former Member
0 Kudos
62

Hi,

which scope is the best for labels, which have to be localizable and shown in jsp? (I dont know if it is better to put it in session bean or every request fetch it from localization bundles...)

thanks

JJ

Accepted Solutions (1)

Accepted Solutions (1)

detlev_beutner
Active Contributor
0 Kudos

Hi JJ,

definitely, fetching labels or any internationalization texts each time they are used directly from the bundle is quite inefficient. I just tried to analyze if the resource bundles are buffered in some way within the portal framework implementation, but it wasn't a one-liner.

Anyhow, even if buffering is done, you would always at least have to check the locale. That's not much, but it is enough to do it once per PortalComponentSession. So this is just a nice place for the bean containing i8n-texts.

Hope it helps

Detlev

PS: It's an additional design question if you just store the bundle or each label/text individually. The latter is definitely more coding (mainly getters in the bean) but for that an easier access within the JSP, for example.

Former Member
0 Kudos

i have an idea, but i don't know if it bad or not.

What about making one singleton class(for each language one instance) with localization texts. And in the session bean have only reference to concrete instance, is it possible? (i don't want to spent time in case if sb know that it is impossible:, is it possible in jsp write st like <?=bean.getLocalSingleton.getLabelName()?> or it is not allowed to call more than one fction?)

thanks

JJ

detlev_beutner
Active Contributor
0 Kudos

Hi JJ,

this would be quite OK. You could implement this via a pseudo Singleton, where each instance is referenced by it's local within a HashMap.

<%=bean.getLocalSingleton().getLabelName()%> is OK too.

The question is if it's worth all the extra coding. Realize that implementing it the way you suggested means many extra calls within the JSP, not very nice to care about. If you want to do it, better call bean.getLabelName(), and get back the right Label by your Singleton via the bean implementation of getLabelName().

Hope it helps

Detlev

PS: Please consider awarding points for nice people helping you

Answers (0)