public void testOnClickReturnTrue() throws Exception {
HtmlPage page = getPage("/faces/jsp/commandLinkOnClickTrue.jsp");
HtmlForm form = getFormById(page, "form");
assertNotNull("form exists", form);
HtmlHiddenInput hidden = null;
try {
hidden = (HtmlHiddenInput)form.getInputByName("form:j_idcl");
} catch (ElementNotFoundException e) {
assertTrue(false);
}
// This initial value was set by an "onLoad" javascript function in the jsp.
assertTrue(hidden.getValueAttribute().equals("Goodbye"));
// click the link..
HtmlAnchor submit = (HtmlAnchor)
page.getFirstAnchorByText("submit");
assertTrue(submit.getOnClickAttribute().equals("var a=function(){setValue('form');};var b=function(){clearFormHiddenParams_form('form');document.forms['form']['form:j_idcl'].value='form:submit'; document.forms['form'].submit(); return false;};return (a()==false) ? false : b();"));
try {
page = (HtmlPage) submit.click();
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
}
// The value of this field was set by the user provided "onclick" javascript
// function.
HtmlTextInput input = (HtmlTextInput)form.getInputByName("form:init");
assertTrue(input.getValueAttribute().equals("Hello"));
// The value of this field was changed by the internal Faces javascript function
// created by CommandLinkRenderer..
try {
hidden = (HtmlHiddenInput)form.getInputByName("form:j_idcl");
} catch (ElementNotFoundException e) {
assertTrue(false);
}
assertTrue(hidden.getValueAttribute().equals("form:submit"));
}