Wicket で
Page#getString(String key)
で
Page間共通で
環境情報
java
- 1.8
java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
- 1.8
wicket
- 7.3.0
<dependency> <groupId>org.apache.wicket</groupId> <artifactId>wicket-core</artifactId> <version>7.3.0</version> </dependency>
- 7.3.0
参考サイト
プロパティファイルの 配置先と 読み込みの 優先順位
ドキュメントを
ストラテジーパターンを
以下、
1. ComponentStringResourceLoader
FooPage.properties
, FooPanel.properties
のように
プロパティファイルを
2. PackageStringResourceLoader
パッケージ単位にwicket-package.properties
をwicket-package.properties
は
Migration to Wicket 6.0 - Apache Wicket - Apache Software Foundation 確かにpackage.properties
では
3. ClassStringResourceLoader
サーチ対象に
デフォルトの
デフォルトと
下記にResourceSettings.java
の
デフォルトで
4. ValidatorStringResourceLoader
Validator
クラスのFooValidator.properties
を
[4]番目なので、
5. InitializerStringResourceLoader
Application
のInitializer
にFooInitializer.properties
を
そもそも
逆に、
以下、
ResourceSettings.java
コンストラクター記述の
確かに、add
されています。
- ResourceSettings.java
package org.apache.wicket.settings; ... public ResourceSettings(final Application application) { this.application = application; stringResourceLoaders.add(new ComponentStringResourceLoader()); stringResourceLoaders.add(new PackageStringResourceLoader()); stringResourceLoaders.add(new ClassStringResourceLoader(application.getClass())); stringResourceLoaders.add(new ValidatorStringResourceLoader()); stringResourceLoaders.add(new InitializerStringResourceLoader(application.getInitializers())); }
Compornent#getString() で プロパティが なかった 場合
java.util.MissingResourceException が
org.apache.wicket.DefaultExceptionMapper: Unexpected error occurred ! java.util.MissingResourceException: Unable to find property: 'snippet.title' for component: videos:0 [class=org.apache.wicket.markup.html.list.ListItem]. Locale: null, style: null ! at org.apache.wicket.Localizer.getString(Localizer.java:268)
確かにsnippet.title
を
と
どこで
@Override protected void populateItem(ListItem<Document> item) { Label title = new Label("title", item.getString("snippet.title")); item.add(title); }
個人的な プロパティファイルの 管理戦略
アプリケーション共通で
使用する 設定値、 文言の 管理
ClassStringResourceLoader を使用する。 画面個別での、
設定値、 文言の 管理
ComponentStringResourceLoader を使用する。
が基本的な
場合にwicket-package.properties
の
以上です。
コメント