user6319790 user6319790 - 1 year ago 161
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 file,
I have file

insert_word=add your word here!

How can I do that with using
I already add this lines at the begin of my html code:

<%@ taglib uri="" prefix="fmt" %>

<fmt:setBundle basename="language" />

When I put the
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

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 Source

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%" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download