0

Access constructor for compsoite component

asked 2012-08-14 10:12:28 +0800

abr gravatar image abr
12

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

How I can call the specific constructor ? Where I add attributes ? Regards

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2012-08-15 02:56:19 +0800

MontyPan gravatar image MontyPan
435 3
http://xitop.blogspot.com...

updated 2012-08-15 02:59:01 +0800

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

link publish delete flag offensive edit

answered 2012-08-15 07:12:29 +0800

abr gravatar image abr
12

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

link publish delete flag offensive edit

answered 2012-08-15 07:29:18 +0800

MontyPan gravatar image MontyPan
435 3
http://xitop.blogspot.com...

Hi abr,

Sorry, I can't understand your question.
Can you explain why you must use this

new Foo(value1, value2);

instead of
foo = new Foo();
foo.setValue1(value1);
foo.setValue2(value2);

especially in Composite Component?

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

link publish delete flag offensive edit

answered 2012-08-15 10:24:13 +0800

abr gravatar image abr
12

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>

generate
foo = new ZkIdTextbox();

Here, I have a call to other remote function, and elementName / categoryName must be set
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

link publish delete flag offensive edit

answered 2012-08-16 04:52:53 +0800

iantsai gravatar image iantsai
2755 1

updated 2012-08-16 04:55:24 +0800

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.

link publish delete flag offensive edit

answered 2012-08-20 08:36:43 +0800

abr gravatar image abr
12

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

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-08-14 10:12:28 +0800

Seen: 184 times

Last updated: Aug 20 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More