Expression Language in JSP not working [duplicate]

I’m quoting from an answer I provided before to the problem of EL not working: With other words, the EL expression doesn’t get evaluated? That can have one or more of the following causes: Application server in question doesn’t support JSP 2.0. The web.xml is not declared as Servlet 2.4 or higher. The @page is … Read more

Get specific element in a list or array using EL

You can use the brace notation [] wherein you specify the (zero-based) index of the element you’d like to retrieve. <p>This is the 3rd item of the list: #{bean.list[2]}</p> This syntax does basically the same as bean.getList().get(2). This is equivalent for arrays. <p>This is the 3rd item of the array: #{bean.array[2]}</p> This syntax does basically … Read more

Accessing a JSTL / EL variable inside a Scriptlet

JSTL variables are actually attributes, and by default are scoped at the page context level. As a result, if you need to access a JSTL variable value in a scriptlet, you can do so by calling the getAttribute() method on the appropriately scoped object (usually pageContext and request). resp = resp + (String)pageContext.getAttribute(“test”); Full code … Read more

instanceof check in EL expression language

You could compare Class#getName() or, maybe better, Class#getSimpleName() to a String. <h:link rendered=”#{model[‘class’].simpleName eq ‘ClassA’}”> #{errorMessage1} </h:link> <h:link rendered=”#{model[‘class’].simpleName eq ‘ClassB’}”> #{errorMessage2} </h:link> Note the importance of specifying Object#getClass() with brace notation [‘class’] because class is a reserved Java literal which would otherwise throw an EL exception in EL 2.2+. The type safe alternative is … Read more

How to output ${expression} in Freemarker without it being interpreted?

This should print ${person.name}: ${r”${person.name}”} From the freemarker docs A special kind of string literals is the raw string literals. In raw string literals, backslash and ${ have no special meaning, they are considered as plain characters. To indicate that a string literal is a raw string literal, you have to put an r directly … Read more

Concatenating strings within EL expression defined in an attribute of a facelets tag

It is possible to concatenate Strings in EL using the java.lang.String.concat(String) method. Thus your code could look like: <h:outputText value=”#{cc.attrs.appreciatedByCurrentUser ? (”.concat(cc.attrs.count).concat(‘&lt;br/&gt;’).concat(cc.attrs.count-1)) : (”.concat((cc.attrs.count+1)).concat(‘&lt;br/&gt;’).concat(cc.attrs.count))}” escape=”false” /> In this particular case however I would go with one of the options that Mr BalusC had suggested because the code above doesn’t look quite elegant. In some cases … Read more

What does this expression language ${pageContext.request.contextPath} exactly do in JSP EL?

The pageContext is an implicit object available in JSPs. The EL documentation says The context for the JSP page. Provides access to various objects including: servletContext: … session: … request: … response: … Thus this expression will get the current HttpServletRequest object and get the context path for the current request and append /JSPAddress.jsp to … Read more

Mixing JSF EL in a JavaScript file

Five ways: Declare it as global variable in the parent JSF page. <script type=”text/javascript” src=”https://stackoverflow.com/questions/2547814/script.js”></script> <script type=”text/javascript”> var messages = []; <ui:repeat value=”#{bean.messages}” var=”message”> messages[‘#{message.key}’] = ‘#{message.value}’; </ui:repeat> </script> Or, if it’s in JSON format already. <script type=”text/javascript” src=”https://stackoverflow.com/questions/2547814/script.js”></script> <script type=”text/javascript”>var messages = #{bean.messagesAsJson};</script> Put the whole <script> in a XHTML file and use ui:include … Read more

The representation of if-elseif-else in EL using JSF

You can use EL if you want to work as IF: <h:outputLabel value=”#{row==10? ’10’ : ’15’}”/> Changing styles or classes: style=”#{test eq testMB.test? ‘font-weight:bold’ : ‘font-weight:normal’}” class=”#{test eq testMB.test? ‘divRred’ : ‘divGreen’}”

Ternary operator in JSTL/EL

I tested the following page in Tomcat 5.59, JSP 2.0 and JSTL 1.1. It ran without any errors. <%@taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c”%> <c:set var=”value” scope=”request” value=”someValue”/> <c:out default=”None” escapeXml=”true” value=”${not empty value ? value : ‘None’}” /> <c:out default=”None” escapeXml=”true” value=”${empty value ? ‘None’ : value}” /> <c:set var=”value” scope=”request” value=”” /> <br/> <c:out default=”None” escapeXml=”true” … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)