开发者

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?


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.


You forgot the quotes 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.


Not sure if it's because of my version of the JST Library, but I couldn't set the var directly on the <fmt:message />. I had to create a 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'm new to JSP so I hope that's good. ;-)


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();" />

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜