2010-04-13 135 views
0

我希望能夠根據我的網站支持的語言創建一個下拉選擇框。我似乎無法在Wicket中找到可以實現這一功能的組件。我怎樣才能做到這一點?語言下拉選擇器

回答

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>