使用spring:message在Spring Web应用程序中定义表单标记属性 [英] Using spring:message to define form tag attribute in Spring web application
问题描述
我正在开发一个Java / Spring Web应用程序。我目前面临的问题是,我希望将message.resources中的消息显示为HTML中的属性。
I'm developing a Java/Spring web application. The problem I'm currently facing is that I'd like to have message from message.resources shown as an attribute in an HTML.
<input type="submit" name="login" value="login" />
因此,不需要硬编码值login,我需要
So instead of the hardcoded value "login" I need to the value of
< spring:message code =general.submit/>
作为该输入标记的value属性。由于页面都是xml,因此无法嵌套标签,例如
<spring:message code="general.submit" />
as the value attribute of that input tag. As the pages are all xml, it's no option to nest tags like
<input type="submit" name="login" value="<spring:message code="general.submit" />" />
因为它没有编译。当然,我可以读取Java控制器中的值并使用JSTL变量来显示值,但我认为它太过于hackish和复杂,特别是对于具有大量提交按钮的页面。是否有某种优雅的方式来完成我想做的事情?
as it does not compile. I could, of course, read the value in the Java controller and use a JSTL variable to display the value, but I think it would be too hackish and complicated, especially for pages with large amount of submit buttons. Is there some kind of elegant way of accomplishing what I want to do?
推荐答案
使用< spring :message>
将值存储在var中,然后使用EL引用该var,例如
Use <spring:message>
to store the value in a var, then reference that var using EL, e.g.
<spring:message code="general.submit" var="submitText"/>
<input type="submit" name="login" value="${submitText}" />
这篇关于使用spring:message在Spring Web应用程序中定义表单标记属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!