错误解析 /page.xhtml:错误跟踪[行:42] 与元素类型 "id" 相关联的属性“{1}”需要左引号
Error Parsing /page.xhtml: Error Traced[line: 42] Open quote is expected for attribute "{1}" associated with an element type "id"
使用以下 JavaScript/jQuery 代码时:
$("#service_container").append("<p id=\"text\">SomeText</p>")
我收到以下错误:
Error Parsing /dashboard.xhtml: Error Traced[line: 140] Open quote is expected for attribute "{1}" associated with an element type "id".
这是堆栈跟踪:
javax.faces.view.facelets.FaceletException: Error Parsing /dashboard.xhtml: Error Traced[line: 140] Open quote is expected for attribute "{1}" associated with an element type "id".
at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:456)
at com.sun.faces.facelets.compiler.SAXCompiler.doMetadataCompile(SAXCompiler.java:439)
at com.sun.faces.facelets.compiler.Compiler.metadataCompile(Compiler.java:130)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.createMetadataFacelet(DefaultFaceletFactory.java:503)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.access0(DefaultFaceletFactory.java:106)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.newInstance(DefaultFaceletFactory.java:205)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.newInstance(DefaultFaceletFactory.java:203)
at com.sun.faces.facelets.impl.DefaultFaceletCache.newInstance(DefaultFaceletCache.java:97)
at com.sun.faces.facelets.impl.DefaultFaceletCache.newInstance(DefaultFaceletCache.java:92)
at com.sun.faces.util.ExpiringConcurrentCache.call(ExpiringConcurrentCache.java:99)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.sun.faces.util.ExpiringConcurrentCache.get(ExpiringConcurrentCache.java:114)
at com.sun.faces.facelets.impl.DefaultFaceletCache.getViewMetadataFacelet(DefaultFaceletCache.java:146)
at com.sun.faces.facelets.impl.DefaultFaceletCache.getViewMetadataFacelet(DefaultFaceletCache.java:63)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:316)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:246)
at com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:138)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:241)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:295)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at com.omegathings.security.AuthorizationFilter.doFilter(AuthorizationFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access0(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
我通过附加没有属性的元素来确保 jQuery 正常工作。
[service_container]
id 也正确并分配给 [ul]
HTML 元素。
jQuery 和 Facelets 解析器是因为某种原因不能相处还是我遗漏了什么?
Facelets 是一种基于 XML 的视图技术,它使用 XHTML+XML 生成 HTML 输出。 XML 有五个被 XML 解析器特殊处理的特殊字符:
<
标签的开始。
>
标签结束。
"
属性值的开始和结束。
'
属性值的替代开始和结束。
&
实体的开始(以 ;
结束)。
在您的特定情况下,JavaScript 字符串中未转义的 <
触发 XML 解析器启动标记。 id
被识别为标签属性,然后它将搜索像 "
或 '
这样的左引号。但是,在您的特定情况下,您使用 \
将其转义为 JavaScript 字符串的引号。这完全解释了您遇到的 XML 解析错误:
Open quote is expected for attribute "{1}" associated with an element type "id"
本质上,你在错误的地方写了 JavaScript 代码,XML 文档而不是 JS 文件,所以你应该相应地转义所有 XML 特殊字符.
所以,本质上,
$("#service_container").append("<p id=\"text\">SomeText</p>")
必须成为
$("#service_container").append("<p id="text">SomeText</p>")
使其XML-有效。应该注意的是,一些解析器在某些字符序列中更宽容,对于大多数解析器,您可以继续使用 >
而不是转义它。
然而,这使得 JavaScript 代码更难阅读和维护。正如 Mozilla Developer Network 的优秀文档 Writing JavaScript for XHTML 中所述,您应该将 JavaScript 代码放在字符数据 (CDATA) 块中。因此,在 JSF 术语中,这将是:
<h:outputScript>
<![CDATA[
// ...
]]>
</h:outputScript>
XML 解析器会将块的内容解释为“普通”字符数据而不是 XML,因此“按原样”解释 XML 特殊字符。
但是,更好的方法是将 JS 代码放在它自己的 JS 文件中,该文件由 <script src>
包含,或者在 JSF 术语中,<h:outputScript>
.
<h:outputScript name="functions.js" target="head" />
这样你就不用担心 XML-JS 代码中的特殊字符了。
另请参阅:
- Error parsing XHTML: The content of elements must consist of well-formed character data or markup
- The entity name must immediately follow the '&' in the entity reference
- Writing JavaScript for XHTML
使用以下 JavaScript/jQuery 代码时:
$("#service_container").append("<p id=\"text\">SomeText</p>")
我收到以下错误:
Error Parsing /dashboard.xhtml: Error Traced[line: 140] Open quote is expected for attribute "{1}" associated with an element type "id".
这是堆栈跟踪:
javax.faces.view.facelets.FaceletException: Error Parsing /dashboard.xhtml: Error Traced[line: 140] Open quote is expected for attribute "{1}" associated with an element type "id".
at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:456)
at com.sun.faces.facelets.compiler.SAXCompiler.doMetadataCompile(SAXCompiler.java:439)
at com.sun.faces.facelets.compiler.Compiler.metadataCompile(Compiler.java:130)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.createMetadataFacelet(DefaultFaceletFactory.java:503)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.access0(DefaultFaceletFactory.java:106)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.newInstance(DefaultFaceletFactory.java:205)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.newInstance(DefaultFaceletFactory.java:203)
at com.sun.faces.facelets.impl.DefaultFaceletCache.newInstance(DefaultFaceletCache.java:97)
at com.sun.faces.facelets.impl.DefaultFaceletCache.newInstance(DefaultFaceletCache.java:92)
at com.sun.faces.util.ExpiringConcurrentCache.call(ExpiringConcurrentCache.java:99)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.sun.faces.util.ExpiringConcurrentCache.get(ExpiringConcurrentCache.java:114)
at com.sun.faces.facelets.impl.DefaultFaceletCache.getViewMetadataFacelet(DefaultFaceletCache.java:146)
at com.sun.faces.facelets.impl.DefaultFaceletCache.getViewMetadataFacelet(DefaultFaceletCache.java:63)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:316)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:246)
at com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:138)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:241)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:295)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at com.omegathings.security.AuthorizationFilter.doFilter(AuthorizationFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access0(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
我通过附加没有属性的元素来确保 jQuery 正常工作。
[service_container]
id 也正确并分配给 [ul]
HTML 元素。
jQuery 和 Facelets 解析器是因为某种原因不能相处还是我遗漏了什么?
Facelets 是一种基于 XML 的视图技术,它使用 XHTML+XML 生成 HTML 输出。 XML 有五个被 XML 解析器特殊处理的特殊字符:
<
标签的开始。>
标签结束。"
属性值的开始和结束。'
属性值的替代开始和结束。&
实体的开始(以;
结束)。
在您的特定情况下,JavaScript 字符串中未转义的 <
触发 XML 解析器启动标记。 id
被识别为标签属性,然后它将搜索像 "
或 '
这样的左引号。但是,在您的特定情况下,您使用 \
将其转义为 JavaScript 字符串的引号。这完全解释了您遇到的 XML 解析错误:
Open quote is expected for attribute "{1}" associated with an element type "id"
本质上,你在错误的地方写了 JavaScript 代码,XML 文档而不是 JS 文件,所以你应该相应地转义所有 XML 特殊字符.
所以,本质上,
$("#service_container").append("<p id=\"text\">SomeText</p>")
必须成为
$("#service_container").append("<p id="text">SomeText</p>")
使其XML-有效。应该注意的是,一些解析器在某些字符序列中更宽容,对于大多数解析器,您可以继续使用 >
而不是转义它。
然而,这使得 JavaScript 代码更难阅读和维护。正如 Mozilla Developer Network 的优秀文档 Writing JavaScript for XHTML 中所述,您应该将 JavaScript 代码放在字符数据 (CDATA) 块中。因此,在 JSF 术语中,这将是:
<h:outputScript>
<![CDATA[
// ...
]]>
</h:outputScript>
XML 解析器会将块的内容解释为“普通”字符数据而不是 XML,因此“按原样”解释 XML 特殊字符。
但是,更好的方法是将 JS 代码放在它自己的 JS 文件中,该文件由 <script src>
包含,或者在 JSF 术语中,<h:outputScript>
.
<h:outputScript name="functions.js" target="head" />
这样你就不用担心 XML-JS 代码中的特殊字符了。
另请参阅:
- Error parsing XHTML: The content of elements must consist of well-formed character data or markup
- The entity name must immediately follow the '&' in the entity reference
- Writing JavaScript for XHTML