Reputation: 612
I'm a beginner in wicket development. I have an issue regarding a popup dialog. This dialog is triggered when I clicked on a button.
This dialog contains a checkbox (Accept terms) and several radio buttons below, and two buttons, one is cancel and the other one accept.
My issue is that I need to make sure, I have both the checkbox and one radio selected to set the button "Accept" to enable state, otherwise it should be sealed (enabled = false).
The thing is the radio buttons are in a different file (they are inside a panel in other file, let's call them "CancellationRadioButtons"). I managed to render them properly inside the main dialog (doing an add(cancellationradioButtons) in "MainPanel").
The question is, if both elements: Checkbox and radio buttons contains their corresponding models, how do I make sure that both are selected (the checkbox and one radio button), I mean how do you communicate the MainPanel with the CancellationRadioButtons and vice versa?
For example, when the dialog is triggered, nothing is selected by default, so the Accept button is sealed. If I click on one of the radio buttons, the Accept button will remain sealed until I checked the checkbox. The same happens if I check the checkbox and no radio button is selected.
I have models for both elements but I don't know how to communicate them. I have a SetEnabled method in the Accept button (now is enabled when I check the checkbox only), but I don't know how to make the conjuction between the two conditions (Checkbox.checked and radiobutton selected)
I would like to post code here to make it simpler, but I couldn't due to company policy, and I'm having a hard time reproducing the same dialog in my local pc, because it was already done, I'm just fixing stuff there.
Any ideas in how to proceed with this, Some hints and simple examples would be appreciated!
Upvotes: 0
Views: 2164
Reputation: 17513
This is the strong side of stateful frameworks like Wicket! You say that the checkbox and the radio buttons have their own models. The easiest way to solve your problem is to make those models available to the Accept button as well, so it can use it in its onConfigure()
to decide what value to use when calling this.setEnabled(...)
.
You can use Wicket's CompoundPropertyModel
for the dialog and each child component can use a property from it. Accept button will use the compound model object to see all properties' values.
Or you can create the current separate models in the dialog constructor and pass them only to the components that need them.
Upvotes: 1