user6319790 user6319790 - 5 months ago 14
HTML Question

Set <fmt:message> tag inside placeholder

I have This html code:

<td style="padding:1%; " width="80%"><form:textarea name="reference" path="" placeholder="insert_word" width="100%" /></td>


I want to get the placeholder word from language.properties file,
I have file langueage.properties:

insert_word=add your word here!


How can I do that with using
<fmt:message>
tag;
I already add this lines at the begin of my html code:

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<fmt:setBundle basename="language" />


When I put the
<fmt:message>
tag inside the "value", it's working fine,
but inside the placeholder I get some error:

<td style="padding:1%; " width="80%"><form:textarea name="reference" path="" placeholder=<fmt:message key="insert_word" /> width="100%" /></td>


The error:

org.apache.jasper.JasperException: /WEB-INF/views/ContactForm.jsp (line: 188, column: 98) quote symbol expected
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:89)
org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:224)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:162)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:153)
org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1229)
.........


If I add some qoute (" "/' ') I get this line inside:

"<fmt:message key="insert_word" />"


Not the translation of insert_word.

What can't I do?

Answer

You may not use a JSP tag inside an attribute of another JSP tag.

But you can use variables:

<%-- translate the message key and store it in a variable --%>
<fmt:message key="insert_word" var="insertTranslation" />

<%-- use it as placeholder of textarea --%>
<form:textarea  name="reference"  path="" placeholder="${insertTranslation}" width="100%" />