< f:facet>是什么?以及何时应该使用它? [英] What does <f:facet> do and when should I use it?

查看:138
本文介绍了< f:facet>是什么?以及何时应该使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用标签<f:facet>时遇到了麻烦.我正在使用使用它的代码的其他示例,但是我不确定它的用途是什么.

I have been having trouble with the tag <f:facet>. I am working form other examples of code which use it, but I'm not sure exactly what purpose it serves.

我写了一些代码,该方法在方法上与我看到的可以工作的其他代码完全相同,只是其中的代码包装在<f:facet name=actions>标记中.当我在代码周围添加此代码时,我将其包裹的下拉框在部署时会消失.有人能够提出这个原因或让我深入了解如何以及何时使用构面吗?

I have written some code which in method is exactly the same as other code I have seen which works, except there's is wrapped in a <f:facet name=actions> tag. When I add this around my code the drop down box I am wrapping it around disappears when I deploy. Anyone able to suggest a reason for this or give me an insight into how and when to use facet?

这是我的代码,我不会费心添加Bean代码,因为它们只是基本的getter和setter,而且我认为它们不会造成麻烦.

Here is my code, I won't bother adding the bean code as they're just basic getters and setters and I don't think they're causing the trouble.

<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那样正常工作.

If I remove the facet tag the dropdown box displays, but doesn't function as it should with the beans.

推荐答案

构面代表容器组件中的命名部分.例如,您可以为dataTable组件创建页眉和页脚构面. https://web.archive.org/web/20170828020413/http://www.jsftoolbox.com/documentation/help/12-TagReference/core/f_facet.html

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

当您要创建使用来自用户的某些代码的组件(例如包装器)时,这很有用.

It's useful when you want to create component that uses some code from user (let's say wrapper).

即.当您要创建隐藏长文本并显示短文本的组件时.您可以只使用元素主体,但是您将仅获得一个值,如果您想从用户那里获得简短和长版本,那么您就不能在一个值中做到这一点(不使用任何判别式),只需使用facet和请说哪个是长版本,哪个是短版本.

ie. when you want to create component that hides long text and shows short version of it. You can use just the element body, but then you will get only one value, if you want to get from user the short AND the long version then you can not do it in one value (without using some discriminant), just use facet and say which one is the long and which is the short version.

<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模板完成此操作,但我希望您能做到.

Yes, this can (and should) be done with jsf templating, but I hope you got it.

要提出的问题:您仅在野生xml中定义了facet,没有人要求它,所以也没有人处理它-这就是为什么它没有引发错误或不显示任何内容的原因.

To question: you defined facet just in the wild xml, nobody requested it so nobody processed it - that's why it did not throw error nor showed anything.

这篇关于&lt; f:facet&gt;是什么?以及何时应该使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆