我在JSF 2.0项目中使用复合组件,我希望将我的复合组件组合成这样:
<ex:mycompositecomponent>
<f:ajax event="change" render="anotherComponent" />
</ex:mycompositecomponent>
有没有办法做到这一点?
答案 0 :(得分:0)
应该是。
以下代码值得一试:
<!-- mycompositecomponent.xhtml -->
...
<composite:implementation>
<h:inputText ...>
<composite:insertChildren /> <!-- contents within <ex:mycompositecomponent>...</ex:mycom....> goes here -->
</h:inputText>
</composite:implementation>
...
现在您对mycompositecomponent.xhtml的使用应该有效。
答案 1 :(得分:0)
我知道旧线程,但您可以使用未记录的clientBehavior执行此操作 属性。此代码将键盘事件从h:inputText映射到逻辑 事件'myevent'。希望这是相当不言自明的。
的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;
}
}