Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why doesn't this work?

 
Mitch Miller
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Expression is blank, not "1".
Tomcat produced:
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${one}", java.lang.String.class, (PageContext)_jspx_page_context, null, false));

Tomcat doc says:
public static java.lang.Object proprietaryEvaluate(java.lang.String expression, java.lang.Class expectedType, javax.servlet.jsp.PageContext pageContext, ProtectedFunctionMapper functionMap, boolean escape) throws javax.servlet.jsp.el.ELException

expectedType - The expected resulting type

if "expectedType" is String, shouldn't it produce "one.toString()"

Similarly: ${one + 1} = "1" not "2"
I expected Integer to be automatically converted to int primitive.

Thanks for your help,
Mitch
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mitch Miller:
[QB]


EL should not mixed with scriplet.. if you want output try this




if you want to display an object using EL.that object should in any of the scope[something like request.setAttribute("one",one)..]
got it?

note: please discourage the scriptlet

Hope This Helps
 
Mitch Miller
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As seetharaman discouraged you from using scriptlet. Thanks, Seetharaman for a good advice.



This code should work. Its equivalent to what you were trying to achieve. This wouldn't bind the thing to request object, unlike the given scriptlet code.

Cheers.

[Edited]
Changed scope from request to page.
[ August 14, 2008: Message edited by: Adeel Ansari ]
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Adeel Ansari:



(...) This wouldn't bind the thing to request object, unlike the given scriptlet code.

Cheers.


Could you clarify on that? To my understanding, c:set does create an attribute for the given scope (request in this case) - just like the scriptlet does. Otherwise there's no way to get the value with EL.
[ August 14, 2008: Message edited by: Jan Sterk ]
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jan Sterk:

Could you clarify on that? To my understanding, c:set does create an attribute for the given scope (request in this case) - just like the scriptlet does. Otherwise there's no way to get the value with EL.



you are right JAN
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason that the original code does not work is that the variable declared is a variable local to the Page but not in the PageContext scope.

The EL does not look at local Page variables.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry did I post "request". I meant "page". So, the given code would become something like below,

Made correction to my original post. Thanks for pointing out Jan. I hope it became clear now.
[ August 14, 2008: Message edited by: Adeel Ansari ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic