如何创建按钮的 Zul 模板然后应用它
How to create a Zul template of a button and then apply it
zkessentials 书中提供的示例过于简单,但文档过于夸张(在我看来)。
我想做的是创建一个只有一个按钮的模板,然后将样式 class 和标签值传递给它。
书中的例子展示了一个十行的 Zul,然后说你必须声明它是一个模板,但没有提到在哪里,也没有提到如何将值传递给模板。
其他示例介绍了 @{define(left)}
和 @{insert(left)}
,这显然没有任何解释,如果我可以在那里传递值或者它是否正在做一些匹配,就很难弄清楚。
感谢您的帮助。
也许您只是想制作一个预定义的 class 谁扩展按钮。
public class MyButton extends Button implements BeforeCompose {
@Override
public void beforeCompose() {
setLabel("new Button");
setStyle("...");
// and more settings you want to set as default
}
}
现在您有了这个 class 您可以通过 3 种不同的方式使用它。
首先:
<button use="my.path.MyButton"/>
第二个:
<?component name="mybutton" class="my.path.MyButton"?>
<mybutton />
第三个:
在 lang-addon.xml 中添加:
<component>
<component-name>mybutton</component-name>
<extends>button</extends>
<component-class>my.path.MyButton</component-class>
</component>
zul 中的用法:
<mybutton />
zkessentials 书中提供的示例过于简单,但文档过于夸张(在我看来)。
我想做的是创建一个只有一个按钮的模板,然后将样式 class 和标签值传递给它。
书中的例子展示了一个十行的 Zul,然后说你必须声明它是一个模板,但没有提到在哪里,也没有提到如何将值传递给模板。
其他示例介绍了 @{define(left)}
和 @{insert(left)}
,这显然没有任何解释,如果我可以在那里传递值或者它是否正在做一些匹配,就很难弄清楚。
感谢您的帮助。
也许您只是想制作一个预定义的 class 谁扩展按钮。
public class MyButton extends Button implements BeforeCompose {
@Override
public void beforeCompose() {
setLabel("new Button");
setStyle("...");
// and more settings you want to set as default
}
}
现在您有了这个 class 您可以通过 3 种不同的方式使用它。 首先:
<button use="my.path.MyButton"/>
第二个:
<?component name="mybutton" class="my.path.MyButton"?>
<mybutton />
第三个:
在 lang-addon.xml 中添加:
<component>
<component-name>mybutton</component-name>
<extends>button</extends>
<component-class>my.path.MyButton</component-class>
</component>
zul 中的用法:
<mybutton />