Book Image

Spring MVC Beginner's Guide

By : Amuthan Ganeshan
Book Image

Spring MVC Beginner's Guide

By: Amuthan Ganeshan

Overview of this book

Table of Contents (19 chapters)
Spring MVC Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – externalizing messages


Let's see how to externalize the label texts in our addProduct.jsp file:

  1. We open our addProduct.jsp file and add the following taglib reference at the top:

    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
  2. Change the product ID <label> tag's value as <spring:message code="addProdcut.form.productId.label"/>, as shown as follows:

    <label class="control-label col-lg-2 col-lg-2" for="productId"> <spring:message code=  "addProduct.form.productId.label"/> </label>
  3. We create a file called messages.properties under /src/main/resources in our project and add the following line in it:

    addProduct.form.productId.label = New Product ID
  4. Now, we open our web application context configuration file DispatcherServlet-context.xml from src/main/webapp/WEB-INF/spring/webcontext/ and add the following bean definition in it:

    <bean id= "messageSource" class="org.springframework.context.support.ResourceBundleMessageSource...