01: /*
02: * $Id: Home.java 461941 2006-08-24 22:26:35Z frankbille $ $Revision: 461941 $
03: * $Date: 2006-08-25 00:26:35 +0200 (Fri, 25 Aug 2006) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.examples.pub;
19:
20: import java.util.Locale;
21:
22: import wicket.PageParameters;
23: import wicket.examples.WicketExamplePage;
24: import wicket.markup.html.basic.Label;
25: import wicket.markup.html.image.Image;
26: import wicket.markup.html.link.Link;
27: import wicket.model.Model;
28: import wicket.model.StringResourceModel;
29: import wicket.util.value.ValueMap;
30:
31: /**
32: * Demonstrates localization.
33: *
34: * @author Jonathan Locke
35: * @author Eelco Hillenius
36: */
37: public final class Home extends WicketExamplePage {
38: /**
39: * Constructor
40: *
41: * @param parameters
42: * Page parameters (ignored since this is the home page)
43: */
44: public Home(final PageParameters parameters) {
45: add(new Image("beer"));
46:
47: // create a dummy object to serve as our substitution model
48: ValueMap map = new ValueMap();
49: map.put("user", "Jonathan");
50:
51: // Here, we create a model that knows how to get localized strings.
52: // It uses the page's resource (Home_cc_LC.properties) and gets the
53: // text with resource key 'salution'. For the US, this is:
54: // salutation=${user}, dude!
55: // variable ${user} will be regconized as a property variable, and will
56: // be substituted with the given model (the wrapped map). Hence,
57: // ${user} will be replaced by map.get('user'), which is 'Jonathan'.
58: StringResourceModel labelModel = new StringResourceModel(
59: "salutation", this , new Model(map));
60:
61: // Add the label with the dynamic model
62: add(new Label("salutation", labelModel));
63:
64: // Add a couple of links to be able to play around with the session
65: // locale
66: add(new Link("goCanadian") {
67: public void onClick() {
68: getSession().setLocale(Locale.CANADA);
69: }
70: });
71: add(new Link("goUS") {
72: public void onClick() {
73: getSession().setLocale(Locale.US);
74: }
75: });
76: add(new Link("goDutch") {
77: public void onClick() {
78: getSession().setLocale(new Locale("nl", "NL"));
79: }
80: });
81: add(new Link("goGerman") {
82: public void onClick() {
83: getSession().setLocale(new Locale("de", "DE"));
84: }
85: });
86: add(new Link("goChinese") {
87: public void onClick() {
88: getSession().setLocale(new Locale("zh", "CN"));
89: }
90: });
91: add(new Link("goDanish") {
92: public void onClick() {
93: getSession().setLocale(new Locale("da", "DK"));
94: }
95: });
96: }
97: }
|