I think I can give you another option based on Alexander's code. I added
comments to explain how does it works. I didn't test it but If you have any
problem just tell me:
// model that indicates if I have to show the textfield
final IModel<Boolean> yesNoState = new Model<Boolean>();
// this is because when textfield is hidden you can't reference it by
markupid because html component doesn't exists.
final WebMarkupContainer fieldContainer = new
WebMarkupContainer("fieldContainer");
// this indicates wicket to create an id for tag. Necesary to update by
ajax.
fieldContainer.setOutputMarkupId(true);
// textfield to show with isVisible redifined based on previous model
final TextField<String> textField = new TextField<String>("text") {
@Override
public boolean isVisible() {
return yesNoState.getObject();
}
};
fieldContainer.add(textField);
// just a component to agrupate options
RadioGroup<Boolean> yesNoGroup = new RadioGroup<Boolean>("yesNoGroup",
yesNoState);
yesNoGroup.add(new AjaxFormChoiceComponentUpdatingBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
// this is to update container by ajax and consequently textField
visibility.
target.addComponent(fieldContainer);
}
});
yesNoGroup.add(new Radio<Boolean>("yes", Model.of(Boolean.TRUE)), new
Radio<Boolean>("no", Model.of(Boolean.FALSE)));
add(fieldContainer);
add(yesNoGroup);
I hope that helps you.
Bye
Norberto
2011/11/20 ridaa <[email protected]>
> Hey ....thanx alot ...!!
> It would be really very helpful if i could get some explanation on above
> code.
>
> Regards.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Radio-button-selection-tp4085827p4088663.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>