el

Why not JSF pages are precompiled (atleast partially) but instead parsed, evaluated each time view is built?

喜你入骨 提交于 2019-12-17 17:59:41
问题 I don't know whether it is true or not but from what I've read, I believe, JSF EL & xhtml pages are not pre-compiled & just used when needed but instead they are parsed, evaluated, compiled each time the view is built. I fail to understand why this is done so! Why not just parse & compile it just once, ok atleast partially , rendering of some components may depend on a dynamically fetched variable so they may be rendered later but why delay that for all the components on page? Whatever

How to obtain request / session / servletcontext attribute in JSP using EL?

眉间皱痕 提交于 2019-12-17 17:58:07
问题 I know this isn't hard, but I'm not having any luck. I want to make fooList from a Servlet available in a JSP. So in the Servlet I have: request.setAttribute("list", fooList); RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/myJsp.jsp"); dispatcher.forward(request, response); Then in the JSP, I want: <c:forEach var="post" items="${SOME_EL_HERE}"> <!-- stuff --> </c:forEach> Where SOME_EL_HERE is an expression that retrieves the attribute that I have set on the request

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

让人想犯罪 __ 提交于 2019-12-17 17:50:11
问题 I need to write an EL expression for an attribute which goes something like this: #{cc.attrs.appreciatedByCurrentUser ? (cc.attrs.count +'<br/>'+ (cc.attrs.count-1)) : ((cc.attrs.count+1) +'<br/>'+ cc.attrs.count)} Now the problem is that this gives an error as strings cannot be concatenated, the way I am doing it. So how can I rectify this? I'm using JSF 2.0 with facelets. EDIT : I'm resolving the issue using the following inline javascript <script type="text/javascript"> var count=#{cc

EL any function to get absolute value of a number?

旧城冷巷雨未停 提交于 2019-12-17 17:05:10
问题 I know the ugly way a>0 ? a : -a but this is very annoyng when a is a relatively long expression. OBJ1["x"]-someVar>0 ? OBJ1["x"]-someVar : -(OBJ1["x"]-someVar) Is there any nicer way of doing it? 回答1: For plain jsp, you can create a custom EL function which delegates to Math#abs(int). If you first just create a /WEB-INF/functions.tld file which look like follows: <?xml version="1.0" encoding="UTF-8" ?> <taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001

JSP Expression Language get parameter

纵饮孤独 提交于 2019-12-17 16:44:35
问题 I am trying to get a String parameter "username" from the request with Expression Language . I've done some research, but couldn't find a way to do so, I would like something similar to ${pageContext.request.parameter.username} How get a specific request parameter, using only expression language? 回答1: If get an attribute from 'session', try this ${username}. If get an parameter from 'request', try this ${param.username}. 回答2: The syntax to get the attributes from session would be, $

JSF 2: how to pass an action including an argument to be invoked to a Facelets sub view (using ui:include and ui:param)?

自作多情 提交于 2019-12-17 10:57:32
问题 This is basically an extension to this answer. I am trying to get an argument into a method/action call (for a delete button in a list/data table). Client: <ui:include src="..."> <ui:param name="acceptButtonBean" value="#{repoHome}" /> <ui:param name="acceptButtonAction" value="removeIndividualDocument(#{doc.id})" /> </ui:include> Sub view: <h:commandButton value="Continue" action="#{acceptButtonBean[acceptButtonAction]}" /> ... </h:commandButton> However, JSF fails with an exception saying:

instanceof check in EL expression language

删除回忆录丶 提交于 2019-12-17 10:47:27
问题 Is there a way to perform an instanceof check in EL? E.g. <h:link rendered="#{model instanceof ClassA}"> #{errorMessage1} </h:link> <h:link rendered="#{model instanceof ClassB}"> #{errorMessage2} </h:link> 回答1: 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

JSP: EL expression is not evaluated [duplicate]

别来无恙 提交于 2019-12-17 10:25:33
问题 This question already has answers here : EL expressions not evaluated in JSP (2 answers) Closed 4 years ago . I have a JSP page running on Tomcat 5.5. I have the following code: <c:forEach var="i" begin="1" end="10" step="1"> <c:out value="${i}" /> <br /> </c:forEach> The output I am getting is: ${i} ${i} ${i} ${i} ${i} ${i} ${i} ${i} ${i} ${i} I cant work out why the forEach loop is working but the output is not working. Any help any one could give would be great. 回答1: I know it's supposed

Use EL ${XY} directly in scriptlet <% XY %>

独自空忆成欢 提交于 2019-12-17 10:03:33
问题 In my project I've to asign a variable every time the JSP is being opened. I tried it with scriptlets <% %> in JSP and EL ${} which gives the variable back. But it seems not working. <% String korrekteAntwort=${frage.korrekteAntwort};%> <%session.setAttribute("korrekteAntwort", korrekteAntwort);%> There is an error after korrekteAntwort=${} , Isn't it possible to asign directly an variable from EL in a scriptlet? 回答1: You're mixing scriptlets and EL and expecting that they run "in sync". That

JSTL/JSP EL (Expression Language) in a non JSP (standalone) context

倾然丶 夕夏残阳落幕 提交于 2019-12-17 09:31:47
问题 Can anyone recommend a framework for templating/formatting messages in a standalone application along the lines of the JSP EL (Expression Language)? I would expect to be able to instantiate a an object of some sort, give it a template along the lines of Dear ${customer.firstName}. You order will be dispatched on ${order.estimatedDispatchDate} provide it with a context which would include a value dictionary of parameter objects (in this case an object of type Customer with a name 'customer',