EL language question

N

Nicolas Laplante

Hi all,

I didn't find a suitable JSP newsgroup so I post my question here:

I have a tag that has an attribute "level" which is a numeric type
(integer).

I want to know if it's possible to use EL language to create the
equivalent of this:


Code:
String str = "";

for (int i = 0; i < level; i++) {
	str += "../";
}

The methods in JSTL's core library (c) cannot do the trick as far as I
know, nor do the functionalities offered by the functions library (f).

Do I need to do it in a scriplet? If so, how can I access the "levels"
variable (which is an attribute of the custom tag) from the Java scriplet?

If you need any additional info, just ask! :)

Thank you,

Nicolas Laplante
 
M

Manish Pandit

Is this in line with what you need?

Make sure you do an isELIgnored="false" in your JSP on the @page
declaration.

<c:forEach var="i" begin="1" end="10">

<c:set var="str" value="${str}../"/>

</c:forEach>

The result is : ${str}

-cheers,
Manish
 
M

Manish Pandit

Oh - just to add the level variable you mentioned - you can access it
by doing a ${level}, which will change the loop to:

<c:forEach var="i" begin="0" end="${level}">

<c:set var="str" value="${str}../"/>

</c:forEach>

The result is : ${str}

Assuming level is a variable available in the page/request/session
scope. If you want you can even qualify the scope by
${requestScope.level} or ${sessionScope.level} or ${pageContext.level}
based on where it is.

-cheers,
Manish
 
N

Nicolas Laplante

Manish said:
Oh - just to add the level variable you mentioned - you can access it
by doing a ${level}, which will change the loop to:

<c:forEach var="i" begin="0" end="${level}">

<c:set var="str" value="${str}../"/>

</c:forEach>

The result is : ${str}

Assuming level is a variable available in the page/request/session
scope. If you want you can even qualify the scope by
${requestScope.level} or ${sessionScope.level} or ${pageContext.level}
based on where it is.

-cheers,
Manish

Thank you very much for your help! I must have misread the JSTL
documentation then :)

Nicolas Laplante
 
M

Mark Space

Nicolas said:
Thank you very much for your help! I must have misread the JSTL
documentation then :)

Nicolas Laplante

Not that I really think anyone here minds EL questions, but there is a
Tomcat mailing list. Check the tomcat.apache.org page, there's a link
to it somewhere on there. They can probably help you faster and better
than most people here can.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top