11package com .baeldung .springintegration .controllers ;
22
3- import java .util .Random ;
43import javax .annotation .PostConstruct ;
4+ import javax .el .ELContextEvent ;
5+ import javax .el .ELContextListener ;
6+ import javax .el .LambdaExpression ;
57import javax .faces .application .Application ;
68import javax .faces .application .FacesMessage ;
9+ import javax .el .LambdaExpression ;
710import javax .faces .bean .ManagedBean ;
811import javax .faces .bean .ViewScoped ;
9- import javax .faces .component .html .HtmlInputText ;
1012import javax .faces .context .FacesContext ;
13+ import java .util .Collection ;
14+ import java .util .Random ;
1115
1216@ ManagedBean (name = "ELBean" )
1317@ ViewScoped
@@ -16,22 +20,37 @@ public class ELSampleBean {
1620 private String firstName ;
1721 private String lastName ;
1822 private String pageDescription = "This page demos JSF EL Basics" ;
23+ public static final String constantField = "THIS_IS_NOT_CHANGING_ANYTIME_SOON" ;
1924 private int pageCounter ;
2025 private Random randomIntGen = new Random ();
2126
2227 @ PostConstruct
2328 public void init () {
2429 pageCounter = randomIntGen .nextInt ();
30+ FacesContext .getCurrentInstance ().getApplication ().addELContextListener (new ELContextListener () {
31+ @ Override
32+ public void contextCreated (ELContextEvent evt ) {
33+ evt .getELContext ().getImportHandler ().importClass ("com.baeldung.springintegration.controllers.ELSampleBean" );
34+ }
35+ });
2536 }
2637
2738 public void save () {
2839
2940 }
41+
42+ public static String constantField () {
43+ return constantField ;
44+ }
3045
3146 public void saveFirstName (String firstName ) {
3247 this .firstName = firstName ;
3348 }
3449
50+ public Long multiplyValue (LambdaExpression expr ) {
51+ Long theResult = (Long ) expr .invoke (FacesContext .getCurrentInstance ().getELContext (), pageCounter );
52+ return theResult ;
53+ }
3554
3655 public void saveByELEvaluation () {
3756 firstName = (String ) evaluateEL ("#{firstName.value}" , String .class );
0 commit comments