This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EL expression using a declared var in data table  RSS feed

 
Stefan Mohr
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have a page with a Richfaces datatable that has a column for dynamic actions (command links) depending on the type of data in each row. I'm trying to use an EL expression to determine which actions to display.

JSP:


For the moment I'm just displaying text into the actions field - later the actions will contain links if I can get this sorted out.

My backing bean contains an ArrayList of type "item" which is a container class with some entity references and public boolean methods to determine the item type (eg. "high" or "low").
So, item.ishigh is a public boolean isHigh().

What I'm experiencing is that my EL expression aren't resolving to anything, nor am I seeing any exceptions in my Application Server log. The table is populating properly with the name/description elements.

I suspect that the problem is that I'm trying to perform an EL expression on an instance of an object declared with the var tag of the datatable. Looking at the JSTL spec, it says you can invoke an expression against any variable in scope, but I'm not sure that the EL processor sees the same "scope" as the item lives in.

Should this even work as I've implemented it?

[Edit: I should mention that EL expression are resolving correctly elsewhere on the page when I reference the bean name directly, eg. ${BackingBean.property == something}]
[ April 16, 2008: Message edited by: Stefan Mohr ]
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well your expression is wrong for one thing.
EL does the adding of the get/set/is for you.
so it should be ${item.high} rather than ${item.isHigh}

JSF and JSTL often don't play well together - mainly because ${expr} is an expression available when rendering the response, and can't always be evaluated when reconstructing the page. You need to use the unified expression language - ie #{expr}

In this case however, it would probably be better to use the JSF attribute rendered. It accomplishes the same effect, without using any JSTL tags.


Cheers,
evnafets
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to be an absolute purist about it, you'd put the text in the backing bean and use a simple value getter. This facilitates I18N and completely removes the taint of logic-ness from the JSF page.

But life is short and deadlines loom, so sometimes we make do.
 
Stefan Mohr
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stefan! That's MUCH cleaner than before (and actually works, to boot).

I've used a lot of JSTL throughout the code simply because I didn't realize how easily the rendered attribute can be. Are there any realistic performance difference between the two, or is it generally a style/compatibility decision?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!