• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF EL Date Functions

 
Cory Cowgill
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to compare two dates in JSF & EL?

For example, I have two Calendar objects and in the view layer I need to display one date or the other based on which one comes first.

 
Tim Holloway
Saloon Keeper
Pie
Posts: 17995
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a logic function and logic should not be performed in the View. It's better to do the logic in the backing bean.

In a backing bean, it's pretty easy. Just expose a property to display the date and make its "get" method return the earlier of 2 Date objects:

 
Cory Cowgill
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Tim.

However, I would argue that this functionality should be available in View layer.

This is not complex business logic, this is logic specific to the View layer and only affects the View. It's specific to rendering elements on the page.

EL provides logic functions specifically so you can do things like this in the View layer to hide/show/perform simple logic to render/not render elements or change css style classes.

Otherwise, the inverse it true. Now I am putting View layer logic inside the Controller to control the rendering of elements.

It may be a mute point anyway since I got it to work.

Thanks for your input though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic