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