【发布时间】:2016-05-01 14:55:04
【问题描述】:
我正在使用以下代码在我的应用程序中创建一个复合组件:
<?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:p="http://primefaces.org/ui"
xmlns:composite="http://xmlns.jcp.org/jsf/composite">
<composite:interface>
<composite:attribute name="url" required="true" type="java.lang.String" />
<composite:attribute name="label" required="true" type="java.lang.String" />
<composite:attribute name="compId" required="true" type="java.lang.String" />
</composite:interface>
<composite:implementation>
<p:menuitem id="#{cc.attrs.compId}" value="#{cc.attrs.label}" url="#{cc.attrs.url}" />
</composite:implementation>
</html>
我在我的索引页面中使用这个复合组件如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:ex="http://xmlns.jcp.org/jsf/composite/example">
<h:head>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
<title>PrimeFaces</title>
</f:facet>
</h:head>
<h:body>
<p:menu>
<p:submenu id="admin" label="Admin" >
<ex:menuItem label="Go" url="www.google.com" compId="tempMenu"/>
</p:submenu>
</p:menu>
</h:body>
</html>
但是每当我尝试访问 index.xhtml 页面时,都会出现以下错误。
javax.faces.component.UINamingContainer cannot be cast to org.primefaces.model.menu.MenuElement
但如果我创建复合组件并在复合:实现部分进行以下更改,它工作正常。
复合组件:
<p:menu>
<p:submenu id="admin" label="Admin" >
<p:menuitem value="#{cc.attrs.label}" url="#{cc.attrs.url}" id="#{cc.attrs.compId}"/>
</p:submenu>
</p:menu>
index.xhtml:
<ex:menuItem label="Go" url="www.google.com" compId="tempMenu" />
为什么我在创建复合组件时收到javax.faces.component.UINamingContainer cannot be cast to org.primefaces.model.menu.MenuElement?任何帮助都会非常有用。提前致谢。
【问题讨论】:
标签: jsf primefaces composite-component