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


marți, 30 iunie 2015

[OmniFaces utilities 2.1] Programmatically EL-resolve the given property on the given base object and return the resolved value

[OmniFaces utilities] The resolveExpressionGet() method programmatically EL-resolve the given property on the given base object and return the resolved value.

See also: Faces#getContext()

Let's suppose that we have the following simple CDI bean:

public class CommandBean {

 private String command;

 public String getCommand() {
  return command;

 public void setCommand(String command) {
  this.command = command;

Now, the Faces#resolveExpressionGet() is capable to programmatically EL-resolve the command property on the CommandBean base object and return the resolved value. In a real scenario, you will be in a JSF artifact (e.g. in a bean, custom component, etc), and you will need to inspect the property of an existing CommandBean object (instance). But, we can also perform a quick test via Beans#getInstance() utility method, which returns the CDI managed bean instance (actual) of the given bean class and creates one if one doesn't exist. Since the above bean is a CDI bean, we can do this:

// returns:
   - null, if the CommandBean object (instance) was created by the Beans#getInstance(), since one doesn't exist
   - if the CommandBean object (instance) exist, it will return the current value of the command property
CommandBean commandBean = Beans.getInstance(CommandBean.class);
String resolved = Faces.resolveExpressionGet(commandBean, "command");

You can resolve a top-level variable also, by passing null as base:

Object resolved = Faces.resolveExpressionGet(null, "top-level variable");

Niciun comentariu :

Trimiteți un comentariu


Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors