170 Chapter 13. Web Applications Tutorial
import com.arsdigita.dispatcher.Dispatcher;
import com.arsdigita.globalization.GlobalizedMessage;
public class HelloWorldDispatcher extends Dispatcher {
// do some stuff, set up URL to method map, etc.
private Page buildHelloWorldPage() {
Label message = new Label(new GlobalizedMessage(
"hello_world",
"com.arsdigita.helloworld.HelloWorldResources"
));
Page page = new Page(message);
page.add(message);
page.lock();
return page;
}
}
When the Page is served, Bebop will automatically call the localize(java.util.Locale)
method of each of the GlobalizedMessageson the Page with the Locale of the current request as
an argument. This will allow the pages to be displayed to each user in his or her preferred language.
13.6. Localizing Stylesheets
WAF uses XSL stylesheets to lay out XML content that is usually produced by Bebop, but which
could be produced by other sources. For more information, see Section 5.4 Bebop - Reusable Web UI
Components. These stylesheets can be associated with Locales. This allows a developer to lay out a
Page differently based on Locale.
Stylesheets can also contain static text. This text can be translated in another stylesheet that is associ-
ated with the appropriate Locale.
The system selects the stylesheet to use for each request by matching it to the Locale of the current
request. It performs matching in the same way that ResourceBundles do, by using the Locale
hierarchy.
13.7. Sending Mail Messages
Sending Plain Text Messages
Plain text messages can be sent using a static convenience method:
Mail.send(to, from, subject, body);
You can use the standard format for email addresses, for example, person@mydomain.net,
Person person@mydomain.name, and Person LastName person@mydomain.net. Mul-
tiple recipients can be speciļ¬ed in a single string separated by commas.
To access the complete set of header attributes, create a Mail object, invoke the various set
methods, and call send:
Mail msg = new Mail();
msg.setTo("User1 user1@example.com, User2 user2@example.com");
msg.setFrom("Me me@example.com");
msg.setReplyTo("User3 user3@example.com");
msg.setCc("User4 user4@example.com");
msg.setBcc("User5 user5@example.com");
msg.setSubject("this is the subject");
msg.setBody("this is the body");