25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10 ■ Showing Your <strong>Spring</strong> Application on the Web<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

select d.documentId, d.name, d.location, d.description as doc_desc,<br />

d.typeId, d.created, d.modified,<br />

t.name as type_name, t.description as type_desc, t.extension from<br />

documents d<br />

join types t<br />

on d.typeId = t.typeId<br />

<br />

<br />

<br />

<br />

In Listing 10-8, you add an interceptor the LocaleChangeInterceptor. It will help you with a parameter<br />

named lang to change the locale. (If omitted, the default parameter will be locale.) Next, you have the<br />

ReloadableResourceBundleMessageSource class, which helps you find the path where your bundle message<br />

will be. In your case, WEB-INF/i18n/ is the path and messages is the name of the bundle. Also, you are defining a<br />

CookieLocaleResolver that will help you to save the state of your locale selected during your session.<br />

After modifying the XML file, you need to add the messages.properties file with its translations. In Chapter 6, I talked<br />

about using resource files. In this example, you will be using Spanish. You are going to create three files, one of which<br />

will be the default: messages.properties, messages_en.properties (for English), and messages_es.properties<br />

(for Spanish). Listing 10-9, 10-10, and 10-11 contain the messages bundles.<br />

Listing 10-9. WEB-INF/i18n/messages.properties<br />

main.title=Welcome to My Documents<br />

search.subtitle=.:: My Documents - Search ::.<br />

search.name=Name:<br />

search.type=Type:<br />

search.location=Location:<br />

Listing 10-9 shows the default message.properties file. Now let’s take a look at the English properties.<br />

See Listing 10-10.<br />

Listing 10-10. WEB-INF/i18n/messages_en.properties<br />

main.title=Welcome to My Documents<br />

search.subtitle=.:: My Documents - Search ::.<br />

search.name=Name:<br />

search.type=Type:<br />

search.location=Location:<br />

142

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!