Forums Register Login

Type Issue with EL

+Pie Number of slices to send: Send
I have a class called "user" and am trying to access an array of these guys that is set up in a servlet with EL, and it appears that EL thinks that it is a string.

Here is the servlet code where it is set up:



The user list (with a length of one for testing purposes) seems OK in the servlet.

The getters user.getUserKey(), user.getUserID(), etc. are all defined, and set up as per the following example:



and here is the point in the JSP where I'm trying to access it (the <option> tag and it's body):



The error I get is:



It *seems* that tomcat thinks it's a string, instead of a user. This is the first time I've use EL or JSTL extensively, but thought type coercion would fix it.

Any insights?

TIA
+Pie Number of slices to send: Send
<c:forEach items="userlist" var="u">


Try:

<c:forEach items="${userlist}" var="u">
+Pie Number of slices to send: Send
Hey, that was it! Thanks a lot!
+Pie Number of slices to send: Send
Done that more times than I care to admit
+Pie Number of slices to send: Send
The important thing is, do you understand the difference?
+Pie Number of slices to send: Send
There's a good chance I don't understand the difference. The syntax I was using was similar to the way one would access a bean, attribute or a name/value pair. The syntax suggested by Ben that worked was EL syntax. I suppose I must confess it is not clear to me when one uses one versus the other, why in this context the access is as an EL variable when I set it using HttpRequest.setAttribute().

The answer may also explain another problem I was just going to post. I don't have a clear understanding at all as to when the various variable go in and out of scope,and exactly how they're accessed under various circumstances.

Please continue...
+Pie Number of slices to send: Send
Do not confuse the JSTL tags with the classic actions like <jsp:getProperty>. They have little in common.

You should have the JSTL Specification open on your desk. The descriptions of the JSTL action in that document are essential.

In

<c:forEach items="userlist" var="listOfUsers">

the items attribute is the string containing the characters u s e r l i s and t.

In

<c:forEach items="${userlist}" var="listOfUsers">

the EL ${} notation makes its content an EL expression; in this case one that references a scoped variable named userlist.
[ September 22, 2006: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
Ahhh! I think I get it. What I really had was:



so when I used


later in the jsp, it interpreted the

as the first element of the attribute

and thought I was trying to use a member of the string class, hence that string-related error.

Right?

Thanks a million!

p.s., sorry about all the code tags; the reply system won't let me use the letter

by itself.
+Pie Number of slices to send: Send
Wow! That was a hassle!

How did you do:



in your post? This thing wouldn't let me use a "you" by itself.
+Pie Number of slices to send: Send
With
items="userlist"

you've got a string literal in the items attribute.
With ${userList} you've got a variable that points the scoped variable named "userList".

Your page blew up when you tried to dereference properties that didn't exist in the string literal.
+Pie Number of slices to send: Send
Exactly. In the first example, you passed it a string literal, so it was iterating over it rather than your intended scoped variable.

And about "u"... that's because too many people think that u is an acceptable form of the word "you". It's not.
+Pie Number of slices to send: Send
Right. I understand perfectly that "u" doesn't equal "you" and only use it under extreme circumstances (like trying to text message and drive at the same time;-). Those of us in the civilized world also capitalize and punctuate, so I actually strongly agree with the policy.

But when you need it, like you did, how do you get the message board to take it? Is there an escape sequence?
+Pie Number of slices to send: Send
&#117;


[ September 22, 2006: Message edited by: Ben Souther ]
+Pie Number of slices to send: Send
 

Originally posted by Ben Souther:
&#117;



Knowledge will set you free!
Hoo hoo hoo! Looks like we got a live one! Here, wave this tiny ad at it:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1281 times.
Similar Threads
JSP, beans and sharing ArrayLists
Database values in JSP page
Retrieving hashtable values in JSP
c:forEach and runtime "end" expression
mapping between JSP n form
Thread Boost feature
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:18:47.