List of usage examples for org.apache.wicket.markup.html.form Check getModelObject
@SuppressWarnings("unchecked") default T getModelObject()
From source file:gr.interamerican.wicket.markup.html.panel.picker.TestMultipleSelectionsPanel.java
License:Open Source License
/** * Tests creation of {@link MultipleSelectionsPanel}. * /* w ww .j a va 2 s . c om*/ * Also tests that pressing the select button, selects the selected items. */ @Test public void testCreation() { MultipleSelectionsPanelDef<BeanWithOrderedFields> def = createDef(); tester.startPage(getTestPage(new MultipleSelectionsPanel<BeanWithOrderedFields>(def))); tester.assertComponent(path("tableForm:checkGroup"), CheckGroup.class); tester.assertComponent(path("tableForm:checkGroup:listTable"), DataTable.class); tester.assertComponent(path("tableForm:checkGroup:listTable:body:rows:1:cells:4:cell:checkBox"), Check.class); String buttonId = path("tableForm:selectButton"); tester.assertComponent(buttonId, AjaxButton.class); AjaxButton button = (AjaxButton) tester.getComponentFromLastRenderedPage(path("tableForm:selectButton")); @SuppressWarnings("unchecked") CheckGroup<BeanWithOrderedFields> checkGroup = (CheckGroup<BeanWithOrderedFields>) tester .getComponentFromLastRenderedPage(path("tableForm:checkGroup")); /* * radio button of first row. Holds the first * BeanWithOrderedFields of the List supplied * to the DataTable. */ @SuppressWarnings("unchecked") Check<BeanWithOrderedFields> check1 = (Check<BeanWithOrderedFields>) tester .getComponentFromLastRenderedPage( path("tableForm:checkGroup:listTable:body:rows:1:cells:4:cell:checkBox")); assertSame(def.getList().get(0), check1.getModelObject()); @SuppressWarnings("unchecked") Check<BeanWithOrderedFields> check2 = (Check<BeanWithOrderedFields>) tester .getComponentFromLastRenderedPage( path("tableForm:checkGroup:listTable:body:rows:2:cells:4:cell:checkBox")); assertSame(def.getList().get(1), check2.getModelObject()); /* * Set the first and second object of the BeanWithOrderedFields List as the * model object of the RadioGroup. This emulates the user actually having * clicked the above check boxes. */ List<BeanWithOrderedFields> selections = new ArrayList<BeanWithOrderedFields>(); selections.add(check1.getModelObject()); selections.add(check2.getModelObject()); checkGroup.setModelObject(selections); callback.setExecuted(false); /* * We insert the values in the request parameters manually, because * the formTester.submit() will assign new ids in the path of the * radio buttons and, as a result, the AjaxEvent will fail to locate * the correct radio and retrieve the model. So, normally we would do: * * FormTester formTester = tester.newFormTester(path("tableForm")); * formTester.select("radioGroup", 0); * formTester.submit(); * * TODO: is there a way to have the ajaxevent submit the form maybe? * Having to do this in two steps is a bit counter-intuitive. * * The following line is the equivalent of having clicked the first * row radio. "radio" is the wicket:id of the radio buttons and 0 stands * for the first row. */ Map<String, String[]> map = tester.getRequest().getParameterMap(); map.put("testId:tableForm:checkGroup", new String[] { "check0", "check1" }); tester.executeAjaxEvent(button, "onclick"); assertTrue(callback.isExecuted()); assertSame(selections, def.getSelectionsModel().getObject()); }