You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shale.apache.org by Hasan Turksoy <ht...@gmail.com> on 2007/05/02 16:59:34 UTC

[validator] possible bug in validator script generation for child comp. inside not rendered parent comp.

hi all,

it seems there is a buggy case at validator script generation(at
findCommonsValidators method to be exact).. issue is; when i use a component
inside another parent component(that's NOT RENDERED), it's still generating
validator scripts for my child component.. this causes script errors when i
submitted my page... Because, there is a validation script exists for a not
rendered(because parent's not rendered) component.

To visualize;
<h:panelGroup rendered="false"> // child components won't be rendered
because parent's not rendered
  <h:inputText id="txt_name" ....>
   <s:commonsValidator type="required" arg="Name" server="true"
client="true" />
  </h:inputText>
</h:panelGroup>

as seen above, my textbox(txt_name) won't be rendered since it's parent
won't be rendered.. But client validator scripts are still being generated
for this field. This causes javascript errors at form submit...

Should we enter an issue for this case?

Below is a test method for the case; (necessary methods already in jar's
test package)
/*-------------------------------------------------------------------*/
    public void testScriptNotGeneratedForComponentsInsideNotRenderedParent()
throws Exception {
        // find the view root
        UIViewRoot root = facesContext.getViewRoot();
        assertNotNull(root);

        UINamingContainer namingContainer = (UINamingContainer)
application.createComponent("javax.faces.NamingContainer");

        namingContainer.setId(root.createUniqueId());
        root.getChildren().add(root.getChildCount(), namingContainer);

        //create a form 1
        UIComponent form1 = this.createForm("test1", namingContainer);


        //create a dummy parent panel component
        HtmlPanelBox panelbox = createPanelBox("pnl_name", form1);

        //create a dummy component 1
        HtmlInputText component1 = createInputText("txt_name", panelbox);

        //create a required field/server rule
        CommonsValidator validator1 = createValidator(component1,
"required", null);

        //create a script component
        ValidatorScript script = createValidatorScript(root);

        // render the javascript for the form
        StringBuffer htmlSnippet = encode(script);

        System.out.println(htmlSnippet.toString());

        // search tokens to test for in the javascript
        String[] searchTokens = {
           "test1_required()",
           "this[0] = new Array(\"test1:txt_name\");"
        };

        // none of search tokens exist..
        checkScriptForNotExist(htmlSnippet, searchTokens);
    }

    private void checkScriptForNotExist(StringBuffer htmlSnippet, String[]
searchTokens) {
        for (int i = 0; i < searchTokens.length; i++) {
            Assert.assertFalse("Found: " + searchTokens[i], (
htmlSnippet.indexOf(searchTokens[i]) != -1));
        }
    }
/*-------------------------------------------------------------------*/

hope the issue is clear enough...

best regards,


Hasan...