This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Use of static classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Use of static classes" Watch "Use of static classes" New topic
Author

Use of static classes

sony vijay
Ranch Hand

Joined: Jun 27, 2010
Posts: 32
Hi,

I am using ZK Ajax Framework and am using Java code to control the components. The idea is to create two labels dynamically with two different values "Label 1" and "Label 2" and append them to two different components i.e. vlayout1 and vlayout2. But, when I try this code, a label is attached to each of the vlayout but the value of both the labels is "Label 2". I am not sure what's wrong, how do I fix this such that the values of labels are created dynamically?

I am not sure if the question is appropriate in this forum but I think the issue is with my Java code (perhaps the way I am using the static class) and not something very specific to ZK. It would be great if someone helps me figure this out. Please see the simplified version of my code below:


TestComposer.java


TestComponent.java


IncludeBuilder.java


testlabel.zul


testcomposer.zul


Thank You,
Sony

Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7696
    
  20

sony vijay wrote:But, when I try this code, a label is attached to each of the vlayout but the value of both the labels is "Label 2". I am not sure what's wrong, how do I fix this such that the values of labels are created dynamically?

I wouldn't stake my life on it, but I certainly don't like the look of
static String value;
in your TestComponent class. Why is it static?

If you truly want the class to be static (and I'm not at all sure you do) then you should include a private default constructor.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use of static classes