File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes JSF EL Date Functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF EL Date Functions" Watch "JSF EL Date Functions" New topic

JSF EL Date Functions

Cory Cowgill

Joined: Mar 15, 2011
Posts: 4
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

Joined: Jun 25, 2001
Posts: 17423

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:

An IDE is no substitute for an Intelligent Developer.
Cory Cowgill

Joined: Mar 15, 2011
Posts: 4
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.
I agree. Here's the link:
subject: JSF EL Date Functions
It's not a secret anymore!