The Java – wicket check box automatically submits its changed value to the domain object
What is the cleanest way I can make a check box automatically submit the form it belongs to in wicket? I don't want to include a submit button at all This check box is supported by a Boolean field (in this case, account) in the domain object
Simplified example of omitting irrelevant parts:
EntityModel<Account> accModel = new EntityModel<Account>(Account.class,id); PropertyModel<Boolean> model = new PropertyModel<Boolean>(accModel,"enabled"); Check@R_507_2419@ check@R_507_2419@ = new Check@R_507_2419@("cb",model); Form form = new Form("form"); form.add(check@R_507_2419@); add(form);
HTML:
<form wicket:id="form" id="form" action=""> <input wicket:id="cb" type="check@R_507_2419@" /> </form>
Edit: to clarify, my goal is to change the field of the domain object (– > value in the database) when the check box is switched Any (clean, simple) way to achieve this will be fine I don't know if you really need this form
Solution
Just override the wantonselectionchanged notifications () of all check boxes, even if it doesn't override onselectionchanged () – it seems to do what I want
In this way, you do not need the form on the Java side, so the above code will become:
EntityModel<Account> accModel = new EntityModel<Account>(Account.class,id); add(new Check@R_507_2419@("cb",new PropertyModel<Boolean>(accModel,"enabled")){ protected boolean wantOnSelectionChangedNotifications() { return true; } });
Feel free to add a better solution or better explain what happened with this approach!
Editor: check carefully. I guess the method's Javadoc makes it clear why it does what I want (emphasize my):