aspose file tools*
The moose likes JSP and the fly likes EL and custom tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "EL and custom tag" Watch "EL and custom tag" New topic
Author

EL and custom tag

Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
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


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"instanceof" is a reserved keyword but is not yet a valid operator in EL.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
Thank you. Do you know of any other way of doing this?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Aug 20, 2003
Posts: 532
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Jan 10, 2002
Posts: 61648
    
  67

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL and custom tag