我有一个页面,我需要在 <f:facet name="last>
中嵌套一些组件。 ,以便应用自定义样式(我正在使用 Primefaces,这是他们处理 CSS 优先顺序的方式,如前所述 here )。但是我无法渲染 <f:facet>
中的任何内容标签。
下面是一些示例代码:
<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>
<title>TODO supply a title</title>
</h:head>
<h:body>
<div>
<h:form>
<h:outputLabel for="loginField" value="Login:" styleClass="form-label"/>
<p:inputText id="loginField" value="#{subscriptionBean.login}" styleClass="form-field"/>
<f:facet name="last">
<h:outputLabel for="pwd2" value="Password:" styleClass="form-label"/>
<p:password id="pwd2" value="#{subscriptionBean.password}" required="true" match="pwd1" styleClass="form-field"/>
<p:message for="pwd2" display="text" styleClass="form-field"/>
</f:facet>
</h:form>
</div>
</h:body>
难道我不能在生成的页面中看到密码输入字段吗?它根本不显示。
根据 starf 的回答,这里有一些示例代码:
<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>
<f:facet name="last">
<h:outputStylesheet library="css" name="default.css"/>
</f:facet>
</h:head>
<h:body>
<h:outputText value="Rendered text!"/>
<h:form>
<h:outputLabel for="pdw1" value="Password: "/>
<p:password id="pwd1" required="true"/>
<p:message for="pwd1"/>
</h:form>
</h:body>
以及生成的渲染页面标题:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link type="text/css" rel="stylesheet" href="/AquitelManagement/faces/javax.faces.resource/default.css?ln=css" />
<link type="text/css" rel="stylesheet" href="/AquitelManagement/faces/javax.faces.resource/primefaces.css?ln=primefaces&v=5.0.RC2" />
<script type="text/javascript" src="/AquitelManagement/faces/javax.faces.resource/jquery/jquery.js?ln=primefaces&v=5.0.RC2">
</script><script type="text/javascript" src="/AquitelManagement/faces/javax.faces.resource/jquery/jquery-plugins.js?ln=primefaces&v=5.0.RC2">
</script>
<script type="text/javascript" src="/AquitelManagement/faces/javax.faces.resource/primefaces.js?ln=primefaces&v=5.0.RC2">
</script>
</head>
<body>...
最佳答案
您正在尝试在 h:form 标记上注册一个构面。链接中的示例注册在 h:head 标签上。 Primefaces 有一个自定义的头部渲染器。
没有为表单定义这样的方面,所以它不知道如何处理它。另见 <f:facet> not working with <h:form>
我相信您混淆了 css 排序问题。如果您希望覆盖 PrimeFaces css,请在头部使用“最后”方面 - 这会将您的 css 定义置于 primefaces css 之下。
<h:head>
<f:facet name="last">
<h:outputStylesheet library="default" name="css/style.css" />
</f:facet>
</h:head>
参见 http://www.mkyong.com/jsf2/primefaces/resource-ordering-in-primefaces/一个很好的解释。
关于css - JSF <f :facet> contents not rendered,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25251019/