How do you manually set the RadioGroup value to the gates?

I am trying to change the selected switch in a Wicket RadioGroup during AjaxEventBehavior, but cannot figure out how to do this. In particular, when a user enters text in a text box, I want to change the selected radio button to one, which I will indicate. How do you do this?

Here is what I still have (it falls on addComponent):

myRadioGroup = new RadioGroup("MyNewGroup", new PropertyModel(getPojo(), "selectedGroup")); Radio internalRadio = new Radio("InternalDirectoryNumber", new Model("Internal")); myRadioGroup .add(internalRadio); Radio externalRadio = new Radio("OtherMobileNumber", new Model("External")); myRadioGroup .add(externalRadio); TextField myTxtField= new TextField("TextBoxPrivateNumber", new PropertyModel(getVoiceItem(), "privateMobilePhone")); myTxtField.add( new AjaxEventBehavior( "onKeyUp" ) { @Override protected void onEvent(AjaxRequestTarget target) { Component component = target.getPage().get("myForm:MyNewGroup").setDefaultModelObject("External"); target.addComponent(component); //this causes an exception } }); myRadioGroup .add(myTxtField); 

Here is an abandoned exception. java.lang.IllegalArgumentException: cannot update a component that does not have setOutputMarkupId set to true. Component: [MarkupContainer [Component id = myRadioGroup]]

What is the right way to do this? I do not find much documentation on the gate for this online.

+4
source share
1 answer

To use addComponent to update the Ajax of your myRadioGroup component, you need to add

 myRadioGroup.setOutputMarkupId(true); 

Here is an example code example of various wickets and documentation .

+5
source

Source: https://habr.com/ru/post/1307473/


All Articles