gpt4 book ai didi

java - 语言下拉选择器

转载 作者:行者123 更新时间:2023-12-02 08:33:21 24 4
gpt4 key购买 nike

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

最佳答案

我还没有测试过这个,但尝试一下:

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>

关于java - 语言下拉选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2633717/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com