Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An issue with fmt tag

I am currently working on a spring project, and I had to use fmt tags inside my JSPs. In fact fmt tags are working fine for me, and its reading the right value from messages.properties file.

for example:

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

in the .properties file:

General.Settings=Settings

it reads it just perfect.

Now, the issue exists when puting the fmt tag inside another JSTL tags.

For example:

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

Inside .properties file:

AllMessages.PostThisMessage=Post this message

but it displays only the word "Post" instead of "Post this message"

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

any suggestions?

like image 853
Ali Taha Ali Mahboub Avatar asked Dec 01 '22 09:12

Ali Taha Ali Mahboub


1 Answers

Don't nest your tags like that, it's confusing and error-prone. Better to do this sort of thing:

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

If you really were using this syntax:

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

Then it's a marvel it worked at all, since that would generate invalid HTML.

like image 71
skaffman Avatar answered Dec 04 '22 06:12

skaffman