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

duminică, 24 ianuarie 2016

PrimeFaces ring with OmniFaces unique value column

As you probably know, PrimeFaces comes with a component capable to display data with a circular animation. This component is named Ring.

For example, the below snippet of code will work in conjunction with BarcelonaSquadBean to return the result from image below:

<h:form id="form">           
 <p:panel>
  <p:ring id="custom" value="#{barcelonaSquadBean.players}" var="t">
   <p:outputPanel style="text-align: center; height:90%;" layout="block">                  
    <p:inputText value="#{t.name}" required="true" style="width: 90%; height: inherit;"/>           
   </p:outputPanel>                            
  </p:ring>   
 </p:panel>

 <p:panel style="text-align: center; margin-top: 10px;">
  <p:commandButton actionListener="#{barcelonaSquadBean.someAction()}" update="@form"
                   value="Subscribe Team"/>                                   
  <p:messages id="msgs"/>
 </p:panel>
</h:form>

The issue consist in the fact that we can mistakenly provide the same player name twice and obviosuly this is not diserable. In order to fix this, we can use the OmniFaces ValidateUniqueColumn validator. This validator is exposed to page authors via <o:validateUniqueColumn/> tag. The main characteristics of this validator are:
  • It validates if the given UIInput component in an UIData component has an unique value throughout all rows.
  • It includes in validation the data that is not visible in case of using pagination, as long as it is in the data model.
  • It works directly on the data model (e.g. when lazy loading is used, the data model contains a subset of data; only this subset counts on validation).
  • It signals only the first invalid row on which the value is actually changed.
  • A faces message will be added on the client ID of the input component in this invalid row.
  • Its default message is of type (the {0} placeholder represents the label of the input component, while the {1} placeholder represents the 1‐based row index of the data model):

{0}: Please fill out an unique value for the entire column. Duplicate found in row {1} 

 If you need to a custom message then just use the message attribute:

<o:validateUniqueColumn message="custom message here" />

So, we can use <o:validateUniqueColumn/> in our case like below:

<p:panel>
 <p:ring id="custom" value="#{barcelonaSquadBean.players}" var="t">
  <p:outputPanel style="text-align: center; height:90%;" layout="block">                  
   <p:inputText value="#{t.name}" required="true" style="width: 90%; height: inherit;">           
    <o:validateUniqueColumn message="Duplicate player not allowed!"/>
   </p:inputText>                     
  </p:outputPanel>                           
 </p:ring>   
</p:panel> 

This time we cannot submit the team with duplicate players. Check figure below:

The complete application is available here.

Read more such goodies in:

PrimeFaces & OmniFaces - Powers Combined

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors