Hi there,
I'm trying to check the presence of a behaviour in a testcase.
I have a page with a checkbox and a button, if a user click on the
button without selecting the checkbox, an alert box show a message. If i
access to the page through a browser (firefox) the page runs fine and
the alert box is correctly displayed. So, i would like to retrieve the
behaviour from the form component after submitting the form itself, but
i can't find any behaviour (the list is empty!).
Why ? Is there something wrong with the testcase ?
Here there are the testcase and the webpage (html and java).
Thanks,
Emanuele
Here is the Testcase:
********
public class TestSimplePage extends TestCase{
public void testSimplePage(){
WicketTester tester = new WicketTester();
tester.startPage(SimplePage.class);
tester.submitForm("simpleForm");
Form simpleForm = (Form)
tester.getComponentFromLastRenderedPage("simpleForm");
assertNotNull(simpleForm.getBehaviors());
assertFalse(simpleForm.getBehaviors().isEmpty());
}
}
*******
Here is the webpage:
*******
public class SimplePage extends WebPage {
private static final long serialVersionUID = 8190084597165080916L;
public SimplePage(){
CompoundPropertyModel simpleModel = new CompoundPropertyModel(new
SimpleBean());
final Form form = new Form("simpleForm", simpleModel){
private static final long serialVersionUID =
8176126527045127325L;
public void onSubmit(){
SimpleBean simple = (SimpleBean)
getModelObject();
if (! simple.isSelected()){
add(new Alert("not selected"));
}
}
};
form.add(new Button("btnok"));
form.add(new CheckBox("selected"));
add(form);
}
public class Alert extends AbstractBehavior {
private static final long serialVersionUID =
3346789663630395006L;
private String msg;
public Alert(String msg) {
this.msg=msg;
}
@Override
public boolean isTemporary() {
return true;
}
@Override
public void renderHead(IHeaderResponse response) {
response.renderOnLoadJavascript("alert('"+msg+"');");
}
}
public class SimpleBean implements Serializable{
private static final long serialVersionUID =
-2386033376652365201L;
private boolean selected;
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
}
}
********
and here the html page (only the form):
********
<form name="simpleForm" wicket:id="simpleForm">
<table>
<tr>
<TD><b>Select</b></TD>
<td>
<input type="checkbox"
wicket:id="selected"></td>
</tr>
</table>
<br>
<input type="submit" value="OK" wicket:id="btnok">
</form>
*******
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]