href 内的 h:outputText 在 JSF 2.0 中不起作用
我正在将代码从 JSF 1.2 迁移到 JSF 2.0(部署在 JBoss 6.1 上)。但是,我在 link
标记的 href
属性内使用 h:outputText
时遇到问题:
<link rel='canonical' href='<h:outputText value="#{resultPage.currentLink}" escape="false"/>' />
我不能只使用,
<link rel='canonical' href="#{resultPage.currentLink}" />
因为我需要 html escape 属性。
我收到以下异常:
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)
但是,相同的代码在 JSF 1.2、JBoss 5.1 中运行良好。
有什么想法吗?谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Facelets 是一种基于 XML 的视图技术。 XML 文档必须格式正确。嵌套 XML 标记无效。要解决您的问题,您需要将整个 HTML 包含在
中。顺便说一句,我真的很想知道为什么你不能直接使用
That 应该同样可以正常工作。否则,在
href
属性中包含 XML 特殊字符将导致浏览器端出现无效的 XML 标记错误,并且浏览器将无法下载资源。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.By the way, I really wonder why you can't just use
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.