With component definitions,
we could specify the initial values for the properties, attributes and
annotations of a component. If you want to set the initial value of a property (such as showTodayLink
for Datebox
, or any other property for any component) globally across your application, you can use the language addon mechanism described above.
Properties
Depending on the requirement, you can change the initial value of a property(attribute) for a particular ZUML document or for the whole application.
Notice that the initial values are applicable only to the component instantiated by ZK Loaders. It has no effect if you instantiate it in pure Java (unless you invoke
after instantiating a component).
Page-wide Initialization
Suppose we want to assign normal
to the border property
(
<?component name="window" extends="window" border="normal"?>
<window title="Border"/>
Application-wide Initialization
If you prefer to have the same initial value for all ZUML documents, you
could specify it in a language addon. For
example, we could prepare a file called WEB-INF/lang-addon.xml
with
the following content:
<language-addon>
<addon-name>myapp</addon-name>
<language-name>xul/html</language-name>
<component>
<component-name>window</component-name>
<extends>window</extends>
<property>
<property-name>border</property-name>
<property-value>normal</property-value>
</property>
</component>
</language-addon>
Then, we could specify this file by adding the following content to
WEB-INF/zk.xml
:
<language-config>
<addon-uri>/WEB-INF/lang-addon.xml</addon-uri>
</language-config>
For more information, please refer to ZK Configuration Reference.
Molds
A mold is yet another property
(ClassName
.mold
. For
example, if you would like to specify trendy
as the initial mold of a
button, then you could add the following to WEB-INF/zk.xml
:
<library-property>
<name>org.zkoss.zul.Button.mold</name>
<value>trendy</value>
</library-property>
Attributes
Like properties, you could assign an attribute’s initial value for a given component in the whole application (like calling [https://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/ext/Scope.html#setAttribute(java.lang.String,_java.lang.Object,_boolean) Component.setAttribute()]).
Notice that the initial values are applicable only to the component instantiated by ZK Loaders. It has no effect if you instantiate it in pure Java (unless you invoke
after instantiating a component).
Page-wide Initialization
Unlike the initial value of a property, there is no way to specify the initial value of a custom attribute in a ZUML document.
Application-wide Initialization
Similar to customizing the initial value of a property, you could specify the following in a language addon to assign an initial value of a attribute to a component.
<language-addon>
<addon-name>myapp</addon-name>
<language-name>xul/html</language-name>
<component>
<component-name>panel</component-name>
<extends>panel</extends>
<custom-attribute>
<attribute-name>any.attribute.name</attribute-name>
<attribute-value>any.value</attribute-value>
</custom-attribute>
</component>
</language-addon>