简体   繁体   中英

Wicket dropdown validation onchange

I have a dropdown in wicket 1.4 (part of a form) which shows choices for numbers. Now when a number is selected, I change the status of that number to reserved in database using onUpdate method of dropdown.

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.

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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