tags:

views:

131

answers:

4

I want to be able to create a drop-down select box based on the languages my website supports. I can't seem to find a component in Wicket that does this out-of-the-box. How can I do this?

+1  A: 

I haven't tested this out, but try something like:

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 ) ) );
}

with markup like:

<html>
<body>
    <form wicket:id="form">
        <select wicket:id="locale" />
        <input type="submit" />
    </form>
</body>
</html>
Brian Laframboise
+1  A: 

Have a look at this link. This is probably along the lines of what you need:

Wicket Locale drop-down selector

Eurig Jones
A: 

Check out wicket-library contribution: http://www.wicket-library.com/wicket-examples/forminput/

Zeratul