This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL and custom tag

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:

Why is the following line cannot be evaluated?

<c:when test="${queryResult instanceof java.util.List}">

queryResult is an Object in the request scope.
I want to check if the queryResult a list or not. I get error that the EL is not valid.
Can it be done any other way?

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"instanceof" is a reserved keyword but is not yet a valid operator in EL.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. Do you know of any other way of doing this?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't be checking on the JSP page. Why are you in the situation where you don't know what type a scoped variable is? This is something that should be handled before the JSP is invoked.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can check for empty.

I'm assuming that, if you have an empty set, you're not binding the list to scope.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code need to be generic. The controller doesn't know whether the return value is a list or anything else. The JSP needs to check if it is a list, a table will be displayed with the result, otherwise the object value will be displayed.

I believe it should be handled by the view not the controller.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would think that it should be handled by the model.
Not the controller or the view.

Perform your operation, test the results, and conditionally bind the list, or not.


A good rule of thumb for EL and JSTL is: If what you're trying to do is difficult, you probably shouldn't be doing it there.
[ April 29, 2008: Message edited by: Ben Souther ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Hanna Habashy:
The controller doesn't know whether the return value is a list or anything else.
But it can. And certainly much easier than in a JSP.

I believe it should be handled by the view not the controller.
It's the page controller's job to make things as easy for the JSP as possible. I'd use the controller to set a scoped variable such that it's easy to do the right thing on the JSP with the simple EL expressions and JSTL tags that are available to us.

It's always possible to write a custom action or EL function that cold help you here, but I use those as last resorts.

Ben's point about abstracting this to a lower level is also worth pondering.
[ April 29, 2008: Message edited by: Bear Bibeault ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic