質問

In my application I have autocompleteTextField. I need to get id of player when text in input changed. I am trying to play with models which are recommended by this question: using AutoCompleteTextField in wicket without String as the generic type but with no success. Behaviour stop working when I use PropertyModel or when I set class Player.class instead of null. I dont understand why.

final AutoCompleteTextField<Player> playersField = new AutoCompleteTextField<Player>("players",
    new Model<Player>(selectedPlayer), null, new AbstractAutoCompleteRenderer<Player>() {

            @Override
            protected void renderChoice(Player player, Response response, String criteria) {
                response.write(getTextValue(player));
            }

            @Override
            protected String getTextValue(Player player) {
                return player.getName() + " " + player.getSurname() + " "
                        + player.getPlayerDiscriminator();
            }
        }
    , settings) {

    @Override
    protected Iterator<Player> getChoices(String prefix) {
        List<Player> choices = getPlayers();
        return choices.iterator();
    }   
};
add(playersField);
playersField.add(new AjaxFormComponentUpdatingBehavior("onchange") {

    @Override
    protected void onUpdate(AjaxRequestTarget target) {
        System.out.println("do something");
        // All I need here is just Id of player
        }

    }
});
役に立ちましたか?

解決

From the question you linked to:

You probably already know this but if your custom class is really custom, you'll also need an IConverter that handles the String<->Someclass conversions: you can either register it with the application or override your component's getConverter(Class clazz ) method to return it.

Did you do that?

Also, if this doesn't fix the problem, please describe how it "stops working" in more details.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top