This is a really confusing error, as it crops up in some of the webpages that I’m creating, but not in others, although syntactically the elements are identical.
For example, this doesn’t show up:
<main:uiInputBox
onDarkBG="${hasDarkBG}"
name="questionTitle1"
onblur="pollUpdateQuestion(false, false, true, this);"
defaultValue="<${field['POLL_FIELD_ENTER_QUESTION']}>"
styleWidth="280px">
</main:uiInputBox>
Where the tag ${field['POLL_FIELD_ENTER_QUESTION']} should return the string “enter question”. What I don’t understand is that the tag returns the string normally in the JSP file, but now when it’s in the HTML descriptor.
Another error is that in javascript if I have a function like this:
It prints out the literal string "${field['POLL_FIELD_CHOICE']}", and not the element that it’s representing. Ex:
template.find('h2').text('${field["POLL_FIELD_CHOICE"]} ');
What am I doing wrong here and how can I fix it?
As to the first problem of EL not being resolved in a custom tag, that’s not JSTL (it are those
<c:xxx>tags). That’s EL (those${}things).You seem to be using EL in a custom tag. The
<main:xxx>does not belong to any JSP standard tag library (look, that’s what JSTL stands for). To get EL in custom tags to work as well, you need to ensure of the following:The
web.xmlmust be declared as at least Servlet 2.4, which implies JSP 2.0 where this feature is supported.The
.tldfile of the<main:xxx>taglib must be declared as at least JSP 2.0, where the<rtexprvalue>attribute is supported.The
defaultValueattribute in the.tldfile of the<main:uiInputBox>must be marked with<rtexprvalue>true</rtexprvalue>to enable the support runtime expressions (the EL, those${}things).As to the second problem of EL not being resolved in a JavaScript file, well, the explanation is pretty simple: EL in template text like that runs in JSP (2.0 or newer) files with
.jspextension only. There are several ways to get it to work anyway:Rename
.jsto.jspand add the following line to top of the page (best solution):Put that piece of JS in an inline
<script>of the JSP page instead (not recommend since that’s generally seen as a poor practice).Map
*.json the JSP servlet inweb.xml(not recommended, it tight-couples your webapp to the servletcontainer’s specific JspServlet which may not necessarily be mapped on the servlet name ofjsp).