views:

724

answers:

3

The following bit of code sets the Locale from lang param on querystring.

<c:if test="${param['lang'] != null}">
    <fmt:setLocale value="${param['lang']}" scope="session"/>
</c:if>

How do I now read that variable?

I know its a bit noobish.

I need a bit of conditional logic to display one language link if the local hasn't been set in the session scope using the fmt:setLocale, and another if it has been set to a specific locale.

Thanks

A: 

Try this:

<c:if test="${pageContext.request.locale.language == 'en'}"> 
    <a href="link1">Link 1</a> 
</c:if> 
<c:if test="${pageContext.request.locale.language != 'en'}"> 
    <a href="link2">Link 2</a> 
</c:if>
Chris Thornhill
thanks - but is not working in my case. a bit more info on what im doing is on next answer.
raq
A: 
<c:choose>
    <c:when test="${pageContext.response.locale eq 'en_CY'}">
     <a href="?lang=en_GB">English</a>
    </c:when>
    <c:otherwise>
     <a href="?lang=en_CY">Cymraeg</a>
    </c:otherwise>
</c:choose>

this works only on the page itslef.

but because its reading from the pageContext, it will not work on other pages by reading it from the sessionScope (where it is being set by the fmt:setLocale).

How would i read it from the sessionScope?

raq
+1  A: 
<c:choose>
    <c:when test="${sessionScope['javax.servlet.jsp.jstl.fmt.locale.session'] eq 'en_CY'}">
     a href="?lang=en_GB">English</a>
    </c:when>
    <c:otherwise>
     <a href="?lang=en_CY">Cymraeg</a>
    </c:otherwise>
</c:choose>

this works but is there a better way to write?

<c:when test="${sessionScope['javax.servlet.jsp.jstl.fmt.locale.session'] eq 'en_CY'}">
raq