【问题标题】:Passing a backing bean instance as parameter to composite component将支持 bean 实例作为参数传递给复合组件
【发布时间】:2014-06-03 15:02:41
【问题描述】:

是否可以使用 JSF 2.2 将支持 bean 实例作为参数传递给复合组件并从 bean 实例调用方法?

有例子吗?感谢您的帮助。

【问题讨论】:

  • “发送一个支持 bean 实例”是什么意思?
  • 我想发送整个 backing bean 实例并在自定义组件中调用它的方法,而不是只发送一个 backing bean 的属性。
  • @Mifmif 表示您是否可以通过表达式语言将托管 bean 的实例以<cc:mycc action="#{bean.foo(anotherBean)}" /> 的形式发送到自定义组件。
  • @LuiggiMendoza 如果是这样,是的,有可能:)
  • @LuiggiMendoza,感谢您的帮助。但是,如果可能的话,我想发送一个像 <cc:mycc backingBeanInstance="#{bean}" /> 这样的支持 bean 实例,并在自定义组件中,从像 <h:commanButton action="#{beanReceivedFromParameter.myPolimorphicMethod}"/> 这样的实例调用一个方法。

标签: jsf el jsf-2.2 composite-component


【解决方案1】:

我明白了!这是我的解决方案:

复合组件:

<!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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    • 2014-05-24
    • 2015-02-26
    • 1970-01-01
    • 2016-07-07
    • 1970-01-01
    相关资源
    最近更新 更多