小票DropDownChoice无法与PropertyModels一起正常使用 [英] Wicket DropDownChoice NOT working correctly with PropertyModels

查看:102
本文介绍了小票DropDownChoice无法与PropertyModels一起正常使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试调试为什么仅具有DropDown和Submit Button的简单形式的DropDownChoice无法正常工作几个小时.

I have been trying to debug why my DropDownChoice in a simple form with just the DropDown and a Submit Button hasn't been working correctly for hours now.

它具有非常奇怪的行为.下拉选项中选择的第一个值成功发送到服务器,此后模型不更新任何其他选项.即,如果我有一个列表人,并且我选择了第二个人,则它成功提交了此人.但是,在选择另一个人并尝试再次提交它时,它会一直显示第一个选择的选项.

It has a very weird behaviour. Where the first value selected in the drop down choice is sent successfully to the server after which any other choice select is not updated by the model. ie if I have a List persons, and I select the 2nd person, it submits this successfully. However, on select of another person and trying to submit it again it keeps showing the first selected option.

此处的代码段:

 ChoiceRenderer<Empowerment> empowermentChoiceRenderer = new ChoiceRenderer<>("name", "id");
 final DropDownChoice<Empowerment> empowermentDropDownChoice =
                    new DropDownChoice<>("empowerment", new PropertyModel<Empowerment>(this, "empowerment"), empowermentList, empowermentChoiceRenderer);
 empowermentDropDownChoice.setRequired(true);
 add(empowermentDropDownChoice);

只有当我将上面的授权变量设置为null时,我才能获得体面的行为.在这种情况下,在提交时,授权将重新初始化为null,然后新提交可以正常工作.

Only way I am able to get a decent behaviour is if I set the empowerment variable above to null. In this case, on submit the empowerment is reinitialised to null and then a new submit works correctly.

授权只是一个JPA实体.

empowerment is just a JPA entity.

很高兴知道这是否是已知问题.我在检票口6.9.1和检票口6.12中经历过

I'll be glad to know if this is a known issue. I experienced it in wicket 6.9.1 and wicket 6.12

推荐答案

最后,找到了解决问题的方法.上面的代码是正确的,但问题出在实体类本身中-授权需要正确实现Equals和Hashcode.

Finally, found the solution to the problem. Above code is correct, but problem lied in the entity class itself - Empowerment needs to implement Equals and Hashcode correctly.

DropDownChoice在此之后工作正常.

The DropDownChoice works just fine after this.

这篇关于小票DropDownChoice无法与PropertyModels一起正常使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆