On 29 April 2011 12:08, Jakob Korherr <jakob.korh...@gmail.com> wrote:
> 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 ;) > > Yes thank you helps a lot. I'd been stripping examples back and back to try and figure out why it was not working, and the way I'd found was not one I was happy with. Somebody should get the tlddoc updated to reflect the different situation for facelets. > 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/metadata.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/metadata.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.apply(ViewMetadataHandler.java:61) > >>>> at > >>>> > org.apache.myfaces.view.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:86) > >>>> at > >>>> > org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:167) > >>>> at > >>>> > org.apache.myfaces.view.facelets.impl.TemplateContextImpl$TemplateManagerImpl.apply(TemplateContextImpl.java:128) > >>>> at > >>>> > org.apache.myfaces.view.facelets.impl.TemplateContextImpl.includeDefinition(TemplateContextImpl.java:92) > >>>> at > >>>> > org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:433) > >>>> at > >>>> > org.apache.myfaces.view.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:93) > >>>> at > >>>> > javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:51) > >>>> at > >>>> > org.apache.myfaces.view.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:156) > >>>> at > >>>> > javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:59) > >>>> at > >>>> > org.apache.myfaces.view.facelets.tag.jsf.ComponentTagHandlerDelegate.apply(ComponentTagHandlerDelegate.java:324) > >>>> at > >>>> > javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:54) > >>>> at > >>>> > javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:51) > >>>> at > >>>> > org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:57) > >>>> at > >>>> > javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:51) > >>>> at > >>>> > org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:45) > >>>> at > >>>> > org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:322) > >>>> at > >>>> > org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:369) > >>>> at > >>>> > org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:347) > >>>> at > >>>> > org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:215) > >>>> at > >>>> > org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:140) > >>>> at > >>>> > org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:57) > >>>> at > >>>> > org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:45) > >>>> at > >>>> > org.apache.myfaces.view.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:143) > >>>> at > >>>> > org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.buildView(FaceletViewDeclarationLanguage.java:327) > >>>> at > >>>> > org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:66) > >>>> at > >>>> > org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239) > >>>> at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191) > >>>> at > >>>> org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:546) > >>>> at > >>>> > org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:483) > >>>> at > >>>> > org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119) > >>>> at > >>>> > org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:516) > >>>> at > >>>> > org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:230) > >>>> at > >>>> > org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:956) > >>>> at > >>>> > org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:411) > >>>> at > >>>> > org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:188) > >>>> at > >>>> > org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:891) > >>>> at > >>>> > org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) > >>>> at > >>>> > org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:247) > >>>> at > >>>> > org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:151) > >>>> at > >>>> > org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:114) > >>>> at org.eclipse.jetty.server.Server.handle(Server.java:353) > >>>> at > >>>> > org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:598) > >>>> at > >>>> > org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1059) > >>>> at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:590) > >>>> at > org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:212) > >>>> at > >>>> > org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:427) > >>>> at > >>>> > org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:510) > >>>> at > >>>> > org.eclipse.jetty.io.nio.SelectChannelEndPoint.access$000(SelectChannelEndPoint.java:34) > >>>> at > >>>> > org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40) > >>>> at > >>>> > org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.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.apply(ViewMetadataHandler.java:61) > >>>> > >>>> > org.apache.myfaces.view.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:86) > >>>> > org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:167) > >>>> > >>>> > org.apache.myfaces.view.facelets.impl.TemplateContextImpl$TemplateManagerImpl.apply(TemplateContextImpl.java:128) > >>>> > org.apache.myfaces.view.facelets.impl.TemplateContextImpl.includeDefinition(TemplateContextImpl.java:92) > >>>> > >>>> > org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:433) > >>>> > org.apache.myfaces.view.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:93) > >>>> > >>>> > javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:51) > >>>> > org.apache.myfaces.view.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:156) > >>>> > >>>> > javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:59) > >>>> > org.apache.myfaces.view.facelets.tag.jsf.ComponentTagHandlerDelegate.apply(ComponentTagHandlerDelegate.java:324) > >>>> > >>>> > javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:54) > >>>> > javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:51) > >>>> > >>>> > org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:57) > >>>> > javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:51) > >>>> > >>>> > org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:45) > >>>> > org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:322) > >>>> > >>>> > org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:369) > >>>> > org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:347) > >>>> > >>>> > org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:215) > >>>> > org.apache.myfaces.view.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:140) > >>>> > >>>> > org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:57) > >>>> > org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:45) > >>>> > >>>> > org.apache.myfaces.view.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:143) > >>>> > org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.buildView(FaceletViewDeclarationLanguage.java:327) > >>>> > >>>> > org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:66) > >>>> > org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java: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/metadata.htmlseriouslywrong > >>>> > >>>> 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.StartupServletContextListener</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 >