gpt4 book ai didi

java - 为什么行为停止在 autocompleteField 内使用 propertyModel

转载 作者:行者123 更新时间:2023-12-01 13:17:42 26 4
gpt4 key购买 nike

在我的应用程序中,我有 autocompleteTextField。当输入中的文本更改时,我需要获取玩家的 ID。我正在尝试使用此问题推荐的模型:using AutoCompleteTextField in wicket without String as the generic type但没有成功。当我使用 PropertyModel 或设置类 Player.class 而不是 null 时,行为停止工作。我不明白为什么。

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
}

}
});

最佳答案

根据您链接到的问题:

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.

你做到了吗?

此外,如果这不能解决问题,请更详细地描述它如何“停止工作”。

关于java - 为什么行为停止在 autocompleteField 内使用 propertyModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22337998/

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