58

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.

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?

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>

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

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
hello123
  • 951
  • 2
  • 15
  • 25
  • 2
    What is the container of the facet? A facet by itself is useless if the container that it is in does not support a facet with that name. So your title (question) is kind of not very much related to your problem. Do you think the answer is what you need, then please accept it – Kukeltje Feb 15 '16 at 17:01

1 Answers1

22

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).

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>

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

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.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Flowy
  • 420
  • 1
  • 5
  • 15
  • Why do components like h:column need a wrapper? Please explain that too. – Navin Israni Sep 09 '17 at 10:02
  • In linked example, the use is obvious. You get header in facet and then children of h:column (in example it is h:outputText) is real content of column. You need to distinguish them. (if header is just plain text then you could use argument of h:column but then you have problem to define css and other things ...) – Flowy Sep 10 '17 at 18:47
  • Where you see syntax error and why you think this example is bad? – Flowy Nov 22 '17 at 13:47