-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I would like to find an application wide solution to get open/closed icons in all groupbox captions.
There is a proposed solution in the Demo: http://www.zkoss.org/zkdemo/layout/group_box
And another here: http://emrpms.blogspot.ch/2012/05/group-box-with-collapse-and-expand.html
But both solutions require me to copy/paste a lot of stuff all over the place. I only want to define this once.
This works (instead of setLabel I plan to use setImage later on):
<groupbox onOpen='self.getFirstChild().setLabel(self.isOpen() ? "Open" : "Closed")' >
<caption label="Caption" />
</groupbox>
But when I try to define this attribute value in the language add-on, it does not work:
<language-addon>
<addon-name>myapp</addon-name>
<language-name>xul/html</language-name>
<component>
<component-name>groupbox</component-name>
<extends>groupbox</extends>
<custom-attribute>
<attribute-name>onOpen</attribute-name>
<attribute-value>self.getFirstChild().setLabel(self.isOpen() ? "Open" : "Closed")</attribute-value>
</custom-attribute>
</component>
</language-addon>
Is it not possible to define event code in the language add on?
Here is my example
zk.xml
<zk>
<language-config>
<addon-uri>/WEB-INF/lang-addon.xml</addon-uri>
</language-config>
</zk>
lang-addon.xml
<language-addon>
<addon-name>simple</addon-name>
<depends>zul</depends>
<language-name>xul/html</language-name>
<component>
<component-name>groupboxex</component-name>
<component-class>simple.GroupboxEx</component-class>
<extends>groupbox</extends>
</component>
</language-addon>
GroupboxEx.java
package simple;
import org.zkoss.zk.ui.event.OpenEvent;
import org.zkoss.zul.Caption;
import org.zkoss.zul.Groupbox;
public class GroupboxEx extends Groupbox{
private static final long serialVersionUID = 1L;
public void onOpen(OpenEvent evt){
Caption cp = getCaption();
if(cp!=null){
cp.setLabel(evt.isOpen()?"Open":"Close");
}
}
}
demo.zul
<vlayout spacing="15px">
<hbox spacing="15px">
<groupboxex width="300px">
<caption label="Open"/>
ABCD
</groupboxex>
</hbox>
</vlayout>
Asked: 2013-02-07 14:29:07 +0800
Seen: 69 times
Last updated: Feb 08 '13
regardless the answer, onOpen is a event, and custom-attribute is the attribute by component.setAttribute(), they are totally different.
dennis ( 2013-02-08 04:45:52 +0800 )editgood to know, that was just a naive assumption on my part, because in the zk demo they have zul markup like this: <attribute name="onOpen"><![CDATA[cb.setChecked(self.isOpen());]]></attribute>
RetoH ( 2013-02-08 14:45:41 +0800 )edit