I’m trying to convert the following scriptlet code to EL. I tried the following (below), but can’t get it working. getValue() is a method off of ConfigFactory that returns a string:
In a listener, I set the configFactory as event.getServletContext().setAttribute("ConfigFactory", new ConfigFactory());
In my scriptlet code there is: (and it works fine)
<%
ConfigFactory cf = (ConfigFactory) application.getAttribute("ConfigFactory");
%>
Value from scriptlet= <%=cf.getValue()%> <br/>
EL gives me trouble:
<c:set var="cf" value="${initParam['ConfigFactory']}"/>
<c:out value="${cf.getValue}"/> <!-- try # 1 -->
<c:out value="${cf.value}"/> <!-- try # 2 -->
This line
does basically the same as
You don’t want this. Get rid of that line. In EL, you have implicitly direct access to all request, session and application attributes by just its name. The following
does basically the same as
The
PageContext#findAttribute()tests respectivelyPageContext#getAttribute(),HttpServletRequest#getAttribute(),HttpSession#getAttribute()and finallyServletContext#getAttribute()until the first non-null value is been found. This is more what you want.You can finally access the
getValue()method on it the usual EL way:Not related to the problem, but you’d normally give instance identifiers a name starting with lowercase. You also don’t do
ConfigFactory ConfigFactory = new ConfigFactory();, right? 🙂