语言下拉选择器

时间:2010-04-13 22:47:06

标签: java wicket

我希望能够根据我的网站支持的语言创建一个下拉选择框。我似乎无法在Wicket中找到一个开箱即用的组件。我怎么能这样做?

2 个答案:

答案 0 :(得分:1)

我没有对此进行测试,但尝试类似:

private Locale chosenLocale;

public LocalePage() {
    Form<Void> form = new Form<Void>( "form" ) {
        @Override
        protected void onSubmit() {
            // do something with this.chosenLocale
            // perhaps getSession().setLocale(this.chosenLocale);
        }
    };
    List<Locale> locales = new ArrayList<Locale>(Arrays.asList( Locale.ENGLISH, Locale.FRENCH  ));
    DropDownChoice<Locale> choice = new DropDownChoice<Locale>( "locale", new PropertyModel<Locale>( this,
            "chosenLocale" ), locales, new IChoiceRenderer<Locale>() {

        @Override
        public Object getDisplayValue(Locale object) {
            return object.toString();
        }

        @Override
        public String getIdValue(Locale object, int index) {
            return String.valueOf( index );
        }

    } );

    add( form.add( choice.setNullValid( false ) ) );
}

标记如:

<html>
<body>
    <form wicket:id="form">
        <select wicket:id="locale" />
        <input type="submit" />
    </form>
</body>
</html>

答案 1 :(得分:1)