'Set default value for Radio Choice - Wicket

I want to set my Radio Choice to "Sim" by default, how can I do that?

My custom Radio Choice class:

package com.sges.web.components;

import java.util.ArrayList;
import java.util.Arrays;

import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior;
import org.apache.wicket.markup.html.form.RadioChoice;
import org.apache.wicket.model.IModel;

public class RadioSimNao extends RadioChoice<Boolean> {
    private static final long serialVersionUID = 1L;

    public RadioSimNao(String id, IModel<Boolean> model) {
        super(id, model, new ArrayList<Boolean>(Arrays.asList(Boolean.TRUE, Boolean.FALSE)), new BooleanChoiceRenderer());
        add(AjaxFormChoiceComponentUpdatingBehavior.onUpdateChoice(target -> target.add(getThis())));
    }

    private RadioSimNao getThis() {
        return this;
    }

}

Here's where I initialize it.

dispoeGeradoresEmergenciaChoice = new RadioSimNao("dispoeGeradoresEmergencia",null);
dispoeGeradoresEmergenciaChoice.setEnabled(false);
dimensao_enquadramento_container.add(dispoeGeradoresEmergenciaChoice);



Solution 1:[1]

super(id, model, new ArrayList<Boolean>(Arrays.asList(Boolean.TRUE, Boolean.FALSE)), new BooleanChoiceRenderer());

Here you say that the RadioChoice may have two possible values: TRUE and FALSE

2.

dispoeGeradoresEmergenciaChoice = new RadioSimNao("dispoeGeradoresEmergencia",null);

Here you pass null as a model for the selected value. If you want to pre-select any of the possible values then you should pass Model.of(true) or Model.of(false)

It is not clear what do you mean with Sim in I want to set my Radio Choice to "Sim" by default. "Sim" is not in the possible value (TRUE | FALSE).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 martin-g