ZK 前端框架GenericForwardComposer和SelectorComposer的区别

来源:互联网 发布:mac版暗黑2技能修改器 编辑:程序博客网 时间:2024/06/10 01:19

1、继承了GenericForwardCompose的类,不需要@Wire就可以调用组件;而继承了SelectorComposer需要@Wire才能调用组件,比如获得它的值,并且需要给它的事件添加监听@Listen;如下所示的一段代码:

public class TestGenericComposer extends SelectorComposer<Component>{/** *  */private static final long serialVersionUID = 8383213293757822132L;@Wireprivate Textbox t1;@Wireprivate Textbox t2;@Wireprivate 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;}

以上所测是本人臆测,

1 0
原创粉丝点击