[英]Using spring:message to define form tag attribute in Spring web application
I'm developing a Java/Spring web application. 我正在开发一个Java / Spring Web应用程序。 The problem I'm currently facing is that I'd like to have message from message.resources shown as an attribute in an HTML.
我目前面临的问题是,我希望将message.resources中的消息显示为HTML中的属性。
<input type="submit" name="login" value="login" />
So instead of the hardcoded value "login" I need to the value of 因此,而不是硬编码值“登录”我需要的值
<spring:message code="general.submit" />
as the value attribute of that input tag. <spring:message code="general.submit" />
作为该输入标记的value属性。 As the pages are all xml, it's no option to nest tags like 由于页面都是xml,因此无法嵌套标签
<input type="submit" name="login" value="<spring:message code="general.submit" />" />
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.
当然,我可以读取Java控制器中的值并使用JSTL变量来显示值,但我认为它太过于hackish和复杂,特别是对于具有大量提交按钮的页面。 Is there some kind of elegant way of accomplishing what I want to do?
是否有某种优雅的方式来完成我想做的事情?
Use <spring:message>
to store the value in a var, then reference that var using EL, eg 使用
<spring:message>
将值存储在var中,然后使用EL引用var,例如
<spring:message code="general.submit" var="submitText"/>
<input type="submit" name="login" value="${submitText}" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.