users@glassfish.java.net

JSF 2.0 Custom Components Problem

From: <forums_at_java.net>
Date: Thu, 30 Jun 2011 09:20:44 -0500 (CDT)

Hello everyone

I have a problem when i create a custom component in JSF 2.0
I've created a simple component "myPanel". I put it in
WebContent/resources/components folder.

Here's the code of the component :
[code]
<?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>
[/code]

In another xhtml page, i use this component :
[code]
<?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>
[/code]

And here's the sandboxManagedBean with the findComponentTest method :
[code]
/**
 * Sandbox.
 */
@ManagedBean
@SessionScoped
public class SandboxManagedBean implements Serializable {
    /** Generated serial version uid. */
    private static final long serialVersionUID = 6643045015184528216L;
    /**
     * Test method
     *
     * @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 "";
    }
}
[/code]

If i put a breakpoint on the roor attribute, my component UIInput (with the
id "hitTestInput") is not present on the ViewRoot.

But if a don't use my component, the UIInput is present on the ViewRoot:
[code]
<?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>
[/code]
Please note that in the two cases (use or not the component), the
root.findcomponent("hitTextInput") return NULL.

After searching on google, it seems there is a bug on the findComponent
method
[url]http://blogs.itemis.de/frey/2008/10/17/javaserver-faces-find-component-recursively/[/url]

So i've created one like the previous example. If i use my custom component,
this new method return null but if i don't use MyPanel component, the method
return the UIInput.

Have you already met this problem ?

Thanks in advance for you help.
PS : sorry if my english isn't correct but i'm a french user of JSF 2.0 :)


--
[Message sent by forum member 'rdeoliveira']
View Post: http://forums.java.net/node/817127