简体   繁体   English

小票下拉验证onchange

[英]Wicket dropdown validation onchange

I have a dropdown in wicket 1.4 (part of a form) which shows choices for numbers. 我在检票口1.4(表单的一部分)中有一个下拉列表,其中显示了数字的选择。 Now when a number is selected, I change the status of that number to reserved in database using onUpdate method of dropdown. 现在,当选择一个数字时,我使用下拉列表的onUpdate方法将该数字的状态更改为保留在数据库中。

Now, I want to create a validator which checks whether selected number is already reserved in database or not (by some other parallel process). 现在,我想创建一个验证器,以检查所选的号码是否已经在数据库中保留(通过其他并行过程)。 But this validator should validate only on value change before onUpdate as the number will get reserved in onUpdate method. 但是此验证器只应在onUpdate之前对值更改进行验证,因为该数字将在onUpdate方法中保留。

So basically what I want to do is to manually invoke validator when I need and prevent it from getting invoked at other times 因此,基本上我想做的是在需要时手动调用验证器,并防止它在其他时间被调用

Or simply, how to make validate and update event work together 或者简单地说,如何使验证和更新事件协同工作

Just curious; 只是好奇; why you would want a validator to do this job when you could potentially add a database call method inside onUpdate itself? 当您可能在onUpdate本身中添加数据库调用方法时,为什么要让验证者执行此工作?

You could still create a reusable method to call it from different places and use it. 您仍然可以创建可重用的方法,以从不同位置调用它并使用它。 Validator is something you want to use for format/range kind of validations ( This is my choice - not necessarily best one ) and have business logic validations either in service layer or close to DAO layer if I don't have 'service' layer. 验证器是您要用于格式/范围类型的验证(这是我的选择-不一定是最好的选择),并且如果没有“服务”层,则可以在服务层或接近DAO层进行业务逻辑验证。

I think this will never work. 我认为这永远都行不通。 As you validate before the update, there is still a chance that the value was changed by another process. 在更新之前进行验证时,仍然有可能该值已被另一个进程更改。

I would use a nice feedback message telling the user that we were unable to update the number because someone else just did it before you. 我会使用一条很好的反馈消息告诉用户我们无法更新该号码,因为其他人只是在您之前这样做了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM