Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use f:metadata JSF tag?

Tags:

metadata

jsf

I have a view that is included in another view. I'm running into problems with f:metadata in the included view. Not sure how to go about it. I've updated both views and restarted the server. No luck.

Parent view

<ui:include src="sub_entityIndexPagination.xhtml">
    <ui:param name="entityIndexBean" value="#{articleIndexBean}"/>
</ui:include>

Sub view

<ui:composition 
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:c="http://java.sun.com/jsp/jstl/core"      
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  >

<f:metadata>
    <f:viewParam name="pn" value="#{entityIndexBean.currentEntityPageNumber}" />
     <f:event type="preRenderView" listener="#{entityIndexBean.toCurrentEntityPage()}" />
</f:metadata>

<c:forEach var="pageNumber" begin="1" end="${entityIndexBean.getEntityPageCount()}">   
    <h:outputLink value="ar_index.xhtml">
        <h:outputText value="${pageNumber}" />
            <f:param name="pn" value="${pageNumber}" />
    </h:outputLink> 
</c:forEach>

JSF Implementation

c:\tomee16\lib\myfaces-api-2.1.13.jar

Error

/sub_entityIndexPagination.xhtml at line 9 and column 14 <f:metadata> Parent UIComponent j_id_9 should be instance of UIViewRoot

phaseId=RENDER_RESPONSE(6)

Caused by:
javax.faces.view.facelets.TagException - /sub_entityIndexPagination.xhtml at line 9 and column 14 <f:metadata> Parent UIComponent j_id_9 should be instance of UIViewRoot
at org.apache.myfaces.view.facelets.tag.jsf.core.ViewMetadataHandler.apply(ViewMetadataHandler.java:60)
like image 984
jacekn Avatar asked Feb 15 '14 20:02

jacekn


2 Answers

The <f:metadata> can't be declared in an include file. It has to be declared in the top view (the file which you indicated as "parent view"). It should be exactly that view which is directly referenced by the request URL.

That said, it's completely wrong to have a <html> in an include file. You're this way effectively nesting <html> tags which only results in syntactically invalid HTML. It would probably be worth the effort to take a JSF pause and learn some basic HTML first. JSF is ultimately just a HTML code generator.

like image 191
BalusC Avatar answered Nov 07 '22 11:11

BalusC


Another reason this might show up is if there is any tag, including , between <ui:composition> and <f:metadata> in facelets.

e.g:

Good:

<ui:composition 
...
template="..."> 
<f:metadata>
    <f:viewParam ...

Also OK, in case you need to set params on f:view:

<ui:composition 
...
template="..."> 
<f:view ...params goes here... /> <!-- ends here, does not enclose anything -->
<f:metadata>
    <f:viewParam ...

Bad:

<ui:composition 
...
template="...">
<f:view>  <!-- you don't even need this with facelets unless you want to pass in parameters. --> 
<f:metadata>
    <f:viewParam ...
</f:view> <!--f:view encloses f:metadata so f:metadata is no longer a direct  child of UIViewRoot. -->

Full explanation from Jakob Korherr is available here: https://mail-archives.apache.org/mod_mbox/myfaces-users/201104.mbox/%[email protected]%3e

like image 4
Erik I Avatar answered Nov 07 '22 13:11

Erik I