Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using spring:message to define form tag attribute in Spring web application

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" />

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. 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" />" />

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?

like image 663
simon Avatar asked Oct 13 '09 13:10

simon


People also ask

How can use spring form tag in JSP?

To use Spring's form tags in our web application, we need to include the below directive at the top of the JSP page. This form tag library comes bundled in spring-webmvc. jar and the library descriptor is called spring-form. tld.

What is spring message tag?

The spring:message tag provides you with internationalization support using Spring's MessageSource concept. The MessageSource is an interface providing functionality for retrieving messages. It closely resembles JSTL's fmt:message -tag, however, the MessageSource classes can be integrated with the Spring context.

What is spring form commandName?

The commandName attribute is the most important attribute in the form tag, which specifies the model attribute name that contains a backing object and the properties of this object will be used to populate the generated form.


1 Answers

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}" />
like image 103
skaffman Avatar answered Oct 21 '22 04:10

skaffman