This is my first time to use wicket. Hence, I don't know whether I did it right or wrong. Anyway, I have reproduced my case below, the first part is java code, and the second part is markup file. Any idea is appreciated, Thanks a lot!!
import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import wicket.markup.html.WebPage; import wicket.markup.html.form.CheckBox; import wicket.markup.html.form.DropDownChoice; import wicket.markup.html.form.Form; import wicket.markup.html.form.FormComponent; import wicket.markup.html.form.validation.AbstractFormValidator; import wicket.markup.html.list.ListItem; import wicket.markup.html.list.ListView; import wicket.model.CompoundPropertyModel; import wicket.model.PropertyModel; public class TestPage extends WebPage { private static final List<String> DROP_DOWN_LIST = Arrays .asList(new String[] { "Sunday", "Monday" }); public TestPage() { super.add(new TestForm("form")); } private class TestForm extends Form { public TestForm(String id) { super(id); List<InnerModel> innerModel = new ArrayList<InnerModel>(); for (int i = 0; i < 5; i++) { innerModel.add(new InnerModel()); } TestModel testModel = new TestModel(); testModel.setInnerModels(innerModel); super.setModel(new CompoundPropertyModel(testModel)); ListView lv = new ListView("innerModels") { protected void populateItem(ListItem item) { CheckBox checkBox = new CheckBox("checked", new PropertyModel(item.getModel(), "checked")); item.add(checkBox); DropDownChoice choice = new DropDownChoice("choice", new PropertyModel(item.getModel(), "choice"), TestPage.DROP_DOWN_LIST); item.add(choice); TestForm.this.add(new TestValidator(checkBox, choice)); } }; super.add(lv); } } private class TestValidator extends AbstractFormValidator { private final FormComponent[] formComponents; public TestValidator(FormComponent comp1, FormComponent comp2) { this.formComponents = new FormComponent[] { comp1, comp2 }; } public FormComponent[] getDependentFormComponents() { return this.formComponents; } public void validate(Form form) { if ((Boolean) this.formComponents[0].getConvertedInput() == true) { if (!this.formComponents[1].getConvertedInput() .equals("Sunday")) { this.formComponents[1].error("ERROR!!"); } } } } private class TestModel implements Serializable { private List<InnerModel> innerModels; public List<InnerModel> getInnerModels() { return this.innerModels; } public void setInnerModels(List<InnerModel> model) { this.innerModels = model; } } private class InnerModel implements Serializable { private boolean checked; private String choice; public boolean isChecked() { return checked; } public void setChecked(boolean checked) { this.checked = checked; } public String getChoice() { return choice; } public void setChoice(String choice) { this.choice = choice; } } } ----------------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="BIG5" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.sourceforge.net"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Insert title here</title> </head> <body> <form wicket:id="form"> <table> <tbody> <tr wicket:id="innerModels"> <td><input wicket:id="checked" type="checkbox" /></td> <td><select wicket:id="choice"> <optgroup label=""> <option>option</option> </optgroup> </select></td> </tr> </tbody> </table> <input type="submit" /> </form> </body> </html> Regards, Chih-liang Chang -- View this message in context: http://www.nabble.com/How-to-add-components-nested-in-the-list-view-to-a-IFormValidator--t1834645.html#a5023169 Sent from the Wicket - User forum at Nabble.com. Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user