1、繼承了GenericForwardCompose的類,不需要@Wire就可以調用組件;而繼承了SelectorComposer需要@Wire才能調用組件,比如獲得它的值,並且需要給它的事件添加監聽@Listen;如下所示的一段代碼:
public class TestGenericComposer extends SelectorComposer<Component>{
/**
*
*/
private static final long serialVersionUID = 8383213293757822132L;
@Wire
private Textbox t1;
@Wire
private Textbox t2;
@Wire
private Textbox t3;
@Listen("onClick = #bt")
public void onClick(){
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Textbox;
public class TestGenericComposer extends GenericForwardComposer<Component> {
/**
*
*/
private static final long serialVersionUID = -8084302987575367204L;
private Textbox tb1;
private Textbox tb2;
private Textbox tb3;
public void onClick$bt(){
System.out.println(tb1.getValue()+"==="+tb2.getValue()+"==="+tb3.getValue()+"===");
}
zul頁面:
至於爲什麼,我應該是GenericForwardComposer所繼承的父類(GenericAutowireComposer.java)裏面有這麼一個構造方法應該可以解釋爲什麼了,如下所示:
這段註釋表明了:構造函數與自定義分隔符。分離器用於單獨的組件ID和事件名稱。默認情況下,它是“$”。Groovy和其他環境,“$”不適用,您可以指定“_”。
protected GenericAutowireComposer() {
this('$');
}
/** Constructor with a custom separator.
* The separator is used to separate the component ID and event name.
* By default, it is '$'. For Groovy and other environment that '$'
* is not applicable, you can specify '_'.
* <p>It is a shortcut of <code>GenericAutowireComposer('$',
* !"true".equals(Library.getProperty("org.zkoss.zk.ui.composer.autowire.zscript")),
* !"true".equals(Library.getProperty("org.zkoss.zk.ui.composer.autowire.xel")))</code>.
* <p>In other words, whether to ignore variables defined in ZSCRIPT and XEL depends
* on the library variables called <code>org.zkoss.zk.ui.composer.autowire.zscript</code>
* and <code>org.zkoss.zk.ui.composer.autowire.xel</code>.
* Furthermore, if not specified, their values are default to <b>false</b>, i.e.,
* they shall <t>not</t> be wired (i.e., shall be ignored)
* <p>If you want to control whether to wire ZSCRIPT's or XEL's variable
* explicitly, you could use
* {@link #GenericAutowireComposer(char,boolean,boolean)} instead.
*
* <h2>Version Difference</h2>
* <p>ZK 5.0 and earlier, this constructor is the same as
* <code>GenericAutowireComposer('$', false, false)</code><br/>
* In other words, it is default to wire (i.e., shall <i>not</i> ignore).
* @param separator the separator used to separate the component ID and event name.
* Refer to {@link #_separator} for details.
* @since 3.6.0
*/
protected GenericAutowireComposer(char separator) {
initIgnores();
_separator = separator;
_ignoreZScript = _sIgnoreZScript;
_ignoreXel = _sIgnoreXel;
}
以上所測是本人臆測,