是否有可能将支持bean实例作为参数传递给使用JSF 2.2的组合组件,并从bean实例调用方法?
有例子吗?谢谢你的帮助。
我明白了!下面是我的解决方案:
复合组件:<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface>
<cc:attribute name="backingBean" required="true" shortDescription="A backing bean to invoke polimorphic methods."/>
</cc:interface>
<cc:implementation>
<h:commandButton value="Foo" action="#{cc.attrs.backingBean.myPolimorphicMethod}"/>
</cc:implementation>
</html>
使用复合组件:
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:cc="http://xmlns.jcp.org/jsf/composite/components"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/templates/template.xhtml">
<ui:define name="content">
<h:form>
<cc:myCustomComponent backingBean="#{myBacking}"></cc:myCustomComponent>
</h:form>
</ui:define>
</ui:composition>