My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

.

.

.

.

.

.

.

.


[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians

Twitter

vineri, 27 noiembrie 2015

[OmniFaces utilities 2.0] A mapping of month names (full/short names) by month numbers for the current locale


[OmniFaces utilities] The getMonths() function returns a mapping of month names by month numbers for the current locale. For example: "January=1", "February=2", etc. This is useful if you want to for example populate a <f:selectItems> which shows all months. The locale is obtained by Faces#getLocale(). The mapping is per locale stored in a local cache to improve retrieving performance.

[OmniFaces utilities] The getShortMonths() function returns a mapping of short month names by month numbers for the current locale. For example: "Jan=1", "Feb=2", etc. This is useful if you want to for example populate a <f:selectItems> which shows all short months. The locale is obtained by Faces#getLocale(). The mapping is per locale stored in a local cache to improve retrieving performance.

[OmniFaces utilities] The getMonth() function returns the month name from the mapping associated with the given month number for the current locale. For example: "1=January", "2=February", etc. The locale is obtained by Faces#getLocale().

[OmniFaces utilities] The getShortMonth() function returns the short month name from the mapping associated with the given month number for the current locale. For example: "1=Jan", "2=Feb", etc. The locale is obtained by Faces#getLocale().

Function (full names):

Function (short names):

Functions (get month name (full/short name) by month number)

Usage:

In OmniFaces Showcase you can see how an example of how to populate a <f:selectItems/> which shows all months. Below, you can see an example of displaying the month numbers and names in a data table.

Full names via of:getMonths():

<h:dataTable value="#{of:getMonths().entrySet()}" var="t">
 <h:column>
  <f:facet name="header">No.</f:facet>
  #{t.value}
 </h:column>
 <h:column>
  <f:facet name="header">Name</f:facet>
  #{t.key}
 </h:column>
</h:dataTable>

Short names via of:getShortMonths():

<h:dataTable value="#{of:getShortMonths().entrySet()}" var="t">
 <h:column>
  <f:facet name="header">No.</f:facet>
  #{t.value}
 </h:column>
 <h:column>
  <f:facet name="header">Name</f:facet>
  #{t.key}
 </h:column>
</h:dataTable>

Moreover, we can obtain a month name (short name) by its number via of:getMonth() and of:getShortMonth():

The 10 month of the year is: #{of:getMonth(10)}
Output: October
The 10 month of the year is: #{of:getShortMonth(10)}
Output: Oct

The month number can be provided from a managed bean also:

#{of:getMonth(fooBean.monthnumer)}
#{of:getShortMonth(fooBean.monthnumer)}

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors