Bonjour à tous,

Je rencontre actuellement un problème lors de la création de composants JSF 2.0.

J'ai créé un simple composant myPanel (myPanel.xhtml) que j'ai placé dans WebContent/resources/components/

Voici son code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jsf/composite"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:f="http://java.sun.com/jsf/core">
 
<c:interface>
	<c:attribute name="title" displayName="title" type="java.lang.String" />
</c:interface>
 
<c:implementation>
	<h:panelGrid>
		<h:panelGroup>
			<h:outputText value="#{cc.attrs.title}" />
		</h:panelGroup>
		<h:panelGroup>
			<c:insertChildren />
		</h:panelGroup>
	</h:panelGrid>
</c:implementation>
 
</html>
Dans une autre page.xhtml j'utilise ce composant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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:cc="http://java.sun.com/jsf/composite/components">
 
<h:body>
	<ui:composition template="/templates/mainLayout.xhtml">
		<ui:define name="container">
			<h:form id="hfFindComponent" prependId="false">
				<cc:myPanel title="MyPanel">
					<h:inputText id="hitTestInput" />
					<p:commandButton value="Afficher"
						actionListener="#{sandboxManagedBean.findComponentTest}" />
				</cc:myPanel>
			</h:form>
		</ui:define>
	</ui:composition>
</h:body>
Et voici la méthode le sandboxManagedBean
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
/**
 * Sandbox.
 */
@ManagedBean
@SessionScoped
public class SandboxManagedBean implements Serializable {
    /** Generated serial version uid. */
    private static final long serialVersionUID = 6643045015184528216L;
 
    /**
     * Afficher un composant en utilisant la méthode findComponent.
     * 
     * @param pAe
     *            événement
     * @return regle de navigation vide.
     */
    public String findComponentTest(final ActionEvent pAe) {
        final FacesContext fc = FacesContext.getCurrentInstance();
        final UIViewRoot root = fc.getViewRoot();         
        return "";
    }
}
Si je place un point d'arret sur l'attribut root, mon composant UIInput (avec id hitTestInput) n'est pas présent dans l'arbre de composants.

Par contre si je n'utilise pas mon composant personnalisé, le UIInput est bien présent dans l'arbre de composants (ViewRoot) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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:cc="http://java.sun.com/jsf/composite/components">
 
<h:body>
	<ui:composition template="/templates/mainLayout.xhtml">
		<ui:define name="container">
			<h:form id="hfFindComponent" prependId="false">				
				<h:inputText id="hitTestInput" />
				<p:commandButton value="Afficher"
					actionListener="#{sandboxManagedBean.findComponentTest}" />				
			</h:form>
		</ui:define>
	</ui:composition>
</h:body>

A noter que dans les deux cas (utilisation ou non de mon composant) la méthode root.findComponent("hitTextInput") me retourne null.
Après vérification sur Internet, il semble que ce soit un bug :
http://blogs.itemis.de/frey/2008/10/...t-recursively/

J'ai donc créé une méthode récursive findComponent comme sur l'exemple.
Lors de l'utilisation de mon composant la méthode retourne null mais lorsque je n'utilise pas le composant, la méthode me retourne bien le UIInput.

Avez-vous déjà rencontré le problème ? Peut-être ai-je oublié de spécifier quelque chose lors de la création de mon composant ?

Merci d'avance pour votre aide et désolé pour le pavé de texte

Cordialement,