Skip to content

Commit 2f4079d

Browse files
authored
Add files via upload
Backing bean to support el intro article
1 parent a661e0e commit 2f4079d

1 file changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package com.baeldung.el.controllers;
6+
7+
import java.util.Random;
8+
import javax.annotation.PostConstruct;
9+
import javax.faces.application.Application;
10+
import javax.faces.application.FacesMessage;
11+
import javax.faces.bean.ManagedBean;
12+
import javax.faces.bean.ViewScoped;
13+
import javax.faces.component.html.HtmlInputText;
14+
import javax.faces.context.FacesContext;
15+
16+
/**
17+
*
18+
* @author Tayo
19+
*/
20+
@ManagedBean(name = "ELBean")
21+
@ViewScoped
22+
public class ELSampleBean {
23+
24+
private String firstName;
25+
private String lastName;
26+
private String pageDescription = "This page demos JSF EL Basics";
27+
private int pageCounter;
28+
private Random randomIntGen = new Random();
29+
30+
@PostConstruct
31+
public void init() {
32+
pageCounter = randomIntGen.nextInt();
33+
}
34+
35+
public void save(){
36+
37+
}
38+
39+
public void saveFirstName(String firstName) {
40+
this.firstName = firstName;
41+
}
42+
43+
44+
public void saveByELEvaluation(){
45+
firstName = (String)evaluateEL("#{firstName.value}", String.class);
46+
FacesContext ctx = FacesContext.getCurrentInstance();
47+
FacesMessage theMessage = new FacesMessage("Name component Evaluated: "+firstName);
48+
theMessage.setSeverity(FacesMessage.SEVERITY_INFO);
49+
ctx.addMessage(null,theMessage);
50+
51+
}
52+
53+
private Object evaluateEL(String elExpression, Class<?> clazz) {
54+
Object toReturn = null;
55+
FacesContext ctx = FacesContext.getCurrentInstance();
56+
Application app = ctx.getApplication();
57+
toReturn = app.evaluateExpressionGet(ctx, elExpression, clazz);
58+
59+
return toReturn;
60+
61+
}
62+
63+
/**
64+
* @return the firstName
65+
*/
66+
public String getFirstName() {
67+
return firstName;
68+
}
69+
70+
/**
71+
* @param firstName the firstName to set
72+
*/
73+
public void setFirstName(String firstName) {
74+
this.firstName = firstName;
75+
}
76+
77+
/**
78+
* @return the lastName
79+
*/
80+
public String getLastName() {
81+
return lastName;
82+
}
83+
84+
/**
85+
* @param lastName the lastName to set
86+
*/
87+
public void setLastName(String lastName) {
88+
this.lastName = lastName;
89+
}
90+
91+
/**
92+
* @return the pageDescription
93+
*/
94+
public String getPageDescription() {
95+
return pageDescription;
96+
}
97+
98+
/**
99+
* @param pageDescription the pageDescription to set
100+
*/
101+
public void setPageDescription(String pageDescription) {
102+
this.pageDescription = pageDescription;
103+
}
104+
105+
/**
106+
* @return the pageCounter
107+
*/
108+
public int getPageCounter() {
109+
return pageCounter;
110+
}
111+
112+
/**
113+
* @param pageCounter the pageCounter to set
114+
*/
115+
public void setPageCounter(int pageCounter) {
116+
this.pageCounter = pageCounter;
117+
}
118+
}

0 commit comments

Comments
 (0)