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

marți, 10 februarie 2015

[OmniFaces utilities (2.0)] Get a list of UI components matching the given type in children of the given component


[OmniFaces utilities] The findComponentsInChildren() returns a list of UI components matching the given type in children of the given component.

Method:
Usage:
JSF Page Snippet
<h:form id="myFormId">
 <h:inputText id="nameId" value="#{playersBean.name}"/>
 <h:inputText id="surnameId" value="#{playersBean.surname}"/>
 <h:inputText id="ageId" value="#{playersBean.age}"/>
 <h:selectOneMenu id="selectId" value="#{playersBean.title}">
  <f:selectItem id="rgItemId" itemValue="Roland Garros" itemLabel="Roland Garros" />
  <f:selectItem id="uoItemId" itemValue="US Open" itemLabel="US Open" />
  <f:selectItem id="aoItemId" itemValue="Australian Open" itemLabel="Australian Open" />
  <f:selectItem id="wItemId" itemValue="Wimbledon" itemLabel="Wimbledon" />
 </h:selectOneMenu>
 <h:commandButton id="btnId" value="Save" action="#{playersBean.save()}">
  <f:param id="auParamId" name="titles" value="Australian Open"/>
  <f:param id="rgParamId" name="titles" value="Roland Garros"/>
  <f:param id="wParamId" name="titles" value="Wimbledon"/>
  <f:param id="uoParamId" name="titles" value="US Open"/>              
 </h:commandButton>
</h:form>

Now, let's have a few examples to see how findComponentsInChildren() works (for all examples, we will use the UIForm (playersForm object) as the component to search in, but you can adjust this accordingly; the output contains the component class and the component clientId):

import org.omnifaces.util.Components;
...
·         find all components in form that are instances if UIInput (or derived from UIInput)

List<UIInput> inputs = Components.findComponentsInChildren(playersForm, UIInput.class);

Output:
 Class: class javax.faces.component.html.HtmlInputText    ClientId:myFormId:nameId
 Class: class javax.faces.component.html.HtmlInputText    ClientId:myFormId:surnameId
 Class: class javax.faces.component.html.HtmlInputText    ClientId:myFormId:ageId
 Class: class javax.faces.component.html.HtmlSelectOneMenu    ClientId:myFormId:selectId

·         find all components in form that are instances if UIParameter (or derived from UIParameter)

List<UIParameter> params = Components.findComponentsInChildren(playersForm, UIParameter.class);

Output:
Class: class javax.faces.component.UIParameter    ClientId:myFormId:auParamId
Class: class javax.faces.component.UIParameter    ClientId:myFormId:rgParamId
Class: class javax.faces.component.UIParameter    ClientId:myFormId:wParamId
Class: class javax.faces.component.UIParameter    ClientId:myFormId:uoParamId

·         find all components in form that are instances if UISelectItem (or derived from UISelectItem)

List<UISelectItem> selectitems = Components.findComponentsInChildren(playersForm, UISelectItem.class);

Output:
Class: class javax.faces.component.UISelectItem    ClientId:myFormId:rgItemId
Class: class javax.faces.component.UISelectItem    ClientId:myFormId:uoItemId
Class: class javax.faces.component.UISelectItem    ClientId:myFormId:aoItemId
Class: class javax.faces.component.UISelectItem    ClientId:myFormId:wItemId

·         find all components in form that are instances if UICommand (or derived from UICommand)

List<UICommand> commands = Components.findComponentsInChildren(playersForm, UICommand.class);

Output:

Class: class javax.faces.component.html.HtmlCommandButton    ClientId:myFormId:btnId

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors