2

What is the best way to use f:importConstants inside of a composite component? You can't place f:metadata there, so what is the best workaround here? With Omnifaces and o:importConstants in JSF 2.2, that was no problem, it was allowed everywhere, even in composite component.

Thanks in Advance :)

jheider
  • 111
  • 8
  • Do you get an error if you do just put it in there? – Kukeltje Feb 07 '19 at 14:24
  • no, it is just not working – jheider Feb 07 '19 at 14:28
  • Also if you just add a `f:metadata` in there as well and iside it the `f:importConstants`? (although it indeed is not the place to add for other usefull things, it might just do the trick) – Kukeltje Feb 07 '19 at 14:37
  • neither putting `f:importConstants` directly in the composite nor putting it inside a `f:metadata` inside of the composite works (which might be right from specs). Putting the `f:importConstants` in the `f:metadata` of the facelet which uses the composite component works. but in terms of reusability, this may not be the solution – jheider Feb 07 '19 at 14:45
  • Reusability in 'code completion' in an IDE you mean? – Kukeltje Feb 07 '19 at 17:57
  • Reusability of the composite component, without knowledge of the "internals" of the component, if I always have to look up, which constants it imports, to add the import in the faclet. – jheider Feb 07 '19 at 18:04
  • Ok, then why not still use or try `o:importConstants`? – Kukeltje Feb 07 '19 at 18:29
  • Yes of course, this is working and im doing so at the moment. But `o:importConstants` is marked as deprecated since 3.0. Don't know, if it is planned to be removed soon. I'm just asking, if there is another solution in JSF, I don't see at the moment. – jheider Feb 07 '19 at 19:03
  • 1
    Then file an issue with OmniFaces to request to not remove it since there is a specifc usecase where the plain jsf one does not work. Reference this question. @BalusC is often (always?) very cooperative – Kukeltje Feb 07 '19 at 19:34
  • 1
    It's indeed already been un-deprecated for this reason. – BalusC Jul 10 '20 at 11:47

1 Answers1

1

Since <f:importConstants> must be a child of <f:metadata> (which in turn must be a child of <f:view>), it must use same compositing pattern as described in the official documentation:

The implementation must allow templating for this element according
 to the following pattern.

template client XHTML view, view01.xhtml

    <ui:composition template="template.xhtml">
        <ui:define name="metadata">
          <f:metadata>
            <f:viewParam name="id"/>
          </f:metadata>
        </ui:define>
        <ui:define name="content">
            <h1>The big news stories of the day</h1>
        </ui:define>
    </ui:composition> 

Note line 4. The page author must ensure that the <f:metadata> element does not 
appear on a template or included page. It must reside on the root page that 
corresponds to the viewId.

The template page, template.xhtml

    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
          xmlns:f="http://xmlns.jcp.org/jsf/core"
          xml:lang="en" lang="en">
     
    <body>
    <f:view>
       
            <ui:insert name="metadata"/>
       
        <div id="container">
            <ui:insert name="content"/>
        </div>
    </f:view>
    </body>
    </html>
MestreLion
  • 12,698
  • 8
  • 66
  • 57