Page 1 of 1

About Question com.enthuware.ets.scwcd.v5.2.56 :

Posted: Tue Jun 11, 2013 7:53 pm
by marcelomnc
The system marks this answer as correct:
The EL code within the body of the tag may refer to the iteration variable but scripting code cannot.
With the following note:
For example, <%=dept.getName()%> is invalid here:

<c:forEach var="dept" items="${departments}">
<c:out value="${dept.name}"/><br><%=dept.getName()%>
</c:forEach>
But I guess its WRONG, because the scripting code can access the iteration variables as follows:

Code: Select all

<c:forEach var="str" items="${arr}" varStatus="status">
	<c:out value="${str}"/><br>
	<c:out value="${status.count}"/><br>
        Now with scriptlet:<br>
	<%=pageContext.getAttribute("status")%><br>
	<%=((String)pageContext.getAttribute("str")).toUpperCase()%><br>
</c:forEach>
I have tested this code and obtained correct output as well. So i guess this can be misleading.

Am I right with this?

Re: About Question com.enthuware.ets.scwcd.v5.2.56 :

Posted: Wed Jun 12, 2013 8:07 am
by ArsenyKo
In that way you are accessing "context attributes" but not "variables". That was my train of thoughts when I met the question.

Re: About Question com.enthuware.ets.scwcd.v5.2.56 :

Posted: Fri Jun 14, 2013 6:51 am
by admin
You are not really accessing the scripting variable. You are accessing the object that stored in the context under the same name.

HTH,
Paul.