1

我有我的 login.xhtml 文件

<!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>

我有这个用于打印 dom 组件树的实用程序:

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

输出是这样的:

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)

但我不明白为什么这不打印 f:facet 标签内的组件。(第一个h:outputLabel...p:commandButton...没有打印 - 只是 f:facet 标签内的组件)

如何访问 f:facet 中的组件?

你能帮我吗,

谢谢

4

1 回答 1

3

好吧,因为一个方面是一个方面,而不是一个孩子。您可以通过简单地使用getFacets()方法而不是getChildren().

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

键代表构面名称。getFacet()您甚至可以通过快捷方式获得特定方面。

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

您可以通过方法获得一个在构面和子代上的迭代器getFacetsAndChildren()

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

现在是学习查找和探索 javadocs 的时候了。所有这些答案都已经在那里了。

于 2013-11-13T02:24:40.010 回答