Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL(EL) Problem

 
Kumar Anupam
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am converting scriptlets to JSTL Expressions. As i am new to it I am, having some problem. Such as.


Hope soon I will get a response.

Thanks in advance.
Kumar Anupam
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to change your approach slightly.

Scriptlets and JSTL/EL do not share a one to one relationship.
JSTL and EL were not intended to be a full programming language.
They were intended to fill in the gaps for view code in an architecture were most of the real programming is done in servlets and javabeans.
In other words, some of the things you're trying to do really shouldn't be done in JSP.

Our esteemed moderator Bear Bibeault has written two very good articles that should answer your questions.
http://www.javaranch.com/journal/200510/Journal200510.jsp#a1
http://www.javaranch.com/journal/200508/Journal200508.jsp#a1
 
Stefan Evans
Bartender
Posts: 1715
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Ben said is perfectly true.
However a couple of the things you ARE trying to do are very relevant to JSTL


1) <%=HTMLUtils.escapeHtml(formDetailVB.getMode())%>
The cut tag escapes HTML by default.
If formDetailVB is an attribute in scope somewhere:
<cut value="${formDetailVB.mode}/>

2) <% String appAction = formDetailVB.getFormType();%>
Not translatable. And not necessary.
JSTL does not interact with java variables.
The JSTL variable space is the attribute scopes: page, request, session, application.
The closest equivalent would be the <c:set> tag to set a JSTL variable:
<c:set var="appAction" value="${formDetailVB.formType}"/>

The java code equivalent to that (just so you see where it goes to):
pageContext.setAttribute("appAction", formDetailVB.getFormType();

3) if (appAction.equals(FormConstants.VALUE_FORM_TYPE_OPEN))
<c:if test="${formDetailVB.formType == FormConstants.VALUE_FORM_TYPE_OPEN}>
<c:set var="DISABLE_NAVIGATION" value="FALSE"/>
</c:if>

See Bear's second article on how to access constants with JSTL.

Cheers,
evnafets
[ November 15, 2005: Message edited by: Stefan Evans ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic