Merge branch 'pr/582-tayo-jsf-3'
This commit is contained in:
commit
b7c563d65d
@ -27,7 +27,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>el-api</artifactId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
<version>${javax.el.version}</version>
|
||||
</dependency>
|
||||
|
||||
@ -126,8 +126,8 @@
|
||||
<org.springframework.version>4.2.5.RELEASE</org.springframework.version>
|
||||
|
||||
<!-- JSF -->
|
||||
<com.sun.faces.version>2.1.7</com.sun.faces.version>
|
||||
<javax.el.version>2.2</javax.el.version>
|
||||
<com.sun.faces.version>2.2.13</com.sun.faces.version>
|
||||
<javax.el.version>3.0.0</javax.el.version>
|
||||
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.13</org.slf4j.version>
|
||||
|
@ -1,13 +1,17 @@
|
||||
package com.baeldung.springintegration.controllers;
|
||||
|
||||
import java.util.Random;
|
||||
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;
|
||||
import javax.el.LambdaExpression;
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.ViewScoped;
|
||||
import javax.faces.component.html.HtmlInputText;
|
||||
import javax.faces.context.FacesContext;
|
||||
import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
@ManagedBean(name = "ELBean")
|
||||
@ViewScoped
|
||||
@ -16,22 +20,37 @@ public class ELSampleBean {
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String pageDescription = "This page demos JSF EL Basics";
|
||||
public static final String constantField = "THIS_IS_NOT_CHANGING_ANYTIME_SOON";
|
||||
private int pageCounter;
|
||||
private Random randomIntGen = new Random();
|
||||
|
||||
@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 constantField() {
|
||||
return constantField;
|
||||
}
|
||||
|
||||
public void saveFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public Long multiplyValue(LambdaExpression expr) {
|
||||
Long theResult = (Long) expr.invoke(FacesContext.getCurrentInstance().getELContext(), pageCounter);
|
||||
return theResult;
|
||||
}
|
||||
|
||||
public void saveByELEvaluation() {
|
||||
firstName = (String) evaluateEL("#{firstName.value}", String.class);
|
||||
|
35
jsf/src/main/webapp/el3_intro.xhtml
Normal file
35
jsf/src/main/webapp/el3_intro.xhtml
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version='1.0' encoding='UTF-8' ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:h="http://java.sun.com/jsf/html"
|
||||
xmlns:c="http://java.sun.com/jsp/jstl/core">
|
||||
<h:head>
|
||||
<title>Baeldung | Expression Language 3.0</title>
|
||||
</h:head>
|
||||
<h:body>
|
||||
<h:outputLabel id="valueLabel" for="valueOutput" value="Composite Lambda Evaluation:"/>
|
||||
<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="#{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()}"/>
|
||||
<br/>
|
||||
<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/>
|
||||
<h:panelGrid title="Data Structures" border="3" >
|
||||
<h:dataTable var="streamResult" value="#{pageLevelNumberList.stream().filter(x-> x>1).toList()}">
|
||||
<h:column id="nameCol">
|
||||
<h:outputText id="name" value="#{streamResult}"/>
|
||||
</h:column>
|
||||
</h:dataTable>
|
||||
</h:panelGrid>
|
||||
</h:body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user