Wicket-Optionsfelder - RadioChoice

Beispiel für Wicket-Optionsfelder - RadioChoice

Wicket-Beispiel zum Erstellen einer Gruppe von Optionsfeldern, und standardmäßig ein einzelnes Optionsfeld aktiviert.

//Java
import org.apache.wicket.markup.html.form.RadioChoice;
...
//choices in radio button
private static final List TYPES = Arrays
    .asList(new String[] { "Shared Host", "VPS", "Dedicated Server" });

//variable to hold the selected radio button value, and default "VPS" is selected
private String selected = "VPS";

RadioChoice hostingType = new RadioChoice(
    "hosting", new PropertyModel(this, "selected"), TYPES);

//HTML for radio button

1. Beispiel für ein Wicket-Optionsfeld

Beispiel für die Anzeige einer Gruppe von Optionsfeldern über „RadioChoice“ und standardmäßig aktiviert ein einzelnes Optionsfeld.

package com.example.user;

import java.util.Arrays;
import java.util.List;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RadioChoice;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.model.PropertyModel;

public class RadioChoicePage extends WebPage {

    //choices in radio button
    private static final List TYPES = Arrays
            .asList(new String[] { "Shared Host", "VPS", "Dedicated Server" });

    //variable to hold radio button values
    private String selected = "VPS";

    public RadioChoicePage(final PageParameters parameters) {

        add(new FeedbackPanel("feedback"));

        RadioChoice hostingType = new RadioChoice(
                "hosting", new PropertyModel(this, "selected"), TYPES);

        Form form = new Form("form") {
            @Override
            protected void onSubmit() {

                info("Selected Type : " + selected);

            }
        };

        add(form);
        form.add(hostingType);

    }
}

2. Wicket-HTML-Seite

Seite zum Rendern einer Gruppe von Optionsfeldern.






    

Wicket RadioChoice Example


3. Demo

“VPS” wird automatisch ausgewählt.

radio button in wicket

Wählen Sie nun die Option „Dedicated Server“ und klicken Sie auf die Schaltfläche zum Anzeigen.

radio button in wicket

Laden Sie es herunter -Wicket-RadioChoice-Examples.zip (7 KB)