BAEL-151 - Adding EL dependency

This commit is contained in:
Slavisa Baeldung 2016-07-06 13:24:52 +02:00
parent eb244dd0e6
commit 3b9e4c7a56
2 changed files with 117 additions and 118 deletions

View File

@ -25,6 +25,12 @@
<artifactId>jsf-impl</artifactId> <artifactId>jsf-impl</artifactId>
<version>${com.sun.faces.version}</version> <version>${com.sun.faces.version}</version>
</dependency> </dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>${javax.el.version}</version>
</dependency>
<!-- Spring --> <!-- Spring -->
@ -114,6 +120,7 @@
<!-- JSF --> <!-- JSF -->
<com.sun.faces.version>2.1.7</com.sun.faces.version> <com.sun.faces.version>2.1.7</com.sun.faces.version>
<javax.el.version>2.2</javax.el.version>
<!-- logging --> <!-- logging -->
<org.slf4j.version>1.7.13</org.slf4j.version> <org.slf4j.version>1.7.13</org.slf4j.version>

View File

@ -1,118 +1,110 @@
/* package com.baeldung.springintegration.controllers;
* To change this template, choose Tools | Templates
* and open the template in the editor. import java.util.Random;
*/ import javax.annotation.PostConstruct;
package com.baeldung.el.controllers; import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import java.util.Random; import javax.faces.bean.ManagedBean;
import javax.annotation.PostConstruct; import javax.faces.bean.ViewScoped;
import javax.faces.application.Application; import javax.faces.component.html.HtmlInputText;
import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped; @ManagedBean(name = "ELBean")
import javax.faces.component.html.HtmlInputText; @ViewScoped
import javax.faces.context.FacesContext; public class ELSampleBean {
/** private String firstName;
* private String lastName;
* @author Tayo private String pageDescription = "This page demos JSF EL Basics";
*/ private int pageCounter;
@ManagedBean(name = "ELBean") private Random randomIntGen = new Random();
@ViewScoped
public class ELSampleBean { @PostConstruct
public void init() {
private String firstName; pageCounter = randomIntGen.nextInt();
private String lastName; }
private String pageDescription = "This page demos JSF EL Basics";
private int pageCounter; public void save() {
private Random randomIntGen = new Random();
}
@PostConstruct
public void init() { public void saveFirstName(String firstName) {
pageCounter = randomIntGen.nextInt(); this.firstName = firstName;
} }
public void save(){
public void saveByELEvaluation() {
} firstName = (String) evaluateEL("#{firstName.value}", String.class);
FacesContext ctx = FacesContext.getCurrentInstance();
public void saveFirstName(String firstName) { FacesMessage theMessage = new FacesMessage("Name component Evaluated: " + firstName);
this.firstName = firstName; theMessage.setSeverity(FacesMessage.SEVERITY_INFO);
} ctx.addMessage(null, theMessage);
}
public void saveByELEvaluation(){
firstName = (String)evaluateEL("#{firstName.value}", String.class); private Object evaluateEL(String elExpression, Class<?> clazz) {
FacesContext ctx = FacesContext.getCurrentInstance(); Object toReturn = null;
FacesMessage theMessage = new FacesMessage("Name component Evaluated: "+firstName); FacesContext ctx = FacesContext.getCurrentInstance();
theMessage.setSeverity(FacesMessage.SEVERITY_INFO); Application app = ctx.getApplication();
ctx.addMessage(null,theMessage); toReturn = app.evaluateExpressionGet(ctx, elExpression, clazz);
} return toReturn;
private Object evaluateEL(String elExpression, Class<?> clazz) { }
Object toReturn = null;
FacesContext ctx = FacesContext.getCurrentInstance(); /**
Application app = ctx.getApplication(); * @return the firstName
toReturn = app.evaluateExpressionGet(ctx, elExpression, clazz); */
public String getFirstName() {
return toReturn; return firstName;
}
}
/**
/** * @param firstName the firstName to set
* @return the firstName */
*/ public void setFirstName(String firstName) {
public String getFirstName() { this.firstName = firstName;
return firstName; }
}
/**
/** * @return the lastName
* @param firstName the firstName to set */
*/ public String getLastName() {
public void setFirstName(String firstName) { return lastName;
this.firstName = firstName; }
}
/**
/** * @param lastName the lastName to set
* @return the lastName */
*/ public void setLastName(String lastName) {
public String getLastName() { this.lastName = lastName;
return lastName; }
}
/**
/** * @return the pageDescription
* @param lastName the lastName to set */
*/ public String getPageDescription() {
public void setLastName(String lastName) { return pageDescription;
this.lastName = lastName; }
}
/**
/** * @param pageDescription the pageDescription to set
* @return the pageDescription */
*/ public void setPageDescription(String pageDescription) {
public String getPageDescription() { this.pageDescription = pageDescription;
return pageDescription; }
}
/**
/** * @return the pageCounter
* @param pageDescription the pageDescription to set */
*/ public int getPageCounter() {
public void setPageDescription(String pageDescription) { return pageCounter;
this.pageDescription = pageDescription; }
}
/**
/** * @param pageCounter the pageCounter to set
* @return the pageCounter */
*/ public void setPageCounter(int pageCounter) {
public int getPageCounter() { this.pageCounter = pageCounter;
return pageCounter; }
} }
/**
* @param pageCounter the pageCounter to set
*/
public void setPageCounter(int pageCounter) {
this.pageCounter = pageCounter;
}
}