ZK 前端框架GenericForwardComposer和SelectorComposer的区别

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

以上所测是本人臆测,

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

戴子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值