Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

Problem with EL (Expression Language) in JST /JSP

Thread view: 
jgmaux@telefonica.net - 29 Dec 2006 21:34 GMT
Hi,

I have a problem with JSTL EL (Expression Language) in JSP.

The follow example show my problem.:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<%
  java.util.HashMap clients = new java.util.HashMap();
  clients.put("1","John");
  clients.put("2","Peter");
  clients.put("3","Gerald");
  clients.put("4","Nick");
  request.setAttribute("clients",clients);
%>
<c:forEach var='clientnum' begin='1' end='4'>
   <br>
       Client Nº::${clientnum}
   </br>
   <br>
       Value:${requestScope.clients["${clientnum}"]}
   </br>
</c:forEach>
</body>
</html>

My code don't display the "clients" values...
¿Where is the problem?
I don't want to use iteration, please....
Thanks in advance.
Steve - 29 Dec 2006 22:23 GMT
The problem is with the nested expressions, which you shouldn't need. I
think that

Value:${requestScope.clients[clientnum]}

should do the trick.

> Hi,
>
[quoted text clipped - 29 lines]
> I don't want to use iteration, please....
> Thanks in advance.
jgmaux@telefonica.net - 29 Dec 2006 22:38 GMT
Thanks, Steve.

I try your solution, but I have same problem.....

Steve ha escrito:

> The problem is with the nested expressions, which you shouldn't need. I
> think that
[quoted text clipped - 36 lines]
> > I don't want to use iteration, please....
> > Thanks in advance.
Lee  Crawford - 30 Dec 2006 00:33 GMT
I think the problem is that the forEach tag is generating a numeric
type for the clientnum variable and the ${clients[clientnum]} syntax is
failing to interpret the expression correctly because it can't use an
int to index a map and isn't making the leap to try and coerce the
value to a string. If you convert the clientnum to a string explicitly
it will work:

Add this at the top:

 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"
%>

and use:

   Value: ${clients[fn:toLowerCase (clientnum)]}

alternately, if the only information being carrier in the map keys is
an integer perhaps a List would do?

<%
   final List clients = new ArrayList ();
   clients.add ("John");
   clients.add ("Peter");
   clients.add ("Gerald");
   request.setAttribute ("clients", clients);
%>

<c:forEach var="client" varStatus="status" items="${clients}">
   ${status.count}: '${client}' <br/>
</c:forEach>

--lee

> Thanks, Steve.
>
[quoted text clipped - 42 lines]
> > > I don't want to use iteration, please....
> > > Thanks in advance.
jgmaux@telefonica.net - 30 Dec 2006 10:23 GMT
Thanks Lee,

I try your solution, and it work's .

Thanks!!!!!

Lee  Crawford ha escrito:

> I think the problem is that the forEach tag is generating a numeric
> type for the clientnum variable and the ${clients[clientnum]} syntax is
[quoted text clipped - 75 lines]
> > > > I don't want to use iteration, please....
> > > > Thanks in advance.
Lew - 30 Dec 2006 14:55 GMT
Please don't top-post. (Post re-ordered for clarity.)

Lee  Crawford ha escrito:
>> <c:forEach var="client" varStatus="status" items="${clients}">
>>     ${status.count}: '${client}' <br/>
>> </c:forEach>

> Thanks Lee,
>
> I try your solution, and it work's [sic].
>
> Thanks!!!!!

Notice that their solution uses the short-form closed "<br/>" tag.

- Lew
Lew - 30 Dec 2006 04:20 GMT
>>>     <br>
>>>         Client Nº::${clientnum}
>>>     </br>
>>>     <br>
>>>         Value:${requestScope.clients["${clientnum}"]}
>>>     </br>

This is not a correct use of the <br> tag. It does not allow content.

In other words, you do not surround text with a <br>. Your best bet is to use
the short-form closed idiom: <br/>.

- Lew


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.