?
Solved

how to pass an EL variable used in a for loop into a scriptlet ?

Posted on 2006-05-23
9
Medium Priority
?
631 Views
Last Modified: 2013-11-24
hi,
 i am getting a problem while converting the scriplets to EL.this for loop variable i0 is not recognised
by this

<c:forEach var="i0" begin="0" end="${rows}" step=1>
             <c:set var ="i0" value ="${i0 + 1}"></c:set>
            <c:set var="_p0_0" value="<%=PolicyQuery.getINSURED_ADDRESS_LINE2(i0)%>"/> // THIS IS WHERE I AM GETTING PROBLEM - THIS "i0" is not recognised in the getter method.
      </c:forEach>

and more query , how can i convert this for loop.,
<%
      for (int _i0 = 0; ; )
{ } %>..,

anybody help me out.
0
Comment
Question by:mali_ini
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:Krule
ID: 16744071


<c:forEach var="i0" begin="0" end="${rows}" step=1>
           <c:set var ="i0" value ="${i0 + 1}"></c:set>
          <c:set var="_p0_0" value="iNSURED_ADDRESS_LINE2(i0)"/> // You should rename your function to adhere to JavaBean standards...
     </c:forEach>
0
 
LVL 3

Expert Comment

by:Krule
ID: 16744132
I lied, sorry

<c:forEach var="i0" begin="0" end="${rows}" step=1 varStatus="idx">
          <c:set var="_p0_0" value="${iNSURED_ADDRESS_LINE2[idx.index]}"/> // You should rename your function to adhere to JavaBean standards...
     </c:forEach>

Also, can you perhaps explain what the for loop is doing? Are you trying to iterate over a collection of objects? Or is it a simple for loop?
0
 
LVL 3

Accepted Solution

by:
Krule earned 672 total points
ID: 16744142
Take a look at this presentation..I think your a bit confused about how to iterate using JSTL

http://www.cs.sunysb.edu/~cse336/Slides/L17-JSTL-2.pdf
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Assisted Solution

by:rrz
rrz earned 664 total points
ID: 16745622
Does this work ?  
<c:forEach var="i0" begin="0" end="${rows}" step="1">
           <c:set var ="i0" value ="${i0 + 1}"></c:set>
          <c:set var="_p0_0" value="${PolicyQuery.INSURED_ADDRESS_LINE2(i0)}"/>
          <c:out value="${_p0_0}"/>
     </c:forEach>

You should not use method names like  getINSURED_ADDRESS_LINE2  they are not javabeans standard.
0
 
LVL 28

Expert Comment

by:rrz
ID: 16745740
0
 
LVL 4

Assisted Solution

by:evnafets
evnafets earned 664 total points
ID: 16748516
Ok, first thing, you can access EL expressions in <%= expr %> tags.  They don't share the same variable space.

It looks like this was your original expression: <%= PolicyQuery.getINSURED_ADDRESS_LINE2(i0) %>
With EL you can only call simple get/set methods.  You cannot directly call methods that take parameters.
It also looks like PolicyQuery is a classname - is this a staic method or is PolicyQuery an object somewhere?  
Again, by java programming conventions, variables should be named with lower case letters, and classes starting with capital letters so you can easily tell the difference.

Is getINSURED_ADDRESS_LINE2() is a static method of the class PolicyQuery?
Are you in a JSP2.0 container (eg Tomcat 5) ?
If so, consider writing it as a static function, defining it in a tld, then you can call your function from the expression library something like
<c:set value="address2" value="${myFunctions:getAddressLine(i0)}" />

0
 
LVL 28

Expert Comment

by:rrz
ID: 16751976
evnavets is right.
So,try it this way
<c:forEach var="i0" begin="0" end="${rows}" step=1>
           <c:set var ="i0" value ="${i0 + 1}"></c:set>
            <%
                  Long i0 = (Long)pageContext.getAttribute("i0");
            %>
           <c:set var="_p0_0" value="<%=PolicyQuery.getINSURED_ADDRESS_LINE2(i0.intValue())%>"/>
</c:forEach>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A solution for Fortify Path Manipulation.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question