Radio buttons in Wicket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="radio" name="ticker" value="AAPL"/>Apple<br/> | |
<input type="radio" name="ticker" value="GOOG"/>Google<br/> | |
<input type="radio" name="ticker" value="MSFT"/>Microsoft<br/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<label><input type="radio" name="ticker" value="AAPL"/>Apple</label> | |
<label><input type="radio" name="ticker" value="GOOG"/>Google</label> | |
<label><input type="radio" name="ticker" value="MSFT"/>Microsoft</label> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
label { display: block; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form wicket:id="form"> | |
<wicket:container wicket:id="group"> | |
<label><input wicket:id="aapl" type="radio" name="ticker"/>Apple</label> | |
<label><input wicket:id="goog" type="radio" name="ticker"/>Google</label> | |
<label><input wicket:id="msft" type="radio" name="ticker"/>Microsoft</label> | |
</wicket:container> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Radio buttons must be part of a Form component. | |
Form form = new Form("form"); | |
add(form); | |
// This model holds the value corresponding to the radio that the user selected. | |
// We use a simple Model here, but in practice it would be a PropertyModel to your | |
// persistent data object. | |
IModel<String> selected = new Model<String>(); | |
RadioGroup group = new RadioGroup("group", selected); | |
form.add(group); | |
// For each radio button, we create it with a hardcoded string value that | |
// represents that choice. That string value will be passed to our selected | |
// model (see above) when the form is submitted. | |
group.add(new Radio("aapl", new Model<String>("AAPL"))); | |
group.add(new Radio("goog", new Model<String>("GOOG"))); | |
group.add(new Radio("msft", new Model<String>("MSFT"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Company implements Serializable | |
{ | |
private String symbol; | |
private String name; | |
// getters and setters omitted for brevity | |
/** | |
* It is very important to provide a meaningful {@code equals()} | |
* implementation. Wicket uses this to compare the saved value of the | |
* form against the various radio button choices in order to determine | |
* which choice should be drawn as selected. | |
*/ | |
public boolean equals(Object other) | |
{ | |
if(!(other instanceof Company)) return false; | |
return symbol != null && symbol.equals(((Company) other).symbol); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form wicket:id="form"> | |
<wicket:container wicket:id="group"> | |
<label wicket:id="choice"> | |
<input wicket:id="radio" type="radio" name="ticker"/> | |
<wicket:container wicket:id="label"/> | |
</label> | |
</wicket:container> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Radio buttons must be part of a Form component. | |
Form form = new Form("form"); | |
add(form); | |
IModel<Company> selected = new Model<Company>(); | |
RadioGroup group = new RadioGroup("group", selected); | |
form.add(group); | |
// Exercise left for the reader: load the list of companies from the database. | |
IModel<List<Company>> companies; | |
// Construct a radio button and label for each company. | |
form.add(new ListView<Company>("choice", companies) { | |
protected void populateItem(ListItem<Company> it) | |
{ | |
it.add(new Radio("radio", it.getModel())); | |
it.add(new Label("label", it.getModelObject().getName())) | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="radio" name="form:group" value="radio13"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IModel<Company> selected = new Model<Company>(); | |
// Exercise left for the reader: load the list of companies from the database. | |
IModel<List<Company>> companies; | |
// Tell RadioChoicesListView what properties to use for label and ID | |
ChoiceRenderer<Company> renderer = new ChoiceRenderer<Company>("name", "symbol"); | |
// Wire it all up! | |
add(new Form("form") | |
.add(new RadioGroup("group", selected) | |
.add(new RadioChoicesListView("choice", companies, renderer)))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment