Reputation: 863
I'm migrating code from JSF 1.2 to JSF 2.0(deployed on JBoss 6.1). However, I am experiencing problem with using h:outputText
inside of href
attribute of link
tag:
<link rel='canonical' href='<h:outputText value="#{resultPage.currentLink}" escape="false"/>' />
I cannot just use
<link rel='canonical' href="#{resultPage.currentLink}" />
because I need html escape attribute.
I'm receiving the following exception:
javax.servlet.ServletException: Error Parsing /shoe/shoe2.xhtml: Error Traced[line: 23] The value of attribute "href" associated with an element type "link" must not contain the '<' character.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
com.youandshoe.web.controller.EncoderFilter.doFilter(EncoderFilter.java:28)
com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:126)
com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)
root cause
javax.faces.view.facelets.FaceletException: Error Parsing /shoe/shoe2.xhtml: Error Traced[line: 23] The value of attribute "href" associated with an element type "link" must not contain the '<' character.
com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:390)
com.sun.faces.facelets.compiler.SAXCompiler.doMetadataCompile(SAXCompiler.java:373)
com.sun.faces.facelets.compiler.Compiler.metadataCompile(Compiler.java:128)
com.sun.faces.facelets.impl.DefaultFaceletFactory.createMetadataFacelet(DefaultFaceletFactory.java:316)
com.sun.faces.facelets.impl.DefaultFaceletFactory.access$200(DefaultFaceletFactory.java:89)
com.sun.faces.facelets.impl.DefaultFaceletFactory$2.newInstance(DefaultFaceletFactory.java:165)
com.sun.faces.facelets.impl.DefaultFaceletFactory$2.newInstance(DefaultFaceletFactory.java:164)
com.sun.faces.facelets.impl.DefaultFaceletCache$2.newInstance(DefaultFaceletCache.java:90)
com.sun.faces.facelets.impl.DefaultFaceletCache$2.newInstance(DefaultFaceletCache.java:86)
com.sun.faces.util.ExpiringConcurrentCache$1.call(ExpiringConcurrentCache.java:95)
java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
java.util.concurrent.FutureTask.run(Unknown Source)
com.sun.faces.util.ExpiringConcurrentCache.get(ExpiringConcurrentCache.java:110)
com.sun.faces.facelets.impl.DefaultFaceletCache.getMetadataFacelet(DefaultFaceletCache.java:131)
com.sun.faces.facelets.impl.DefaultFaceletCache.getMetadataFacelet(DefaultFaceletCache.java:58)
com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:249)
com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:198)
com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:102)
com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:223)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:107)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
org.apache.myfaces.extensions.cdi.jsf2.impl.listener.phase.CodiLifecycleWrapper.execute(CodiLifecycleWrapper.java:97)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
com.youandshoe.web.controller.EncoderFilter.doFilter(EncoderFilter.java:28)
com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:126)
com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)
However, the same code works fine in JSF 1.2, JBoss 5.1.
Any ideas? Thanx!
Upvotes: 1
Views: 3591
Reputation: 1109865
Facelets is a XML based view technology. The XML document must be well-formed. Nesting XML tags is invalid. To fix your problem, you'd need to include the whole HTML inside the <h:outputText>
instead.
<h:outputText value="<link rel="canonical" href="#{resultPage.currentLink}" />" escape="false" />
By the way, I really wonder why you can't just use
<link rel="canonical" href="#{resultPage.currentLink}" />
That should work equally fine. Having XML special characters in href
attribute would otherwise result in invalid XML markup errors in the browser side anyway and the browser won't be able to download the resource.
Upvotes: 3