This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JSP and the fly likes Passing variable name to java method with JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing variable name to java method with JSTL" Watch "Passing variable name to java method with JSTL" New topic
Author

Passing variable name to java method with JSTL

Riccardo Panaia
Greenhorn

Joined: Dec 31, 2003
Posts: 2
Hello All, my first time posting here. I've done some research on this topic and so far have come up empty. What I am trying to do is call a java method and pass a parameter string using JSTL. Here is a sample of the code I am using:
<c:when test='${holding.product.validity["lineOfBusiness"] == "1"}'> This code compiles but throws this error when hit:
An error occurred while evaluating custom action attribute "test" with value "${holding.product.validity["lineOfBusiness"] == "1" && holding.product.lineOfBusiness != null}":
Unable to find a value for "validity" in object of class "com.mm.dts.paar.data.PAARProduct" using operator "." (null)
Now I am fairly new to the whole java/jsp/jstl realm, but my first question is it possible to call a java method and pass in a parameter using jstl core tags? If this it true, then my next question would be is my syntax messed up that's causing it to fail? Thanks in advance for any suggestions/comments. Thanks, Rick.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61106
    
  66

To my knowledge, no. (Caveat, I recall reading something about JSP 2 being able to do something along these lines, but I haven't had a chance to play around with it yet -- you know, busy getting product out the door and all).
However, in your example, the EL is expecting 'validity' to be a property of the 'product' bean. If 'validity' is a method (as I suspect from your post), the EL will not call it. (Rather it is looking for method getValidity()).
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Riccardo Panaia
Greenhorn

Joined: Dec 31, 2003
Posts: 2
Thanks for the input Bear, I was afraid of that. Back to rewriting my code. Happy New Year!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Passing variable name to java method with JSTL