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, 11 martie 2015

[OmniFaces utilities (2.0)] Programmatically evaluate/set the given EL expression

[OmniFaces utilities] The evaluateExpressionGet() method programmatically evaluate the given EL expression and return the evaluated value.
[OmniFaces utilities] The evaluateExpressionSet() method programmatically evaluate the given EL expression and set the given value.


Let's prepare something:

public class LoginBean implements Serializable {
 private String email;     // suppose it will be ''
 private String password;  // suppose it will be 'numberonealltimes'
 private String reverse;   // it will store the password reversed string

 public String loginAction(String role, String user){
  return "Welcome, " + user + "(" + role + ")!";

 public String logoutAction(){
  return "Successfully logout";

 //getters and setters

Now, let's evaluate the email and password:

import org.omnifaces.util.Faces;
// evaluated to ''
String getemail = Faces.evaluateExpressionGet("#{}");

// evaluated to 'numberonealltimes'
String getpassword = Faces.evaluateExpressionGet("#{loginBean.password}");

// evaluated to 'Welcome,!'
String login = Faces.evaluateExpressionGet("#{loginBean.loginAction('gold','"+getemail+"')}");

// evaluated to 'Successfully logout'
String logout = Faces.evaluateExpressionGet("#{loginBean.logoutAction()}");

OmniFaces also provides an OmniFaces utilities for setting the value.


// set 'email' field as ''
Faces.evaluateExpressionSet("#{}", "");

// set 'password' field as 'numberonealltimes'
Faces.evaluateExpressionSet("#{loginBean.password}", "numberonealltimes");

// set 'reverse' field as reverse string of evaluated 'password'
Faces.evaluateExpressionSet("#{loginBean.reverse}",  new StringBuffer((String)Faces.evaluateExpressionGet("#{loginBean.password}")).reverse().toString());

Niciun comentariu :

Trimiteți un comentariu


Postări populare

OmniFaces/JSF Fans

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors