Skip to main content

JSF2 - f:event preValidate - automatic readout question

1 reply [Last post]
nanoinverno
Offline
Joined: 2010-10-17
Points: 0

Hello,

I am quite new to JSF and have a question about the automatic readout of a ComponentSystemEvent by a preValidation-Method. I'm not sure if this forum is the right one for this problem but maybe someone can help me :)

<br />
	public void preValidate( ComponentSystemEvent evt )<br />
	{<br />
		UIForm form = (UIForm) evt.getComponent();<br />
		for ( int i = 0; i < beanFields.length; i++ )<br />
		{</p>
<p>			String c_name = beanFields.getName();<br />
			UIComponent componente = findComponentRecursive( form, c_name );</p>
<p>			...<br />
		}<br />
	}

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

</p>
<p>	...</p>
<p>	...<br />
	

form.xhtml

</p>
<p>			...(send-button)...</p>
<p>	

inputText.xhtml

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

layout.xhtml

</p>
<p>	

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 field directly into 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]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

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nanoinverno
Offline
Joined: 2010-10-17
Points: 0

I found my mistake:

I used [b]UIComponent.getChildren()[/b] in my recursive method and got the following components:

[code]Level: 0 | validatorTest:form | Family: javax.faces.Form | Children: 8
Level: 1 | validatorTest:form:j_idt47 | Family: javax.faces.NamingContainer | Children: 0
Level: 1 | validatorTest:form:j_idt61 | Family: javax.faces.Output | Children: 0
Level: 1 | validatorTest:form:j_idt62 | Family: javax.faces.Command | Children: 0
Level: 1 | validatorTest:form:j_idt63 | Family: javax.faces.Output | Children: 0[/code]

...but I have to use [b]UIComponent.getFacetsAndChildren()[/b] to get that deep I want to

[code]Level: 0 | validatorTest:form | Family: javax.faces.Form | Children: 8 | Facets: 0
Level: 1 | validatorTest:form:j_idt47 | Family: javax.faces.NamingContainer | Children: 0 | Facets: 1
Level: 2 | validatorTest:form:j_idt47:j_id3 | Family: javax.faces.Panel | Children: 1 | Facets: 0
Level: 3 | validatorTest:form:j_idt47:j_idt48 | Family: javax.faces.NamingContainer | Children: 0 | Facets: 1
Level: 4 | validatorTest:form:j_idt47:j_idt48:j_id3 | Family: javax.faces.Panel | Children: 1 | Facets: 0
Level: 5 | validatorTest:form:j_idt47:j_idt48:j_idt49 | Family: javax.faces.Panel | Children: 4 | Facets: 0
Level: 6 | validatorTest:form:j_idt47:j_idt48:j_idt50 | Family: javax.faces.NamingContainer | Children: 0 | Facets: 1
Level: 7 | validatorTest:form:j_idt47:j_idt48:j_idt50:j_id3 | Family: javax.faces.Panel | Children: 1 | Facets: 0
Level: 8 | validatorTest:form:j_idt47:j_idt48:j_idt50:j_idt51 | Family: javax.faces.Column | Children: 1 | Facets: 0
Level: 9 | validatorTest:form:j_idt47:j_idt48:j_idt50:j_idt52 | Family: javax.faces.Output | Children: 0 | Facets: 0
Level: 6 | validatorTest:form:j_idt47:j_idt48:einString | Family: javax.faces.Input | Children: 0 | Facets: 0
Level: 1 | validatorTest:form:j_idt61 | Family: javax.faces.Output | Children: 0 | Facets: 0
Level: 1 | validatorTest:form:j_idt62 | Family: javax.faces.Command | Children: 0 | Facets: 0
Level: 1 | validatorTest:form:j_idt63 | Family: javax.faces.Output | Children: 0 | Facets: 0[/code]

and there it is, "einString", and my Validator can handle the input :)

Benjamin