• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

fmt: tag

 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic