0

I have HTML Tag in my JSP page which I need to localize. I have mentioned it below

<form:input path="firstName" cssStyle="width:155px;" description=<fmt:message
key="firstName" /> mandatory="true"
title="Enter First Name as in Corp. Directory"
validation="mavenname" maxlength="50" />

While I compile this I get the following error.

Sep 17, 2012 2:12:51 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet dispatcher threw exception
org.apache.jasper.JasperException: /WEB-INF/jsp/resource/GeneralDetails.jsp(72,23) quote symbol expected
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
    at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:198)
    at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:148)
    at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1207)
    at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1421)
    at org.apache.jasper.compiler.Parser.parseBody(Parser.java:1633)
    at org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:977)
    at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1245)
    at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1421)
    at org.apache.jasper.compiler.Parser.parseBody(Parser.java:1633)
    at org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:977)
    at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1245)
    at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1421)
    at org.apache.jasper.compiler.Parser.parse(Parser.java:130)
    at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255)
    at org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:185)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:347)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
    at org.apache.jsp.WEB_002dINF.jsp.resource.ResComponent_jsp._jspService(ResComponent_jsp.java:2090)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:574)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

Could you please let me know how to embed the <fmt:messagein the HTML tag's description attribute ? And also guide me if I am doing anything wrong. Since the tag is working as a standalone tag but throws an error when put into some HTML attribute as mentioned above.

NOTE: I am using Spring3,Java 1.6 and the above page is a JSP. Server is Tomcat 6.02

helios
  • 13,574
  • 2
  • 45
  • 55
Shiv Kumar Ganesh
  • 3,799
  • 10
  • 46
  • 85

3 Answers3

4

I suggest using spring:message tag:

<spring:message code="firstName" var="firstName_label" />
<form:input description="${firstName_label}" />
nobeh
  • 9,784
  • 10
  • 49
  • 66
  • Since we are having more than 70 fields each page its really cumbersome to use it for each field.Please suggest something that would be like single tag :) . I would appreciate if you can show me the reuse of the fmt Tag itself. – Shiv Kumar Ganesh Sep 17 '12 at 09:54
  • Could you pls help in getting this thing fixed. Would be great help :) – Shiv Kumar Ganesh Sep 17 '12 at 10:04
  • @nobeh is right. You can put a JSP tag inside an HTML tag because the first will be rendered at server and the second will receive the rendered value. But I don't think you can nest a JSP tag into another. This answer suggest a correct format for your JSP page. If it's cumbersome is because of 70 fields, not because of 2 tags. Another approach would be to make your own JSP tag to genrate correct code, or to create a small JSP fragment and use it with params like "code of message", "name of input" and so on. – helios Sep 17 '12 at 11:06
  • @helios very well said helios. This could be one of the probable way but could you pls point me to some tutorial where I can make my own JSP tags to handel such a situation :) ?? – Shiv Kumar Ganesh Sep 17 '12 at 11:50
  • If you really do not want to use Spring tags, maybe an idea such as [this one](http://stackoverflow.com/a/3174422/248082) can help you better to replace with `fmt:message`. – nobeh Sep 17 '12 at 12:09
  • @ShivKumarGanesh: I've googled and found an informal tutorial (http://viralpatel.net/blogs/tutorial-create-custom-tag-library-taglib-in-jsp/). Seems nice because it's short and to the point (declare TLD, create class, program the doStart/endTag). But I don't have a lot of experience on it, just modified a taglib once :) – helios Sep 17 '12 at 12:58
2

Try adding quotes around the tag:

description="<fmt:message key='firstName' />"

or alternatively copying the value to a variable and referencing it via JSTL:

<c:set var="descLoc">
    <fmt:message key="firstName" />
</c:set>

description="${descLoc}"

Caveat: code not tested, so may have typos or errors.

nickdos
  • 8,348
  • 5
  • 30
  • 47
0

You havenot read the exception properly. It specifically tells you the problem. You have not put the tag in the double quots. Try to put double quots in description.

It should solve your problem. Cheers.

Japan Trivedi
  • 4,445
  • 2
  • 23
  • 44