I have my login.xhtml file

<!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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<h:head>
</h:head>
<f:event listener="#{seguridadMB.doManageEvents}" type="preRenderView" />
<h:body>
    <h:outputStylesheet name="css/default.css" />
    <h:outputStylesheet name="css/jquery-silk-icons.css" />
    <h:form prependId="false" id="form_login">
    <p:growl id="messages" />
    <p:panelGrid columns="2" styleClass="center">
        <f:facet name="header">
            <h:outputLabel value="#{msg['login.dialogTitle']}" />
        </f:facet>

        <h:outputLabel for="j_username" value="#{msg['login.username']}: *" />
        <p:inputText id="j_username" value="#{seguridadMB.username}"
            required="true" label="#{msg['login.username']}" />

        <h:outputLabel for="j_password" value="#{msg['login.password']}: *" />
        <p:password id="j_password" value="#{seguridadMB.password}"
            required="true" label="#{msg['login.password']}" />

        <f:facet name="footer">
            <div class="column-center">
                <p:commandButton type="submit" ajax="false"
                    value="#{msg['login.signin']}" icon="silk-icon-door-in"
                    action="#{seguridadMB.doLogin}" style="margin:0" update="messages" />
            </div>
        </f:facet>

    </p:panelGrid>
</h:form>

And I have this utility for print the dom component tree:

http://www.jroller.com/cschalk/entry/a_jsf_phaselistener_to_print

And the output is this:

20:08:17,522 INFO  [stdout] (http-localhost-127.0.0.1-8180-4) j_id1 (javax.faces.component.UIViewRoot)
20:08:17,522 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)   |
20:08:17,523 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)   j_idt1 (com.sun.faces.facelets.compiler.UIInstructions)
20:08:17,523 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)   |
20:08:17,524 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)   j_idt2 (com.sun.faces.facelets.compiler.UIInstructions)
20:08:17,524 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)   |
20:08:17,525 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)   j_idt3 (javax.faces.component.UIOutput)
20:08:17,525 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)   |
20:08:17,526 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)   j_idt4 (javax.faces.component.html.HtmlBody)
20:08:17,526 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)     |
20:08:17,527 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)     form_login (javax.faces.component.html.HtmlForm)
20:08:17,528 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)       |
20:08:17,528 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)       messages (org.primefaces.component.growl.Growl)
20:08:17,529 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)       |
20:08:17,529 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)       j_idt7 (org.primefaces.component.panelgrid.PanelGrid)
20:08:17,530 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)         |
20:08:17,531 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)         j_idt9 (javax.faces.component.html.HtmlOutputLabel)
20:08:17,532 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)         |
20:08:17,532 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)         j_username (org.primefaces.component.inputtext.InputText)
20:08:17,533 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)         |
20:08:17,534 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)         j_idt10 (javax.faces.component.html.HtmlOutputLabel)
20:08:17,534 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)         |
20:08:17,535 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)         j_password (org.primefaces.component.password.Password)
20:08:17,536 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)   |
20:08:17,536 INFO  [stdout] (http-localhost-127.0.0.1-8180-4)   j_idt12 (com.sun.faces.facelets.compiler.UIInstructions)

But I dont find why this not print the components inside f:facet tag. (first h:outputLabel... and the p:commandButton... is not printed - just the components inside f:facet tag)

How to acces to components inside f:facet?

Can you help me please,

Thanks

有帮助吗?

解决方案

Well, because a facet is a facet, not a child. You can get facets by simply using getFacets() method instead of getChildren().

Map<String, UIComponent> facets = component.getFacets();

The key represents the facet name. You can even get a specific facet by getFacet() shortcut.

UIComponent facet = component.getFacet("name");

You can get an iterator over facets and children by getFacetsAndChildren() method.

Iterator<UIComponent> iter = component.getFacetsAndChildren();

It's time to learn to find and explore the javadocs. All those answers were already in there.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top