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?
SimpleDateFormat df = new SimpleDateFormat(" dd MMM yyyy"); Date oneDate = new Date(startDate); df. format(oneDate);
JSF: Handling Dates in JSF Forms The user enters the student data into the form: first name, last name and hire date. The input format for the hire date is day, month, year. As an example For 1 May 2016, you would enter: 1-5-2016. Once the form is submitted, then the app will show the output.
Use <f:convertDateTime>
. You can nest this in any input and output component. Pattern rules are same as java.text.SimpleDateFormat
.
<h:outputText value="#{someBean.dateField}" > <f:convertDateTime pattern="dd.MM.yyyy HH:mm" /> </h:outputText>
If you use OmniFaces you can also use it's EL functions like of:formatDate()
to format Date
objects. You would use it like this:
<h:outputText value="#{of:formatDate(someBean.dateField, 'dd.MM.yyyy HH:mm')}" />
This way you can not only use it for output but also to pass it on to other JSF components.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With