我为客户列表创建了一个复合组件。我可以在视图中使用这个组件:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:customer="http://java.sun.com/jsf/composite/components/customer">
<ui:composition template="/WEB-INF/templates/template.xhtml">
<ui:define name="caption">
<h:outputText value="#{msg.customerListHeading}" />
</ui:define>
<ui:define name="content">
<ui:decorate template="/WEB-INF/templates/sidebox.xhtml">
<ui:param name="title" value="#{msg.customerListHeading}" />
<p:outputPanel>
<h:form id="customerList">
<customer:list list="#{customerControllerBean.list}">
<f:facet name="headerButton">
<h:button outcome="customerdetail.jsf"
value="#{msg.newButtonLabel}" />
</f:facet>
<f:facet name="rowButton">
<h:commandButton value="#{msg.deleteButtonLabel}"
action="#{customerControllerBean.delete(customer)}" />
<h:button outcome="customerdetail.jsf?id=#{customer.id}"
value="#{msg.editButtonLabel}" />
</f:facet>
</customer:list>
</h:form>
</p:outputPanel>
</ui:decorate>
</ui:define>
</ui:composition>
</html>
但是当我在非常相似的视图中使用该组件时,我收到以下错误:
<customer:list> Tag Library supports namespace: http://java.sun.com/jsf/composite/components/customer, but no tag was defined for name: list
有问题的视图如下所示:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:customer="http://java.sun.com/jsf/composite/components/customer">
<ui:composition template="/WEB-INF/templates/template.xhtml">
<ui:define name="caption">
<h:outputText value="#{msg.customerListHeading}" />
</ui:define>
<ui:define name="content">
<ui:decorate template="/WEB-INF/templates/sidebox.xhtml">
<ui:param name="title" value="#{msg.customerListHeading}" />
<p:outputPanel>
<h:form id="customerList">
<customer:list list="#{customerControllerBean.list}">
<f:facet name="rowButton">
<h:commandButton value="#{msg.applyButtonLabel}"
action="#{orderControllerBean.setCustomer(customer)}" />
</f:facet>
</customer:list>
</h:form>
</p:outputPanel>
</ui:decorate>
</ui:define>
</ui:composition>
</html>
正如您所看到的,这两个视图的不同之处仅在于我用来向客户列表表添加按钮的方面,因为我在两个不同的上下文中使用该列表。但是为什么第二种观点不起作用呢?
我发现 Mojarra 存在/曾经存在问题,但我使用所谓的稳定版本来解决这个问题:
2012-09-16 19:09:41,512 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-4) Mojarra 2.1.7-jbossorg-1 (20120227-1401)