dev@javaserverfaces.java.net

f:event preValidate - automatic readout question

From: <nanoinverno_at_web.de>
Date: Sun, 17 Oct 2010 23:01:20 +0200 (CEST)

Hello,

I am quite new to JSF and have a question about the automatic readout of a ComponentSystemEvent by a preValidation-Method.

    public void preValidate( ComponentSystemEvent evt )
    {
        UIForm form = (UIForm) evt.getComponent();
        for ( int i = 0; i < beanFields.length; i++ )
        {

            String c_name = beanFields[i].getName();
            UIComponent componente = findComponentRecursive( form, c_name );
            
            ...
        }
    }

The fields in the bean must have the same name as the id of the component. The own method findComponentRecursive() uses findComponent() to find the component recursively. The method calls itself if the actual component is not the right one and has children.
The JSF-form is build up of some composite components and there my problem occurs. If there are to many CCs interlaced the component cannot be found.

The form works, the values inserted pass the JSF-validator and are saved to the bean, but my validator is not called.

Some more information about the JSF code:

    index.xhtml > form.xhtml
    index.xhtml > inputText.xhtml > layout.xhtml > label.xhtml

index.xhtml

    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:form="http://java.sun.com/jsf/composite/components/form">
    ...
        <form:form id="validatorTest" vali="#{testValidator}">
            <form:inputText ident="einString" beanField="#{testBean.einString}" />
        </form:form>
    ...
    </html>

form.xhtml

    <composite:interface>
        <composite:attribute name="ident" default="form" />
        <composite:attribute name="vali" shortDescription="validator used i.e. #{myValidator}" />
    </composite:interface>
    <composite:implementation>
        <h:form id="#{cc.attrs.ident}">
            <f:event type="preValidate" listener="#{cc.attrs.vali.preValidate}" />
            <composite:insertChildren />
            ...(send-button)...
        </h:form>
    </composite:implementation>

inputText.xhtml

    ...
    xmlns:st="http://java.sun.com/jsf/composite/components/form/subtemplates"
    ...

    <composite:interface>
        <composite:attribute name="ident" required="true" />
        <composite:attribute name="beanField" required="true" shortDescription="the bean-var, i.e. #{myBean.myVar}" />
        <composite:attribute name="label" shortDescription="label for this input field" />
    </composite:interface>
    <composite:implementation>
        <st:layout>
            <h:inputText id="#{cc.attrs.ident}" value="#{cc.attrs.beanField}" />
        </st:layout>
    </composite:implementation>

layout.xhtml

    <composite:interface>
    </composite:interface>
    <composite:implementation>
        <h:panelGrid columns="4" columnClasses="form_tableLabel,form_tableInput">
            <st:label ident="#{cc.parent.attrs.ident}" label="#{cc.parent.attrs.label}" />
            <composite:insertChildren />
        </h:panelGrid>
    </composite:implementation>

label.xhtml only displays the label for the input field.

The component is rendered with an id like "validatorTest:form:j_idt47:j_idt48:einString" where j_idt47 is the inputText-composite and j_idt48 is the layout-composite. if I put the <h:inputText> field directly into <composite:implementation> of inputText.xhtml, the part "j_idt48" is gone an the preValidation works.
In my recursive method the component with the ID "j_idt48" has no children an is a NamingContainer.
I tried to use a facet instead of composite:insertChildren in layout.xhtml but it was the same result.

Is there a (better) way to find all input fields of the form submitting the ComponentSystemEvent to my method?

Can anyone help me with that?

I'm using the Mojarra 2.0.3 FCS jsf-libs in a Tomcat 6.0.29, JRE-sun 1.6.0.20. Eclipse Helios

Thanks!
Benjamin
___________________________________________________________
WEB.DE DSL Doppel-Flat ab 19,99 &euro;/mtl.! Jetzt auch mit
gratis Notebook-Flat! http://produkte.web.de/go/DSL_Doppel_Flatrate/2