BAEL-197 - minor changes
This commit is contained in:
parent
28fa846e48
commit
171cf1f3b4
@ -1,6 +1,8 @@
|
|||||||
package com.baeldung.springintegration.controllers;
|
package com.baeldung.springintegration.controllers;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.el.ELContextEvent;
|
||||||
|
import javax.el.ELContextListener;
|
||||||
import javax.el.LambdaExpression;
|
import javax.el.LambdaExpression;
|
||||||
import javax.faces.application.Application;
|
import javax.faces.application.Application;
|
||||||
import javax.faces.application.FacesMessage;
|
import javax.faces.application.FacesMessage;
|
||||||
@ -8,6 +10,7 @@ import javax.el.LambdaExpression;
|
|||||||
import javax.faces.bean.ManagedBean;
|
import javax.faces.bean.ManagedBean;
|
||||||
import javax.faces.bean.ViewScoped;
|
import javax.faces.bean.ViewScoped;
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.context.FacesContext;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@ManagedBean(name = "ELBean")
|
@ManagedBean(name = "ELBean")
|
||||||
@ -16,7 +19,6 @@ public class ELSampleBean {
|
|||||||
|
|
||||||
private String firstName;
|
private String firstName;
|
||||||
private String lastName;
|
private String lastName;
|
||||||
private Collection<Integer> numberList;
|
|
||||||
private String pageDescription = "This page demos JSF EL Basics";
|
private String pageDescription = "This page demos JSF EL Basics";
|
||||||
public static final String constantField = "THIS_IS_NOT_CHANGING_ANYTIME_SOON";
|
public static final String constantField = "THIS_IS_NOT_CHANGING_ANYTIME_SOON";
|
||||||
private int pageCounter;
|
private int pageCounter;
|
||||||
@ -25,13 +27,19 @@ public class ELSampleBean {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
pageCounter = randomIntGen.nextInt();
|
pageCounter = randomIntGen.nextInt();
|
||||||
|
FacesContext.getCurrentInstance().getApplication().addELContextListener(new ELContextListener() {
|
||||||
|
@Override
|
||||||
|
public void contextCreated(ELContextEvent evt) {
|
||||||
|
evt.getELContext().getImportHandler().importClass("com.baeldung.springintegration.controllers.ELSampleBean");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getConstantField() {
|
public static String constantField() {
|
||||||
return constantField;
|
return constantField;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,8 +47,8 @@ public class ELSampleBean {
|
|||||||
this.firstName = firstName;
|
this.firstName = firstName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String multiplyValue(LambdaExpression expr){
|
public Long multiplyValue(LambdaExpression expr) {
|
||||||
String theResult = (String) expr.invoke(FacesContext.getCurrentInstance().getELContext(), pageCounter);
|
Long theResult = (Long) expr.invoke(FacesContext.getCurrentInstance().getELContext(), pageCounter);
|
||||||
return theResult;
|
return theResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<h:outputText id="valueOutput" value="#{(cube=(x->x*x*x);cube(4))}"/>
|
<h:outputText id="valueOutput" value="#{(cube=(x->x*x*x);cube(4))}"/>
|
||||||
<br/>
|
<br/>
|
||||||
<h:outputLabel id="staticLabel" for="staticFieldOutput" value="Static Field Output:"/>
|
<h:outputLabel id="staticLabel" for="staticFieldOutput" value="Static Field Output:"/>
|
||||||
<h:outputText id="staticFieldOutput" value="#{com.baeldung.el.controllers.ELSampleBean.constantField}"/>
|
<h:outputText id="staticFieldOutput" value="#{ElBean.constantField}"/>
|
||||||
<br/>
|
<br/>
|
||||||
<h:outputLabel id="avgLabel" for="avg" value="Average of Integer List Value:"/>
|
<h:outputLabel id="avgLabel" for="avg" value="Average of Integer List Value:"/>
|
||||||
<h:outputText id="avg" value="#{['1','2','3'].stream().average().get()}"/>
|
<h:outputText id="avg" value="#{['1','2','3'].stream().average().get()}"/>
|
||||||
@ -19,6 +19,7 @@
|
|||||||
<h:outputLabel id="lambdaLabel" for="lambdaPass" value="Passing Lambda Expressions:"/>
|
<h:outputLabel id="lambdaLabel" for="lambdaPass" value="Passing Lambda Expressions:"/>
|
||||||
<h:outputText id="lambdaPass" value="#{ELBean.multiplyValue(x->x*x*x)}"/>
|
<h:outputText id="lambdaPass" value="#{ELBean.multiplyValue(x->x*x*x)}"/>
|
||||||
<br/>
|
<br/>
|
||||||
|
<c:set var='pageLevelNumberList' value="#{[1,2,3]}"/>
|
||||||
<h:outputLabel id="avgPageVarLabel" for="avgPageVar" value="Average of Page-Level Integer List Value:"/>
|
<h:outputLabel id="avgPageVarLabel" for="avgPageVar" value="Average of Page-Level Integer List Value:"/>
|
||||||
<h:outputText id="avgPageVar" value="#{pageLevelNumberList.stream().average().get()}"/>
|
<h:outputText id="avgPageVar" value="#{pageLevelNumberList.stream().average().get()}"/>
|
||||||
<br/>
|
<br/>
|
||||||
@ -29,7 +30,6 @@
|
|||||||
</h:column>
|
</h:column>
|
||||||
</h:dataTable>
|
</h:dataTable>
|
||||||
</h:panelGrid>
|
</h:panelGrid>
|
||||||
<c:set var='pageLevelNumberList' value="#{[1,2,3]}"/>
|
|
||||||
</h:body>
|
</h:body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user