Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

fmt setLocale  RSS feed

 
meetu arora
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am trying to setLocale in fmt using a variable. Here is my code:

<%
Object loc = request.getSession().getAttribute("locale");
String locStr = loc.toString();
out.println("locStr" + locStr);
%>
<fmt:setLocale value="${locStr}" />

But this is not setting the value in fmt. If i hardcode value here to fr_FR, it works.

Thanks
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is shown on the page if you add <c:out value="${locStr}" /> to the JSP?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mixing scriptlets and the JSTL/EL is a recipe for disaster. The EL and JSTL have no visibility to scripting variables. They are not designed to work together, and though you can duct-tape it together, it's never pretty.

Why do you feel the need for the Java scriptlet in the first place? The locale information is already available to the EL, why the scriptlet?
 
meetu arora
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i display value using <cut locStr, it shows empty string. In scriplet I can see the value of locStr
I just need to get value of locale from request.getSession.getAttribute and set it in <fmt:setLocale.
Please let me know how can I do the same.

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i display value using <c:out locStr, it shows empty string.

Good, that was meant to teach you what Bear said explicitly:
Bear Bibeault wrote:The EL and JSTL have no visibility to scripting variables

He also asked:
The locale information is already available to the EL, why the scriptlet?

 
meetu arora
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I am getting incorrect locale , thats why setting in session.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, session attributes are available in the EL without the need for scriptlets. If you aren't familiar with how to access page/request/session/application attributes using the EL I suggest to consult an EL tutorial like this one.
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why bother with the scriptlet code?
${sessionScope.locale} accesses the value you want using EL.
It should work with the setLocale tag unless it is an object other than a Locale or a String...

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!