If #{myBean.birthdate}
is of java.util.Calendar
or java.util.Date
type, can I possibly format this inside the EL itself using an existing function perhaps, with the output of like the one produced by the DateFormat
's SHORT
, MEDIUM
,LONG
abd FULL
output type?
Instead of outputting the complete form for the #{myBean.birthdate}
: Wed Jan 19 19:01:42 WIT 2011, I just prefer a simple output of Jan 19, 2011.
Should I use #{formatBean.format(myBean.birthdate)}
instead?
Use
<f:convertDateTime>
. You can nest this in any input and output component. Pattern rules are same asjava.text.SimpleDateFormat
.If you use OmniFaces you can also use it's EL functions like
of:formatDate()
to formatDate
objects. You would use it like this:This way you can not only use it for output but also to pass it on to other JSF components.
With EL 2 (Expression Language 2) you can use this type of construct for your question:
Or you can add an alternate getter in your bean resulting in
where getBirthdateString returns the proper text representation. Remember to annotate the get method as @Transient if it is an Entity.