01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.examples.compref;
18:
19: import org.apache.wicket.examples.WicketExamplePage;
20: import org.apache.wicket.markup.html.basic.Label;
21: import org.apache.wicket.markup.html.form.Form;
22: import org.apache.wicket.markup.html.form.Radio;
23: import org.apache.wicket.markup.html.form.RadioGroup;
24: import org.apache.wicket.markup.html.list.ListItem;
25: import org.apache.wicket.markup.html.list.ListView;
26: import org.apache.wicket.markup.html.panel.FeedbackPanel;
27: import org.apache.wicket.model.Model;
28: import org.apache.wicket.model.PropertyModel;
29:
30: /**
31: * RadioGroup and Radio components example page
32: *
33: * @author ivaynberg
34: */
35: public class RadioGroupPage extends WicketExamplePage {
36: /**
37: * Constructor
38: */
39: public RadioGroupPage() {
40:
41: final RadioGroup group = new RadioGroup("group", new Model());
42: Form form = new Form("form") {
43: protected void onSubmit() {
44: info("selected person: "
45: + group.getModelObjectAsString());
46: }
47: };
48:
49: add(form);
50: form.add(group);
51:
52: ListView persons = new ListView("persons",
53: ComponentReferenceApplication.getPersons()) {
54:
55: protected void populateItem(ListItem item) {
56: item.add(new Radio("radio", item.getModel()));
57: item.add(new Label("name", new PropertyModel(item
58: .getModel(), "name")));
59: item.add(new Label("lastName", new PropertyModel(item
60: .getModel(), "lastName")));
61: }
62:
63: };
64:
65: group.add(persons);
66:
67: add(new FeedbackPanel("feedback"));
68: }
69:
70: protected void explain() {
71: String html = "<form wicket:id=\"form\">\n"
72: + "<span wicket:id=\"group\">\n"
73: + "<tr wicket:id=\"persons\">\n"
74: + "<td><input type=\"radio\" wicket:id=\"radio\"/></td>\n"
75: + "<td><span wicket:id=\"name\">[this is where name will be]</span></td>\n"
76: + "<td><span wicket:id=\"lastName\">[this is where lastname will be]</span></td>\n"
77: + "</tr>\n" + "</span>" + "</form>";
78: String code = " Form f=new Form(\"form\");<br/>"
79: + " add(f);<br/>"
80: + " RadioGroup group=new RadioGroup(\"group\");<br/>"
81: + " form.add(group);<br/>"
82: + " ListView persons=new ListView(\"persons\", getPersons()) {<br/>"
83: + " protected void populateItem(ListItem item) {<br/>"
84: + " item.add(new Radio(\"radio\", item.getModel()));<br/>"
85: + " item.add(new Label(\"name\", new PropertyModel(item.getModel(), \"name\")));<br/>"
86: + " item.add(new Label(\"lastName\", new PropertyModel(item.getModel(), \"lastName\")));<br/>"
87: + " };<br/>"
88: + " group.add(persons);<br/>";
89: add(new ExplainPanel(html, code));
90: }
91: }
|