• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple JSTL question  RSS feed

 
Bhushan Jawle
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,
I am preparing to dive into JSTL as I will be using it in my new project but have landed into a seemingly simple problem.
I have parse an XML document and could successfully loop thro. it and display the elements. However I would like to do some conditional processing based on value of elements.
The obvious solution seems to use <x:if> and compare the current value with a variable, however I am struggling with syntax.
Any help will be appreciated.
Source :
<c:import url="xml/languages.xml" var="languageList"/>
<x arse xml="${languageList}" var="parsedLanguageList"/>
<c:set var="lang" value="Japanese"/>
<c ut value="Var is ${lang}"/><br/>
<x:forEach select="$parsedLanguageList/language-list/language" var="currLanguage">
<%--<x:if select="$currLanguage/name='${lang}'">
<x ut select="name"/>
</x:if>--%>
<%-- Code above is syntactically correct but dosen't work where as writing text directly instead of ${lang} works . Another approach I tried is listed below..--%>

<x:set var="selLang" select="$currLanguage/name"/>
<c ut value="${selLang}"/><br/>
</x:forEach>Regards,
Bhushan
 
Bhushan Jawle
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for another post on same topi.
Soln. to get around this seems to be in 'A way to evaluate variables in <x:if> stmt.' in particular or parameterized conditional processing in general.
Regards,
Bhushan
 
Bhushan Jawle
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found out the soln.
This is what I used
<c:import url="xml/languages.xml" var="languageList"/>
<x arse xml="${languageList}" var="parsedLanguageList"/>
<c:set var="lang" value="${loginBean.userId}" scope="page"/>

<x:forEach select="$parsedLanguageList/language-list/language" var="currLanguage">
<x:choose>
<x:when select="$currLanguage/name = $pageScope:lang">
-><x ut select="name"/><br/>
</x:when>
<x therwise>
->Hello <br/>
</x therwise>
</x:choose>
</x:forEach>
Regards,
Bhushan
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!