投稿‎ > ‎

Wicketウィザード画面のタイトルを設定する

posted Jul 19, 2013, 7:29 AM by Zhang Wenxu   [ updated Jul 19, 2013, 8:56 AM ]
Wicketウィザードサンプル画面を動かして、各ウィザード画面に適切のタイトルを表示したい場合の対応方法を共有します。
1.WizardPage.html
<title wicket:id="title">Wicket Examples - wizard</title>
2.WizardPage.java
public class WizardPage extends WebPage
{
Wizard wizard;
/**
* Construct.
* @param <C>
* @param wizardClass
*            class of the wizard component
*/
public <C extends Wizard> WizardPage(Class<C> wizardClass)
{
add(new Label("title", new PropertyModel(this, "title"))); 
if (wizardClass == null)
{
throw new IllegalArgumentException("argument wizardClass must be not null");
}
try
{
Constructor<? extends Wizard> ctor = wizardClass.getConstructor(String.class);
wizard = ctor.newInstance("wizard");
add(wizard);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
public String getTitle(){
return ((WizardTitle)wizard).getTitle();
}; 
}
3.WizardTitle.java
public interface WizardTitle {
public String getTitle();
}

4.NewUserWizard.java
public class NewUserWizard extends Wizard implements WizardTitle
{

...

@Override
public String getTitle() {
return new ClassStringResourceLoader(this.getClass()).loadStringResource(this.getClass(), "title", getLocale(), null, null);
}
}
5.NewUserWizard.properties
title=New User
  NewUserWizard_ja.properties
title=ユーザー新規登録

6.画面表示

Google+
By Zhang Wenxu
Comments