Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can not resolve symbol in c:forEach  RSS feed

 
Di Wang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WSAD 5.1.2 lite container, JSP container 1.2 I believe

jsp:useBean id="currency" classname="CurrencyConverter"
/jsp:useBean
..
c:forEach var="ccdc" items="${orderBean.items}"
[leftbracket]%= currency.convertPrice(ccdc.price) %[righbracket]
/c:forEach

It complains "cannot resolve symbol" ccdc. I need to use scriptlet due to existing code.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please edit your post, adding UBB code tags to perserved the formatting.

Also, please use real left and right angle brackets so your code is readable.
[ August 15, 2006: Message edited by: Bear Bibeault ]
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSTL variables and scriptlet variables do not share the same namespace.

JSTL variables map to the attributes in page, request, session and application scopes.

So if you have a JSTL variable ${expr}
Printing <%= expr %> will not display it. Instead it would have to be something like <%= pageContext.findAttribute("expr") %>

JSTL doesn't have any facility for passing parameters to methods. You can only invoke getters/setters via the EL.

The workaround would be to have the CurrencyConverter implement two getters/setters- get/set price, and get/set convertedPrice, and evaluate the code something like this.
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSTL variables and scriptlet variables do not share the same namespace.

JSTL variables map to the attributes in page, request, session and application scopes.

So if you have a JSTL variable ${expr}
Printing <%= expr %> will not display it. Instead it would have to be something like <%= pageContext.findAttribute("expr") %>

JSTL doesn't have any facility for passing parameters to methods. You can only invoke getters/setters via the EL.

The workaround would be to have the CurrencyConverter implement two getters/setters- get/set price, and get/set convertedPrice, and evaluate the code something like this.
 
nizams uddin
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i feel that you have many simple errors in code.
such as id yu have given as "currency" and you are accessing method with name
"orderBean" instead of "currency".
And also,
<jsp:useBean id="currency" classname="CurrencyConverter" />
has a class atribute and not classname attribute as you have specified.
make these changes and try to access.
 
Di Wang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The scriptlet can access "currency". How is this different from "ccdc"? And more specifically, in terms of namespace? Thanks!
 
Di Wang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I did:



It works. A little ugly but I guess this is the best I can do (without changing existing code)? Any other suggestions?

Thanks Stefan for the tip.

Thanks Nizams for pointing out the errors. I had the orderBean defined but not included in the snipplet and the tags "classname" was indeed my typo.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!