我在使用标签 <f:facet>
时遇到了问题。我正在编写使用它的其他代码示例,但我不确定它到底有什么用途。
我编写了一些代码,其方法与我见过的其他有效代码完全相同,只是其中包含在 <f:facet name=actions>
中。标签。当我在代码中添加此内容时,我将其包裹的下拉框在部署时消失。任何人都可以提出一个原因,或者让我深入了解如何以及何时使用facet?
这是我的代码,我不会费心添加 bean 代码,因为它们只是基本的 getter 和 setter,我不认为它们会造成麻烦。
<f:facet name="actions">
<p:selectOneMenu id="SwitchWeekDrpDwnMenu"
value="#{depotWorkloadBean.selectView}"
partialSubmit="true">
<p:ajax update="mainForm"
listener="#{depotWorkloadBean.updateView}" />
<f:selectItem itemLabel="Day view" itemValue="Day"/>
<f:selectItem itemLabel="01/01/2014" itemValue="Week"/>
</p:selectOneMenu>
</f:facet>
如果我删除facet标签,下拉框会显示,但不会像bean那样发挥作用。
最佳答案
A facet represents a named section within a container component. For example, you can create a header and a footer facet for a dataTable component. https://web.archive.org/web/20170828020413/http://www.jsftoolbox.com/documentation/help/12-TagReference/core/f_facet.html
当您想要创建使用用户的某些代码(比方说包装器)的组件时,它非常有用。
即。当您想要创建隐藏长文本并显示其短版本的组件时。您可以只使用元素主体,但是您只会得到一个值,如果您想从用户那里获取短版本和长版本,那么您不能用一个值来做到这一点(不使用一些判别式),只需使用facet和说出哪个是长版本,哪个是短版本。
<textShortener>
<f:facet name="short">
This text is short.
</f:facet>
<f:facet name="long">
This text is too <b>long</b> to be showed when page loads. User have to click the button after the short text to show this.
</f:facet>
</textShortener>
是的,这可以(并且应该)通过 jsf 模板来完成,但我希望你明白了。
提问:您只是在狂野的 xml 中定义了facet,没有人请求它,所以没有人处理它 - 这就是为什么它没有抛出错误,也没有显示任何内容。
关于jsf - <f :facet> do and when should I use it? 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25162407/