Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

fmt: tag

 
Deepak Jain
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic