jsf - <f :facet> do and when should I use it? 是什么意思

标签 jsf primefaces xhtml facet

我在使用标签 <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/

相关文章:

SelectItem 标签中的 JSF 链接

jsf - PrimeFaces 扩展 CKEditor : attempts to set encoding to UTF-8 unsuccessful

jsf - 对话框不会关闭 primefaces

php - 回显一个 XHTML 标签

HTML - 当使用 UTF-8 或 ISO-8859-1 时,我还需要输入特殊字符的代码吗?

XSLT 转换以生成有效的 XHTML : a namespace issue

java - 简单的 JSF 应用程序给出 Jasper 异常,引用属性名称是唯一的

java - 为什么a(Map对象)的值的数据类型改变了?

jsf - 如何通过 clientId 访问复合组件的兄弟

jsf - LocalDate(仅限)与 primefaces 日历