BAEL-197 - minor changes

This commit is contained in:
slavisa-baeldung 2016-08-14 08:46:06 +02:00
parent 28fa846e48
commit 171cf1f3b4
2 changed files with 14 additions and 6 deletions

View File

@ -1,6 +1,8 @@
package com.baeldung.springintegration.controllers;
import javax.annotation.PostConstruct;
import javax.el.ELContextEvent;
import javax.el.ELContextListener;
import javax.el.LambdaExpression;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
@ -8,6 +10,7 @@ import javax.el.LambdaExpression;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import java.util.Collection;
import java.util.Random;
@ManagedBean(name = "ELBean")
@ -16,7 +19,6 @@ public class ELSampleBean {
private String firstName;
private String lastName;
private Collection<Integer> numberList;
private String pageDescription = "This page demos JSF EL Basics";
public static final String constantField = "THIS_IS_NOT_CHANGING_ANYTIME_SOON";
private int pageCounter;
@ -25,13 +27,19 @@ public class ELSampleBean {
@PostConstruct
public void init() {
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 static String getConstantField() {
public static String constantField() {
return constantField;
}
@ -39,8 +47,8 @@ public class ELSampleBean {
this.firstName = firstName;
}
public String multiplyValue(LambdaExpression expr){
String theResult = (String) expr.invoke(FacesContext.getCurrentInstance().getELContext(), pageCounter);
public Long multiplyValue(LambdaExpression expr) {
Long theResult = (Long) expr.invoke(FacesContext.getCurrentInstance().getELContext(), pageCounter);
return theResult;
}

View File

@ -11,7 +11,7 @@
<h:outputText id="valueOutput" value="#{(cube=(x->x*x*x);cube(4))}"/>
<br/>
<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/>
<h:outputLabel id="avgLabel" for="avg" value="Average of Integer List Value:"/>
<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:outputText id="lambdaPass" value="#{ELBean.multiplyValue(x->x*x*x)}"/>
<br/>
<c:set var='pageLevelNumberList' value="#{[1,2,3]}"/>
<h:outputLabel id="avgPageVarLabel" for="avgPageVar" value="Average of Page-Level Integer List Value:"/>
<h:outputText id="avgPageVar" value="#{pageLevelNumberList.stream().average().get()}"/>
<br/>
@ -29,7 +30,6 @@
</h:column>
</h:dataTable>
</h:panelGrid>
<c:set var='pageLevelNumberList' value="#{[1,2,3]}"/>
</h:body>
</html>