开发者

Ajax-enabled composite component

I am using composite components in my JSF 2.0 project, and I want to combine my composite components with like this:

开发者_如何学Go<ex:mycompositecomponent>
    <f:ajax event="change" render="anotherComponent" />
</ex:mycompositecomponent>

Is there any way to do that?


Should be.

The following code is worth the try:

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

Now your usage of mycompositecomponent.xhtml should work.


Old thread I know, but you can do this with the undocumented clientBehavior attribute. This code maps a keyup event from a h:inputText to a logical event 'myevent'. Hopefully this is reasonably self-explanatory.

index.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;
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜