Problem with fmt tag

I am currently working on a spring project and I had to use fmt tags inside my JSPs. Actually fmt tags work fine for me and read the correct value from the messages.properties file.

eg:

 <fmt:message key="General.Settings"/> 

in the .properties file:

 General.Settings=Settings 

he reads it just fine.

Now the problem occurs when setting the fmt tag inside other JSTL tags.

For instance:

 <input name="commit" value= <fmt:message key="AllMessages.PostThisMessage"/> type="submit" onclick="return isEmpty();" /> 

Inside the .properties file:

 AllMessages.PostThisMessage=Post this message 

but it only displays the word "Message" instead of "Send this message"

and the same with all other fmt tags inside other JSTL tags.

any suggestions?

+4
source share
4 answers

Do not embed your tags, this is confusing and error prone. Better to do things like this:

 <fmt:message key="AllMessages.PostThisMessage" var="myMessage"/> <input name="commit" value="${myMessage}" type="submit" onclick="return isEmpty();" /> 

If you really used this syntax:

 value= <fmt:message key="AllMessages.PostThisMessage"/> 

Then it is a miracle that it worked in general, as it would create invalid HTML.

+17
source

You forgot the quotation marks for the value parameter:

<input name="commit" value="<fmt:message key="AllMessages.PostThisMessage"/>" type="submit" onclick="return isEmpty();" />

But, as already mentioned, nested tags are harder to read.

+1
source

Not sure if this is due to my version of the JST library, but I could not install var directly on <fmt:message /> . I had to create c: set for it to work:

 <c:set var="buttonEdit"> <fmt:message key="EDIT" bundle="${yourBundle}"/> </c:set> <input class="button edit" type="submit" title="your Title" value="${buttonEdit}" /> 

I am new to JSP, so hope this is good. ;-)

+1
source

Adding single quotes around the value attribute will do the trick.

<input name="commit" value='<fmt:message key="AllMessages.PostThisMessage"/>' type="submit" onclick="return isEmpty();" />

+1
source

Source: https://habr.com/ru/post/1334054/


All Articles