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


miercuri, 21 ianuarie 2015

OmniFaces 2.0 - Write a custom component that receive the FaceletContext for the Facelet in which it is declared

Derived from EL context, the FaceletContext is the context representative of a single request from a Facelet. Sometimes you may need this context to be available in your custom component. Per example, you can use FaceletContext to store a ValueExpression in the "facelet scope". FaceletContext has access to the EL variable mapper via getVariableMapper()/setVariableMapper(). An EL variable mapper provides a method for resolving ValueExpressions by name, resolveVariable(), and one method for assigning a ValueExpressions to an EL variable, setVariable():
//put a ValueExpression in the "facelet" scope
FaceletContext faceletContext;
faceletContext.getVariableMapper().setVariable("variable_name", value_expression);
//get a ValueExpression from "facelet" scope
FaceletContext faceletContext;
ValueExpression ve = faceletContext.getVariableMapper().getVariable("variable_name");
But, how to obtain the FaceletContext inside a custom component ? Well, OmniFaces knows how! Whenever you need the FaceletContext for the Facelet in which your own components are declared, you can use the OmniFaces solution, which is available if you respect the following two simple bullets:

·         your custom component

public class YourComponent implements FaceletContextConsumer {

  public void setFaceletContext(FaceletContext faceletContext) {
    // use the faceletContext to do something

·         your *.taglib file:
  <tag-name>your tag name for your component</tag-name>
      <component-type>your component  type</component-type>

Niciun comentariu :

Trimiteți un comentariu


Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors