Hi Stephen, an additional example with the use of templates would be -> template.xhtml :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" > <f:view locale="#{localeHandler.aktuelleLocale}" contentType="text/html"> <ui:insert name="metadata"/> <h:head> ................................. you can then decide on every page if you need the metatdata or not -> pageX.xhtml: <body> <ui:composition template="/templates/template.xhtml"> <ui:define name="metadata"> <f:metadata> <f:viewParam name="xxxx" value="#{bean.xxxx}" /> </f:metadata> </ui:define> .......... best regards Thomas -----Ursprüngliche Nachricht----- Von: sethfromaust...@gmail.com [mailto:sethfromaust...@gmail.com] Im Auftrag von Jakob Korherr Gesendet: Freitag, 29. April 2011 13:09 An: MyFaces Discussion Betreff: Re: [NOT SOLVED] Re: JSF2 f:metadata and templates what the feck am I doing wrong? Hi Stephen, This actually is a very common mistake people make with JSF 2. The problem is the following: As you correctly pointed out, f:metadata needs to be a direct child of f:view. However, with facelets f:view is handled very differently then with JSP. In JSP you need f:view as the root tag for every other JSF tag, but in facelets the UIViewRoot is always the xml root tag (the most outer tag with the xmlns attributes). Thus in JSF 2 when using facelets, UIViewRoot is most certainly created by the following code: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> This means that you have to place f:metadata as a direct child of the above root element, for example: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <f:metadata>....</f:metadata> </html> This will make it work ;) Also, as an explanation why there still is a f:view tag for facelets also: Since you need some kind of way to set the attributes of f:view (like e.g. locale), you still need the f:view tag. However, it does not create an additional UIViewRoot, but only pass through the attributes to the already existing UIViewRoot. Thus you will use it in this way: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <f:metadata>....</f:metadata> <f:view locale="...." /> <h:head>...</h:head> <h:body>...</h:body> </html> I hope this helps ;) Regards, Jakob 2011/4/29 Stephen Connolly <stephen.alan.conno...@gmail.com>: > If I change the template to > > */WEB-INF/templates/basic.xhtml* > > <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC > "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:ui=" > http://java.sun.com/jsf/facelets" > > xmlns:h="http://java.sun.com/jsf/html" xmlns:f=" > http://java.sun.com/jsf/core"> > <ui:insert name="metadata"/> > <html> > <h:head> > <ui:insert name="header"/> > </h:head> > <h:body> > <ui:insert name="content"/> > </h:body> > </html> > </f:view> > > > Then it seems to work... but the tagdocs on > http://javaserverfaces.java.net/nonav/docs/2.0/vdldocs/facelets/f/meta > data.html > say > it should work the way I had things originally.... strange > > On 29 April 2011 10:23, Stephen Connolly <stephen.alan.conno...@gmail.com>wrote: > >> Spoke too soon >> >> :-( >> >> I'd been checking to see if it was the servlet mapping that was >> causing the issues, so I changed the mapping from *.xhtml to >> *.faces... and I'd forgotten to change the url in my browser, so I >> was being served the raw .xhtml which was rendering the <h2> as a <h2>... >> >> removing the com.sun.faces.validateXml had no effect >> >> The problem still exists! >> >> HELP! >> >> -Stephen >> >> >> On 29 April 2011 10:10, Stephen Connolly <stephen.alan.conno...@gmail.com>wrote: >> >>> Ok, I just found the/a solution. >>> >>> that was to remove >>> >>> <context-param> >>> <param-name>com.sun.faces.validateXml</param-name> >>> <param-value>true</param-value> >>> </context-param> >>> >>> from the web.xml >>> >>> For some reason this completely ruins the f:metadata tag >>> >>> Not sure if that is a bug or a "feature" but might as well post the >>> solution anyway so that others might benefit >>> >>> -Stephen >>> >>> On 29 April 2011 10:08, Stephen Connolly >>> <stephen.alan.conno...@gmail.com >>> > wrote: >>> >>>> Myfaces 2.0.5. >>>> >>>> I have been reading the JSF docs on the f:metadata tag..., e.g. >>>> http://javaserverfaces.java.net/nonav/docs/2.0/vdldocs/facelets/f/m >>>> etadata.htmland >>>> http://myfaces.apache.org/core20/myfaces-impl/tlddoc-facelets/index >>>> .html >>>> >>>> I cannot seem to get f:metadata to work, e.g. >>>> >>>> */WEB-INF/templates/basic.xhtml* >>>> >>>> <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC >>>> "-//W3C//DTD XHTML 1.0 Transitional//EN" >>>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> >>>> <html xmlns="http://www.w3.org/1999/xhtml" >>>> xmlns:ui="http://java.sun.com/jsf/facelets" >>>> xmlns:h="http://java.sun.com/jsf/html" >>>> xmlns:f="http://java.sun.com/jsf/core" >>>> > >>>> <h:head> >>>> <ui:insert name="header"/> >>>> </h:head> >>>> <h:body> >>>> <f:view> >>>> <ui:insert name="metadata"/> >>>> <ui:insert name="content"/> >>>> </f:view> >>>> </h:body> >>>> </html> >>>> >>>> >>>> and then reference that template >>>> >>>> */test.xhtml* >>>> <?xml version="1.0" encoding="utf-8"?> <ui:composition >>>> xmlns="http://www.w3.org/1999/xhtml" >>>> xmlns:ui="http://java.sun.com/jsf/facelets" >>>> xmlns:h="http://java.sun.com/jsf/html" >>>> xmlns:f="http://java.sun.com/jsf/core" >>>> template="/WEB-INF/templates/basic.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> >>>> >>>> >>>> whenever i try to access the test.xhtml view I get the following: >>>> >>>> *[In Jetty 8.0.0.M2] >>>> * >>>> >>>> HTTP ERROR 500 >>>> >>>> Problem accessing /test.xhtml. Reason: >>>> >>>> /test.xhtml at line 8 and column 19 <f:metadata> Parent >>>> UIComponent j_id1187866547_41aebe2a should be instance of >>>> UIViewRoot Caused by: >>>> >>>> javax.faces.view.facelets.TagException: /test.xhtml at line 8 and >>>> column >>>> 19 <f:metadata> Parent UIComponent j_id1187866547_41aebe2a should >>>> be instance of UIViewRoot >>>> at >>>> org.apache.myfaces.view.facelets.tag.jsf.core.ViewMetadataHandler.a >>>> pply(ViewMetadataHandler.java:61) >>>> at >>>> org.apache.myfaces.view.facelets.tag.ui.DefineHandler.applyDefiniti >>>> on(DefineHandler.java:86) >>>> at >>>> org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(Co >>>> mpositionHandler.java:167) >>>> at >>>> org.apache.myfaces.view.facelets.impl.TemplateContextImpl$TemplateM >>>> anagerImpl.apply(TemplateContextImpl.java:128) >>>> at >>>> org.apache.myfaces.view.facelets.impl.TemplateContextImpl.includeDe >>>> finition(TemplateContextImpl.java:92) >>>> at >>>> org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.include >>>> Definition(DefaultFaceletContext.java:433) >>>> at >>>> org.apache.myfaces.view.facelets.tag.ui.InsertHandler.apply(InsertH >>>> andler.java:93) >>>> at >>>> javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFa >>>> celetHandler.java:51) >>>> at >>>> org.apache.myfaces.view.facelets.tag.jsf.core.ViewHandler.apply(Vie >>>> wHandler.java:156) >>>> at >>>> javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler >>>> (DelegatingMetaTagHandler.java:59) >>>> at >>>> org.apache.myfaces.view.facelets.tag.jsf.ComponentTagHandlerDelegat >>>> e.apply(ComponentTagHandlerDelegate.java:324) >>>> at >>>> javax.faces.view.facelets.DelegatingMetaTagHandler.apply(Delegating >>>> MetaTagHandler.java:54) >>>> at >>>> javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFa >>>> celetHandler.java:51) >>>> at >>>> org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(Na >>>> mespaceHandler.java:57) >>>> at >>>> javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFa >>>> celetHandler.java:51) >>>> at >>>> org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(Enc >>>> odingHandler.java:45) >>>> at >>>> org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(Defaul >>>> tFacelet.java:322) >>>> at >>>> org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(Defaul >>>> tFacelet.java:369) >>>> at >>>> org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(Defaul >>>> tFacelet.java:347) >>>> at >>>> org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.include >>>> Facelet(DefaultFaceletContext.java:215) >>>> at >>>> org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(Co >>>> mpositionHandler.java:140) >>>> at >>>> org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(Na >>>> mespaceHandler.java:57) >>>> at >>>> org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(Enc >>>> odingHandler.java:45) >>>> at >>>> org.apache.myfaces.view.facelets.impl.DefaultFacelet.apply(DefaultF >>>> acelet.java:143) >>>> at >>>> org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.bui >>>> ldView(FaceletViewDeclarationLanguage.java:327) >>>> at >>>> org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderR >>>> esponseExecutor.java:66) >>>> at >>>> org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.jav >>>> a:239) at >>>> javax.faces.webapp.FacesServlet.service(FacesServlet.java:191) >>>> at >>>> org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:5 >>>> 46) >>>> at >>>> org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.ja >>>> va:483) >>>> at >>>> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler >>>> .java:119) >>>> at >>>> org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.j >>>> ava:516) >>>> at >>>> org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHan >>>> dler.java:230) >>>> at >>>> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHan >>>> dler.java:956) >>>> at >>>> org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.jav >>>> a:411) >>>> at >>>> org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHand >>>> ler.java:188) >>>> at >>>> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHand >>>> ler.java:891) >>>> at >>>> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler >>>> .java:117) >>>> at >>>> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(Co >>>> ntextHandlerCollection.java:247) >>>> at >>>> org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCo >>>> llection.java:151) >>>> at >>>> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapp >>>> er.java:114) at >>>> org.eclipse.jetty.server.Server.handle(Server.java:353) >>>> at >>>> org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnectio >>>> n.java:598) >>>> at >>>> org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComple >>>> te(HttpConnection.java:1059) >>>> at >>>> org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:590) >>>> at >>>> org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:21 >>>> 2) >>>> at >>>> org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java: >>>> 427) >>>> at >>>> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannel >>>> EndPoint.java:510) >>>> at >>>> org.eclipse.jetty.io.nio.SelectChannelEndPoint.access$000(SelectCha >>>> nnelEndPoint.java:34) >>>> at >>>> org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelE >>>> ndPoint.java:40) >>>> at >>>> org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPo >>>> ol.java:450) at java.lang.Thread.run(Thread.java:680) >>>> >>>> >>>> [In Tomcat 7.0.12] >>>> >>>> HTTP Status 500 - >>>> >>>> type Exception report >>>> >>>> message >>>> >>>> description The server encountered an internal error () that >>>> prevented it from fulfilling this request. >>>> >>>> exception >>>> >>>> javax.servlet.ServletException: /test.xhtml at line 8 and column 19 >>>> <f:metadata> Parent UIComponent j_id1187866547_41aebe2a should be >>>> instance of UIViewRoot >>>> javax.faces.webapp.FacesServlet.service(FacesServlet.java:205) >>>> root cause >>>> >>>> javax.faces.view.facelets.TagException: /test.xhtml at line 8 and >>>> column >>>> 19 <f:metadata> Parent UIComponent j_id1187866547_41aebe2a should >>>> be instance of UIViewRoot >>>> org.apache.myfaces.view.facelets.tag.jsf.core.ViewMetadataHandler.a >>>> pply(ViewMetadataHandler.java:61) >>>> >>>> org.apache.myfaces.view.facelets.tag.ui.DefineHandler.applyDefiniti >>>> on(DefineHandler.java:86) >>>> org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(Co >>>> mpositionHandler.java:167) >>>> >>>> org.apache.myfaces.view.facelets.impl.TemplateContextImpl$TemplateM >>>> anagerImpl.apply(TemplateContextImpl.java:128) >>>> org.apache.myfaces.view.facelets.impl.TemplateContextImpl.includeDe >>>> finition(TemplateContextImpl.java:92) >>>> >>>> org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.include >>>> Definition(DefaultFaceletContext.java:433) >>>> org.apache.myfaces.view.facelets.tag.ui.InsertHandler.apply(InsertH >>>> andler.java:93) >>>> >>>> javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFa >>>> celetHandler.java:51) >>>> org.apache.myfaces.view.facelets.tag.jsf.core.ViewHandler.apply(Vie >>>> wHandler.java:156) >>>> >>>> javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler >>>> (DelegatingMetaTagHandler.java:59) >>>> org.apache.myfaces.view.facelets.tag.jsf.ComponentTagHandlerDelegat >>>> e.apply(ComponentTagHandlerDelegate.java:324) >>>> >>>> javax.faces.view.facelets.DelegatingMetaTagHandler.apply(Delegating >>>> MetaTagHandler.java:54) >>>> javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFa >>>> celetHandler.java:51) >>>> >>>> org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(Na >>>> mespaceHandler.java:57) >>>> javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFa >>>> celetHandler.java:51) >>>> >>>> org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(Enc >>>> odingHandler.java:45) >>>> org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(Defaul >>>> tFacelet.java:322) >>>> >>>> org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(Defaul >>>> tFacelet.java:369) >>>> org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(Defaul >>>> tFacelet.java:347) >>>> >>>> org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.include >>>> Facelet(DefaultFaceletContext.java:215) >>>> org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(Co >>>> mpositionHandler.java:140) >>>> >>>> org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(Na >>>> mespaceHandler.java:57) >>>> org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(Enc >>>> odingHandler.java:45) >>>> >>>> org.apache.myfaces.view.facelets.impl.DefaultFacelet.apply(DefaultF >>>> acelet.java:143) >>>> org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.bui >>>> ldView(FaceletViewDeclarationLanguage.java:327) >>>> >>>> org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderR >>>> esponseExecutor.java:66) >>>> org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.jav >>>> a:239) >>>> javax.faces.webapp.FacesServlet.service(FacesServlet.java:191) >>>> note The full stack trace of the root cause is available in the >>>> Apache >>>> Tomcat/7.0.12 logs. >>>> >>>> Apache Tomcat/7.0.12 >>>> >>>> >>>> Which says it's not the container... >>>> >>>> If I try direct with no template, e.g. >>>> >>>> test2.xhtml >>>> <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC >>>> "-//W3C//DTD XHTML 1.0 Transitional//EN" >>>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> >>>> <html xmlns="http://www.w3.org/1999/xhtml" >>>> xmlns:ui="http://java.sun.com/jsf/facelets" >>>> xmlns:h="http://java.sun.com/jsf/html" >>>> xmlns:f="http://java.sun.com/jsf/core" >>>> > >>>> <h:head> >>>> <ui:insert name="header"/> >>>> </h:head> >>>> <h:body> >>>> <f:view> >>>> <f:metadata> >>>> <f:viewParam name="id"/> >>>> </f:metadata> >>>> <h1>The big news stories of the day</h1> >>>> </f:view> >>>> </h:body> >>>> </html> >>>> >>>> Then I get: >>>> >>>> javax.servlet.ServletException: /test2.xhtml at line 14 and column >>>> 21 <f:metadata> Parent UIComponent j_id1723811066_66bf44b9 should >>>> be instance of UIViewRoot >>>> javax.faces.webapp.FacesServlet.service(FacesServlet.java:205) >>>> >>>> >>>> Which tells me I must be reading >>>> http://javaserverfaces.java.net/nonav/docs/2.0/vdldocs/facelets/f/m >>>> etadata.htmlseriously wrong >>>> >>>> Oh, before I forget, here is my web.xml >>>> >>>> <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" >>>> xmlns="http://java.sun.com/xml/ns/javaee" >>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >>>> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee >>>> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> >>>> <context-param> >>>> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> >>>> <param-value>server</param-value> >>>> </context-param> >>>> <context-param> >>>> <param-name>javax.faces.DEFAULT_SUFFIX</param-name> >>>> <param-value>.xhtml</param-value> >>>> </context-param> >>>> <context-param> >>>> <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name> >>>> <param-value>true</param-value> >>>> </context-param> >>>> <context-param> >>>> <param-name>javax.faces.PROJECT_STAGE</param-name> >>>> <!--<param-value>Production</param-value>--> >>>> <param-value>Development</param-value> >>>> </context-param> >>>> <context-param> >>>> <param-name>com.sun.faces.validateXml</param-name> >>>> <param-value>true</param-value> >>>> </context-param> >>>> <listener> >>>> >>>> <listener-class>org.apache.myfaces.webapp.StartupServletContextList >>>> ener</listener-class> >>>> </listener> >>>> >>>> <servlet> >>>> <servlet-name>Faces Servlet</servlet-name> >>>> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> >>>> <load-on-startup>1</load-on-startup> >>>> </servlet> >>>> <servlet-mapping> >>>> <servlet-name>Faces Servlet</servlet-name> >>>> <url-pattern>*.xhtml</url-pattern> >>>> </servlet-mapping> >>>> >>>> <session-config> >>>> <session-timeout>60</session-timeout> >>>> </session-config> >>>> </web-app> >>>> >>>> Any and all help appreciated >>>> >>>> -Stephen >>>> >>> >>> >> > -- Jakob Korherr blog: http://www.jakobk.com twitter: http://twitter.com/jakobkorherr work: http://www.irian.at