When I use the tag:
<c:if test="${comment.mediaObject.getClass().name == 'entities.persistent.Photo'}">
inside a JavaScript function in a jsp page I get the following error:
Syntax error on token "if", ( expected after this token
Under html code in .jsp page this works great but not when under JavaScript functions.
What I am trying to do is passing a list of Photos in JavaScript to then pass them to the initialize function that prints them in Google maps. But for that I need to know whether the mediaObjects is of type photo or else I don't do anything.
EDIT:
replacing getClass() with class actually stops the sintax error, although i get the following execution error:
message /MapRoutes.jsp (line: 113, column: 4) "${comment.mediaObject.class.name == 'entities.persistent.Photo'}" contains invalid expression(s): javax.el.ELException: Failed to parse the expression [${comment.mediaObject.class.name == 'entities.persistent.Photo'}]
Change comment.mediaObject.getClass().name
to comment.mediaObject.class.name
.
When your JSP is compiled it will translate to comment.getMediaObject().getClass().getName()
.
The fact that it's inside a JavaScript block has nothing to do with the error.
EDIT to address the invalid expression:
A little searching shows that certain containers and/or EL specs require the following syntax due to the fact that class
is a reserved keyword.
comment.mediaObject['class'].name
A final option is to add the following startup paramater. I'd recommend only doing this if nothing else works since it makes your application less portable.
-Dorg.apache.el.parser.SKIP_IDENTIFIER_CHECK=true
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.