In my Application i have a DropDownSelect which changes a Label onUpdate by  
AjaxFormComponentUpdatingBehaviorThen there is a Button which tries access at 
the selected item. In the real Webapp it works fine but when i test itwhen i 
click the Button the selected Item is null.What I am doing wrong. Here the 
HomePage:
public class HomePage extends WebPage { private static final long 
serialVersionUID = 1L; private static final List<String> SEARCH_ENGINES = 
Arrays.asList(new String[] { "Google", "Bing", "Baidu" }); //make Google 
selected by default private String selected = "Google";
    Model<String> model = new Model<String>() {                    public 
String getObject() {              return getSelected();          }      }; 
      private Label chosen=new Label("chosen", model);   public HomePage(final 
PageParameters parameters) { super(parameters);  FeedbackPanel feedback=new 
FeedbackPanel("feedback"); add(feedback);  feedback.setVisible(true); // other 
pages will set this to visible         feedback.setEscapeModelStrings(false); 
add(new Label("version", 
getApplication().getFrameworkSettings().getVersion()));  DropDownChoice<String> 
listSites = new DropDownChoice<String>( "sites", new 
PropertyModel<String>(this, "selected"), SEARCH_ENGINES);
 Form<?> form = new Form<Void>("form");  final   Button detailButton=new 
Button("detailButton") { @Override public void onSubmit() {info(getSelected()); 
} };  detailButton.setOutputMarkupId(true); chosen.setOutputMarkupId(true);   
listSites.add(new AjaxFormComponentUpdatingBehavior("onchange")        {        
    @Override            protected void onUpdate(AjaxRequestTarget target)      
      {                              target.add(chosen);            
target.add(detailButton);                      }        });    
form.add(chosen);  add(form); form.add(listSites); form.add(detailButton);    } 
 public String getSelected() { return selected; }
 public void setSelected(String selected) { this.selected = selected; }}

and here the Test :
public class TestHomePage{ private WicketTester tester;
 @Before public void setUp() { tester = new WicketTester(new 
WicketApplication()); }
 @Test public void homepageRendersSuccessfully() { //start and render the test 
page tester.startPage(HomePage.class);
 //assert rendered page class tester.assertRenderedPage(HomePage.class); 
FormTester  formTester = tester.newFormTester("form"); 
formTester.select("sites", 1);  
tester.executeBehavior((AbstractAjaxBehavior)tester.getComponentFromLastRenderedPage("form:sites").getBehaviors().get(0));
  tester.assertLabel("form:chosen", "Bing");   
formTester.submit("detailButton");  
tester.assertInfoMessages("feedback","Bing"); }}
i am using wicket 6.19.0

Reply via email to