我有我的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中的组件?
请你帮帮我吧,
由于
答案 0 :(得分:3)
嗯,因为一个方面是一个方面,而不是一个小孩。您只需使用getFacets()
方法而不是getChildren()
即可获得方面。
Map<String, UIComponent> facets = component.getFacets();
键代表构面名称。您甚至可以通过getFacet()
快捷方式获得特定方面。
UIComponent facet = component.getFacet("name");
您可以通过getFacetsAndChildren()
方法在facets 和子项上获得迭代器。
Iterator<UIComponent> iter = component.getFacetsAndChildren();
是时候学习寻找和探索javadoc了。所有这些答案都已经存在。