From 3b9e4c7a567054f3113aa3554e2c59eaa30d1f93 Mon Sep 17 00:00:00 2001 From: Slavisa Baeldung Date: Wed, 6 Jul 2016 13:24:52 +0200 Subject: [PATCH] BAEL-151 - Adding EL dependency --- jsf/pom.xml | 7 + .../{ => controllers}/ELSampleBean.java | 228 +++++++++--------- 2 files changed, 117 insertions(+), 118 deletions(-) rename jsf/src/main/java/com/baeldung/springintegration/{ => controllers}/ELSampleBean.java (80%) diff --git a/jsf/pom.xml b/jsf/pom.xml index c4801996de..b5fbae4cf0 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -25,6 +25,12 @@ jsf-impl ${com.sun.faces.version} + + javax.el + el-api + ${javax.el.version} + + @@ -114,6 +120,7 @@ 2.1.7 + 2.2 1.7.13 diff --git a/jsf/src/main/java/com/baeldung/springintegration/ELSampleBean.java b/jsf/src/main/java/com/baeldung/springintegration/controllers/ELSampleBean.java similarity index 80% rename from jsf/src/main/java/com/baeldung/springintegration/ELSampleBean.java rename to jsf/src/main/java/com/baeldung/springintegration/controllers/ELSampleBean.java index 32076bcbad..a13f0890b5 100644 --- a/jsf/src/main/java/com/baeldung/springintegration/ELSampleBean.java +++ b/jsf/src/main/java/com/baeldung/springintegration/controllers/ELSampleBean.java @@ -1,118 +1,110 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.baeldung.el.controllers; - -import java.util.Random; -import javax.annotation.PostConstruct; -import javax.faces.application.Application; -import javax.faces.application.FacesMessage; -import javax.faces.bean.ManagedBean; -import javax.faces.bean.ViewScoped; -import javax.faces.component.html.HtmlInputText; -import javax.faces.context.FacesContext; - -/** - * - * @author Tayo - */ -@ManagedBean(name = "ELBean") -@ViewScoped -public class ELSampleBean { - - private String firstName; - private String lastName; - private String pageDescription = "This page demos JSF EL Basics"; - private int pageCounter; - private Random randomIntGen = new Random(); - - @PostConstruct - public void init() { - pageCounter = randomIntGen.nextInt(); - } - - public void save(){ - - } - - public void saveFirstName(String firstName) { - this.firstName = firstName; - } - - - public void saveByELEvaluation(){ - firstName = (String)evaluateEL("#{firstName.value}", String.class); - FacesContext ctx = FacesContext.getCurrentInstance(); - FacesMessage theMessage = new FacesMessage("Name component Evaluated: "+firstName); - theMessage.setSeverity(FacesMessage.SEVERITY_INFO); - ctx.addMessage(null,theMessage); - - } - - private Object evaluateEL(String elExpression, Class clazz) { - Object toReturn = null; - FacesContext ctx = FacesContext.getCurrentInstance(); - Application app = ctx.getApplication(); - toReturn = app.evaluateExpressionGet(ctx, elExpression, clazz); - - return toReturn; - - } - - /** - * @return the firstName - */ - public String getFirstName() { - return firstName; - } - - /** - * @param firstName the firstName to set - */ - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - /** - * @return the lastName - */ - public String getLastName() { - return lastName; - } - - /** - * @param lastName the lastName to set - */ - public void setLastName(String lastName) { - this.lastName = lastName; - } - - /** - * @return the pageDescription - */ - public String getPageDescription() { - return pageDescription; - } - - /** - * @param pageDescription the pageDescription to set - */ - public void setPageDescription(String pageDescription) { - this.pageDescription = pageDescription; - } - - /** - * @return the pageCounter - */ - public int getPageCounter() { - return pageCounter; - } - - /** - * @param pageCounter the pageCounter to set - */ - public void setPageCounter(int pageCounter) { - this.pageCounter = pageCounter; - } -} +package com.baeldung.springintegration.controllers; + +import java.util.Random; +import javax.annotation.PostConstruct; +import javax.faces.application.Application; +import javax.faces.application.FacesMessage; +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ViewScoped; +import javax.faces.component.html.HtmlInputText; +import javax.faces.context.FacesContext; + +@ManagedBean(name = "ELBean") +@ViewScoped +public class ELSampleBean { + + private String firstName; + private String lastName; + private String pageDescription = "This page demos JSF EL Basics"; + private int pageCounter; + private Random randomIntGen = new Random(); + + @PostConstruct + public void init() { + pageCounter = randomIntGen.nextInt(); + } + + public void save() { + + } + + public void saveFirstName(String firstName) { + this.firstName = firstName; + } + + + public void saveByELEvaluation() { + firstName = (String) evaluateEL("#{firstName.value}", String.class); + FacesContext ctx = FacesContext.getCurrentInstance(); + FacesMessage theMessage = new FacesMessage("Name component Evaluated: " + firstName); + theMessage.setSeverity(FacesMessage.SEVERITY_INFO); + ctx.addMessage(null, theMessage); + + } + + private Object evaluateEL(String elExpression, Class clazz) { + Object toReturn = null; + FacesContext ctx = FacesContext.getCurrentInstance(); + Application app = ctx.getApplication(); + toReturn = app.evaluateExpressionGet(ctx, elExpression, clazz); + + return toReturn; + + } + + /** + * @return the firstName + */ + public String getFirstName() { + return firstName; + } + + /** + * @param firstName the firstName to set + */ + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + /** + * @return the lastName + */ + public String getLastName() { + return lastName; + } + + /** + * @param lastName the lastName to set + */ + public void setLastName(String lastName) { + this.lastName = lastName; + } + + /** + * @return the pageDescription + */ + public String getPageDescription() { + return pageDescription; + } + + /** + * @param pageDescription the pageDescription to set + */ + public void setPageDescription(String pageDescription) { + this.pageDescription = pageDescription; + } + + /** + * @return the pageCounter + */ + public int getPageCounter() { + return pageCounter; + } + + /** + * @param pageCounter the pageCounter to set + */ + public void setPageCounter(int pageCounter) { + this.pageCounter = pageCounter; + } +}