2

我在我的 JSF 2.0 项目中使用复合组件,我想将我的复合组件与这样的组合:

<ex:mycompositecomponent>
    <f:ajax event="change" render="anotherComponent" />
</ex:mycompositecomponent>

有没有办法做到这一点?

4

2 回答 2

0

应该。

以下代码值得一试:

<!-- mycompositecomponent.xhtml -->
    ...
    <composite:implementation>
      <h:inputText ...>
        <composite:insertChildren /> <!-- contents within <ex:mycompositecomponent>...</ex:mycom....> goes here -->
      </h:inputText>
    </composite:implementation>
    ...

现在您对 mycompositecomponent.xhtml 的使用应该可以了。

于 2010-06-01T19:32:33.407 回答
0

我知道旧线程,但是您可以使用未记录的 clientBehavior 属性来执行此操作。此代码将 ah:inputText 中的 keyup 事件映射到逻辑事件“myevent”。希望这是合理的不言自明。

索引.xhtml

<?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:h="http://java.sun.com/jsf/html"
      xmlns:sqcc="http://java.sun.com/jsf/composite/sqcc"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <h:form id="mainform" prependId="false">
            <sqcc:testcomp value="#{indexBean.inputText1}">
                <f:ajax render=":mainform:echo1"/>
            </sqcc:testcomp>
            <h:outputText id="echo1" value="a:#{indexBean.inputText1}"/>
            <br/>
        </h:form>
    </h:body>
</html>

testcomp.xhtml

<?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">
<ui:component xmlns="http://www.w3.org/1999/xhtml"
              xmlns:cc="http://java.sun.com/jsf/composite"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:ui="http://java.sun.com/jsf/facelets">

    <cc:interface>
        <cc:attribute name="value"/>
        <cc:clientBehavior name="myevent" default="true" event="keyup" targets="#{cc.clientId}:ccinput"/>
    </cc:interface>

    <cc:implementation>
        <h:outputLabel for="#{cc.clientId}:ccinput" value="Input: "/>
        <h:inputText id="ccinput" value="#{cc.attrs.value}"
                     autocomplete="off">
            <f:ajax event="keyup" render="#{cc.clientId}:ccoutput"/>
        </h:inputText>
        <h:outputText id="ccoutput" value="cc:#{cc.attrs.value}"/>
    </cc:implementation>
</ui:component>

IndexBean.java

package testAjaxCC;


import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class IndexBean implements Serializable {

    private String inputText1;
    private String inputText2;

    public IndexBean() {
    }

    public String getInputText1() {
        return inputText1;
    }

    public void setInputText1(String inputText1) {
        this.inputText1 = inputText1;
    }

    public String getInputText2() {
        return inputText2;
    }

    public void setInputText2(String inputText2) {
        this.inputText2 = inputText2;
    }

}
于 2011-03-26T21:46:16.317 回答