001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.wicket.util.tester.apps_3;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.apache.wicket.markup.html.WebPage;
023: import org.apache.wicket.markup.html.form.Button;
024: import org.apache.wicket.markup.html.form.Check;
025: import org.apache.wicket.markup.html.form.CheckBox;
026: import org.apache.wicket.markup.html.form.CheckBoxMultipleChoice;
027: import org.apache.wicket.markup.html.form.CheckGroup;
028: import org.apache.wicket.markup.html.form.ChoiceRenderer;
029: import org.apache.wicket.markup.html.form.DropDownChoice;
030: import org.apache.wicket.markup.html.form.Form;
031: import org.apache.wicket.markup.html.form.ListChoice;
032: import org.apache.wicket.markup.html.form.ListMultipleChoice;
033: import org.apache.wicket.markup.html.form.Radio;
034: import org.apache.wicket.markup.html.form.RadioChoice;
035: import org.apache.wicket.markup.html.form.RadioGroup;
036: import org.apache.wicket.markup.html.list.ListItem;
037: import org.apache.wicket.markup.html.list.ListView;
038: import org.apache.wicket.model.CompoundPropertyModel;
039: import org.apache.wicket.model.Model;
040: import org.apache.wicket.util.tester.apps_1.Book;
041:
042: /**
043: * @author Ingram Chen
044: */
045: public class ChoicePage extends WebPage {
046: private static final long serialVersionUID = 1L;
047:
048: /** test DropDownChoice */
049: public Book dropDownChoice;
050:
051: /** test ListChoice */
052: public Book listChoice;
053:
054: /** test RadioChoice */
055: public Book radioChoice;
056:
057: /** test RadioChoice */
058: public Book radioGroup;
059:
060: /** test CheckBox initial value */
061: public boolean checkBox;
062:
063: /** test CheckGroup initial value */
064: public List initialCheckGroup = new ArrayList();
065:
066: /** test ListMultipleChoice initial values */
067: public List initialListMultipleChoice = new ArrayList();
068:
069: /** test CheckBoxMultipleChoice initial values */
070: public List initialCheckBoxMultipleChoice = new ArrayList();
071:
072: /** test CheckBoxMultipleChoice */
073: public List checkBoxMultipleChoice = new ArrayList();
074:
075: /** test CheckGroup */
076: public List checkGroup = new ArrayList();
077:
078: /** test ListMultipleChoice */
079: public List listMultipleChoice = new ArrayList();
080:
081: /** test multiple button */
082: public boolean anotherButtonPressed;
083:
084: /**
085: * Test page for FormTester.select()
086: *
087: * @param candidateChoices
088: */
089: public ChoicePage(List candidateChoices) {
090: ChoiceRenderer bookChoiceRenderer = new ChoiceRenderer("name",
091: "id");
092:
093: Form form = new Form("choiceForm");
094: add(form);
095:
096: form.setModel(new CompoundPropertyModel(this ));
097:
098: // setting initial values
099: dropDownChoice = (Book) candidateChoices.get(1);
100: listChoice = (Book) candidateChoices.get(3);
101: radioChoice = (Book) candidateChoices.get(2);
102: checkBox = true;
103: initialListMultipleChoice.add(candidateChoices.get(1));
104: initialListMultipleChoice.add(candidateChoices.get(2));
105: initialCheckBoxMultipleChoice.add(candidateChoices.get(0));
106: initialCheckBoxMultipleChoice.add(candidateChoices.get(3));
107: initialCheckGroup.add(candidateChoices.get(2));
108: initialCheckGroup.add(candidateChoices.get(3));
109:
110: // single select family
111: form.add(new DropDownChoice("dropDownChoice", candidateChoices,
112: bookChoiceRenderer));
113: form.add(new ListChoice("listChoice", candidateChoices,
114: bookChoiceRenderer).setMaxRows(4));
115: form.add(new RadioChoice("radioChoice", candidateChoices,
116: bookChoiceRenderer));
117: form.add(new CheckBox("checkBox"));
118: form.add(newRadioGroup(candidateChoices));
119:
120: // multiple select family
121: form.add(new ListMultipleChoice("initialListMultipleChoice",
122: candidateChoices, bookChoiceRenderer));
123: form.add(new CheckBoxMultipleChoice(
124: "initialCheckBoxMultipleChoice", candidateChoices,
125: bookChoiceRenderer));
126: form.add(newCheckGroup("initialCheckGroup", candidateChoices));
127: form.add(new ListMultipleChoice("listMultipleChoice",
128: candidateChoices, bookChoiceRenderer).setMaxRows(4));
129: form.add(new CheckBoxMultipleChoice("checkBoxMultipleChoice",
130: candidateChoices, bookChoiceRenderer));
131: form.add(newCheckGroup("checkGroup", candidateChoices));
132: form.add(new Button("anotherButton") {
133: private static final long serialVersionUID = 1L;
134:
135: public void onSubmit() {
136: anotherButtonPressed = true;
137: }
138: });
139: }
140:
141: private CheckGroup newCheckGroup(final String id,
142: List candidateChoices) {
143: CheckGroup checkGroupComponent = new CheckGroup(id);
144: ListView listView = new ListView("loop", candidateChoices) {
145: private static final long serialVersionUID = 1L;
146:
147: protected void populateItem(ListItem item) {
148: item.add(new Check("check", new Model((Book) item
149: .getModelObject())));
150: }
151:
152: };
153: checkGroupComponent.add(listView);
154: return checkGroupComponent;
155: }
156:
157: private RadioGroup newRadioGroup(List candidateChoices) {
158: RadioGroup radioGroupComponent = new RadioGroup("radioGroup");
159: ListView listView = new ListView("loop", candidateChoices) {
160: private static final long serialVersionUID = 1L;
161:
162: protected void populateItem(ListItem item) {
163: item.add(new Radio("radio", new Model((Book) item
164: .getModelObject())));
165: }
166:
167: };
168: radioGroupComponent.add(listView);
169: return radioGroupComponent;
170: }
171: }
|