Nesting EL functions
Asked Answered
P

2

6

I am getting EL parsing exceptions when doing this in my JSP:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@page import="my.InternalConstants"%>

[...]

<c:set var="MYPREFIX"><%=InternalConstants.MYPREFIX%></c:set>

[...]

<c:forEach var="name" items="${data.names}" varStatus="status">
    <c:set var="reducedName" value="${fn:substring(name, fn:length(MYPREFIX), fn:length(name))}"/> <-- here is where the exception occurs

What am I doing wrong?

Thanks.

Update:

This is the exception:

view.jsp(86,94) --> JSPG0122E: Unable to parse EL function ${fn:substring(name, fn:length(MYPREFIX), fn:length(name)}).

at com.ibm.ws.jsp.translator.visitor.validator.ELValidator.validateElFunction(ELValidator.java:500)
at com.ibm.ws.jsp.translator.visitor.validator.ELValidator.validateELExpression(ELValidator.java:122)
at com.ibm.ws.jsp.translator.visitor.validator.ELValidator.validateELExpression(ELValidator.java:149)
at com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.validateCustomTagAttribute(ValidateVisitor.java:1752)
at com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.validateCustomTagAttributeValues(ValidateVisitor.java:1400)
at com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.visitCustomTagStart(ValidateVisitor.java:294)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:366)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:369)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:369)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:369)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:234)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.visit(JspVisitor.java:216)
at com.ibm.ws.jsp.translator.JspTranslator.processVisitors(JspTranslator.java:127)
Paramilitary answered 12/5, 2011 at 21:25 Comment(2)
Looks fine, just tested on Tomcat 7.0.12 and works fine. What exception exactly are you getting? Probably ${name} isn't a String at all.Shakeup
I added the exception to the original posting above.Paramilitary
H
1

If you have been using the WebSphere 8 your issue seems to be related with question:17744158

Harbinger answered 6/2, 2019 at 14:16 Comment(0)
E
-1

I have used you code with following way.Its working fine.

JSP file

<%@page import="com.Utils"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<c:set var="MYPREFIX"><%=Utils.MYPREFIX%></c:set>
<c:forEach var="name" items="${names}" varStatus="status">
    <c:set var="reducedName"
        value="${fn:substring(name, fn:length(MYPREFIX), fn:length(name))}" />
        ${reducedName}
</c:forEach>



Controller File


@WebServlet("/HomeController")
public class HomeController extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public HomeController() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");

        List<String> list = new ArrayList<>();
        list.add("Ahasdasdadas");
        list.add("Ah1213232");

        request.setAttribute("names", list);
        RequestDispatcher rd = request.getRequestDispatcher("one.jsp");
        rd.forward(request, response);
    }

}

Utils

package com;

public class Utils {
    public static String MYPREFIX = "AH";
}
Englut answered 6/1, 2019 at 5:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.