<img src="//bat.bing.com/action/0?ti=5129185&amp;Ver=2" height="0" width="0" style="display: none; visibility: hidden;">

Custom Spring MVC - multilingual IBM WCM

A typical website implemented through IBM WCM may have multiple HTML forms for allowing users to contact the site administrators for various purposes, such as contacting the company or sending other custom requests such as feedback and complaints.

The same website when translated into multiple languages needs to be able to provide the same functionality but in different languages for different locales. The solution discussed here provides a custom functionality for displaying a form and sending an email with the user's request through a Java implementation based on the Spring MVC framework. The implementation is deployed onto the IBM WebSphere Application Server as a web application (EAR file) and referenced in IBM WCM presentation templates.

Fig 1: Spring MVC framework

Each HTML form available on the website is rendered through a JSP. This is the view in the Spring MVC framework as defined in the spring-servlet.xml:

The JSP utilizes the Spring form (<form:form>) to bind the values to/from Spring's form tags.

When the request is submitted, the url that the jsp is attempting to access is intercepted by the DispatcherServlet. The DispatcherServlet finds the Handler Mappings for this url, provided in the web.xml and dispatches the request to the appropriate Controller.

Each Controller represents a form for a single purpose, for e.g. a ContactUsController, SubscribeController or a FeedbackController. Inside the controller is a service layer that transforms the input (Form object) into a domain object which is used to construct the corresponding email.

The locale for which an email is to be sent is extracted from the URL of the contact-us page. A
 typical wcm page with a contact us form has the following url format: www.example.com/wps/wcm/connect/library_name/contact

The “library_name” in the URL provides a way to look-up the locale for which the email should be sent. The locale mapping is constructed through an enumeration which maps the library names to the locales.

The information that is to be sent in the email is stored in multiple properties file. Each property file contains information in the language for a specific locale. Each property file is mapped to a particular country in an xml configuration file, for example the properties files for China and France are defined as follows:

The property file contains the information in the translated language for each corresponding country, for e.g. a property file for Japan would contain the following information:

These property files are declared in the ContactUsServiceImpl (the service layer in the Controller):

Once the email properties from the properties file is read, the email is sent for the corresponding form type using JavaMailSender:

Upon success/failure, the controller resolves the appropriate view that is sent as output for the user. This can be another wcm page with a thank-you note or a custom JSP, the re-direction can be done through a javascript.