• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

fmt: tag

 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Now that i have cleared SCWCD i want to apply that knowledge to my job and in this process i want to use i18N support available in the JSTL library via fmt tag.

I was able to successfully get locale specific strings via
<fmt:bundle basename="TempMgrResources">
<fmt:setLocale value="${loginBean.locale}"/>
<fmt:message key="Report.StepText" />
</fmt:bundle>

But now to access every key in the resource bundle do i have to repeat the above three lines every where. Is there no way to
a) Set the Resource bundle
b) set the locale

After doing these two just access the keys via fmt:message tag.
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer:
<fmt:setBundle basename="TempMgrResources" var="resource"/>

The above code will store the Resource bundle into the resource specified by the var attribute of setBundle tag, scoped variable which can be used in the rest of the JSP's as follows


<fmt:message key="Report.StepText" bundle="${resource}"/>

Looks cool .
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing that i did not understand was how did the locale got set automatically???
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Locale does get set automatically to browser locale using ServletRequest.getLocales() which can be overridden by <fmt:setLocale/>.

This thread can now be closed
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic