-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I created specific textbox component zkidtextbox extended textbox
<?component name="zkidtextbox" extends="textbox" class="com.ubiqube.ses.zk.utils.ZkIdTextbox" ?> <zkidtextbox id="voicemail_extension" elementName="EXT" categoryName="VMAIL"></zkidtextbox>
When zkIdtextbox is created, the default constructor is called
public ZkIdTextbox() { }
But, i want to call other constructor with my two arguments elementName and categoryName directly from zul page
public ZkIdTextbox(String categoryName, String elementName) { this.categoryName = categoryName; this.elementName = elementName; }
Hi abr,
I am a little confused of your question.
Actually. if you write setter in ZkIdTextbox.java, elementName and categoryName in ZUL will automatically assign to ZkIdTextbox isntance.
So you does not need write another constructor like above.
I write a simple example:
https://github.com/MontyPan/RTFM/blob/master/src/org/zkoss/rtmf/composite/Email.java
https://github.com/MontyPan/RTFM/blob/master/src/archive/composite.zul
When composite.zul load, the server side console will print
constructor set category : categoryValue set element : elementValue
Then you click "show attribute", it will alert
categoryValue elementValue
Regards,
Monty Pan
Hi MontyPan,
Correct, but
Is is possible to call antother constructor with my attributes than the default constructor ?
Cause, in my code, I have operations between the instanciation of the object and the set of my two parameters...and I need to set my parameters in instanciation
Regards
Hi abr,
Sorry, I can't understand your question.
Can you explain why you must use this
new Foo(value1, value2);
foo = new Foo(); foo.setValue1(value1); foo.setValue2(value2);
On the other hand, if do so, you must provide all field combination constructor,
because you can't sure how many attribute will be defined in ZUL file (and other polymorphism issue).
Regards,
Monty Pan
Hi monty
On the other hand, if do so, you must provide all field combination constructor,
because you can't sure how many attribute will be defined in ZUL file (and other polymorphism issue).
So, how do this in zul file with many attributes ? Do you have a sample ?
Cause
<zkidtextbox id="voicemail_extension" elementName="EXT" categoryName="VMAIL"></zkidtextbox>
foo = new ZkIdTextbox();
foo.setElementName("EXT'); foo.setCategoryName("VMAIL");
and I want:
foo = new ZkIdTextbox("EXT", "VMAIL");
So, Is anybody knows how to reproduce this in ZUL file ?
Regards
Sorry abr,
Currently it is impossible to ask ZUL parser to use argument constructor to instantiate a component.
I assume you want to use argument constructor because there's some initialization works need to be done after getting these two variables.
If I'm right, please make your component implements org.zkoss.zk.ui.ext.AfterCompose, then put your initialization code in afterCompose() method.
I solve the issue with the workaround :
From ZK support
You tried to create UUID from component attribute by getting the component attribute when ZK invokes IdGenerator.nextComponentUuid(), but you get an empty attribute because ZK haven't set an attribute to component.
Here is a workaround: in the IdGenerator interface, you can get raw property from ComponentInfo.
Sample code:
public String nextComponentUuid(Desktop desktop, final Component comp, ComponentInfo compInfo) {
List<Property> properties = compInfo.getProperties();
for (Property p : properties) {
String name = p.getName();
String val = p.getRawValue();
System.out.println(name + ":" + val);
}
Asked: 2012-08-14 10:12:28 +0800
Seen: 184 times
Last updated: Aug 20 '12