• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EL and custom tag

 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. Do you know of any other way of doing this?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic