0

"Extend Window" --- problem

asked 2008-11-18 11:37:13 +0800

erdem gravatar image erdem
57

hi all,

i have 2 java files and a zk file.. zk file uses Class2's methods.. But the problem is how to trigger a method inside the Class2 from Class1 ???

when I use like that a "java.lang.NullPointerException" is thrown while trying to add a value inside the listbox...

import ...Class2; 
......... 
public class Class1{ 
 
   public void fillListbox(){ 
      Class2 obj = new Class2(); 
      obj.fill(Strign xxx);  
   } 
} 
 
********************** 
public class Class2 extends Window{ 
 
    public void fill(String xxx){ 
       ............... 
    } 
} 

How i can solve this problem without carrying "fillListbox()" function into the "Class2"...
thx...

delete flag offensive retag edit

11 Replies

Sort by ยป oldest newest

answered 2008-11-18 12:12:09 +0800

ziccardi gravatar image ziccardi
321 7

updated 2008-11-18 12:19:40 +0800

The esiest way would be to make Class1 a composer of the Class2 window. Something like this:

<window id="myWin" use="Class2" apply="Class1">
</window>

Then, something like this should do the trick:

import ...Class2; 
......... 
public class Class1 extends GenericForwardComposer
{  
  
   public void fillListbox(){ 
      Class2 obj = (Class2) self; 
      obj.fill(Strign xxx);  
   } 
} 

Hope this helps.

link publish delete flag offensive edit

answered 2008-11-18 13:15:20 +0800

erdem gravatar image erdem
57

thx ..
i try but it doesn't work..
When I try to get the id of the window inside the "fill()" function, returns null not "myWin"...

Any idea ??

link publish delete flag offensive edit

answered 2008-11-18 14:08:20 +0800

ziccardi gravatar image ziccardi
321 7

I tried this and it worked for me...

<zk>
<zscript>

    
    class Class2 extends Window
    {
        public void sayHello()
        {
           alert("Hello World!!");
        }
    }
    
    class Class1 extends org.zkoss.zk.ui.util.GenericForwardComposer
    {
         public void onClick$myBtn(Event evt)
         {
              ((Class2) self).sayHello();
         }

    }
    
</zscript>

<window apply="Class1" use="Class2">
   <button id="myBtn" label="ClickHere"/>
</window>

</zk>

link publish delete flag offensive edit

answered 2008-11-19 08:29:53 +0800

hkn gravatar image hkn
246 3

Hello,

I use a single class as a controller which is both, the window and the composer:
In may case, workspace and db are just simple singletons. ws is more or less a shortcut for session and db implements the business logic and data access and transactions.

public abstract class CrtlBase extends Window implements AfterCompose {
protected AnnotateDataBinder binder;
protected Workspace ws;
protected Db db;
protected Map<String, Object> args;

public void doOnCreateCommon(Window w) throws Exception {
binder = new AnnotateDataBinder(w);
binder.loadAll();
ws = Workspace.getWorkspace();
db = ws.getDb();
}

public void doOnCreateCommon(Window w, Event fe) throws Exception {
doOnCreateCommon( w );
CreateEvent ce = (CreateEvent)((ForwardEvent)fe).getOrigin();
args = (Map<String, Object>) ce.getArg();
}

public CrtlBase() {
super();
}

public void afterCompose() {
Components.wireVariables(this, this);
Components.addForwards(this, this);
}
}


In my Apps I extend most of may window classes as:

public class CrtlPdfView extends CrtlBase {
protected Window pdfView;
protected Toolbarbutton btnView;
protected Toolbarbutton btnNew;
protected Listbox lbPdf;
private ListModelList lml;
public void onCreate$pdfView(Event ev) throws Exception {
doOnCreateCommon(pdfView);
lml = new ListModelList(db.getListMdbPdf(), false);
lbPdf.setModel(lml);
lbPdf.setItemRenderer(new MdbPdfRenderer());
btnView.setDisabled(true);
}
public void onSelect$lbPdf(Event e) {
btnView.setDisabled(false);
}

public void onClick$btnNew(Event e) {
MdbPdf newPdf = new MdbPdf();
HashMap<String, Object> arg = new HashMap<String, Object>();
arg.put("data", newPdf);
Window win = (Window) Executions.getCurrent().createComponents("/inc/pdf/pdfFind.zul", null, arg);
win.doModal();
....
}
}

the zul file for this extract is like:
<?xml version="1.0" encoding="UTF-8"?>
<z:window ..... id="pdfView" use="de.nbcon.cfp.crtl.CrtlPdfView">
<z:toolbar>
<z:toolbarbutton id="btnNew" label="New"...../>
<z:toolbarbutton id="btnView" label="View" ..../>
</z:toolbar>
<z:listbox id="lbPdf" .....>
<z:listhead>
<z:listheader label="Publication No." sort="none" width="150px" />
<z:listheader label="PDF" sort="none" width="250px" />
<z:listheader label="Size" sort="none" width="100px" />
</z:listhead>
</z:listbox>
</z:window>

That works fine and I can combine composer and window controller. In my zul files you will find no
scripting, it is really just the "VIEW". Maybe this approach fits your needs too.

Good luck!
Horst

link publish delete flag offensive edit

answered 2008-11-19 14:18:54 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

erdem,

In what context, you will call the fillListbox() of class2? In a event listener? It is better give an example and use case that the community can give you suggestion.

link publish delete flag offensive edit

answered 2008-11-19 14:52:56 +0800

erdem gravatar image erdem
57

updated 2008-11-19 15:10:56 +0800

i am using a chat application and different users could be online at the same time and also i want to show the online people who are in chat now..

So when a user enters the chatroom, then i want to refresh the Online list for all users, so i try to trigger "fillListbox()" function to refresh the list...
how i can i provide this ??

link publish delete flag offensive edit

answered 2008-11-19 21:09:55 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

@hkn (Horst)

Hy Horst,

your code snippets are the way i would go with my app. But at time i have problems with the spring managed beans (scope).
I would try a few days more on it.
Horst, are you german?
It's possible that you can have a look at my early code, if i go the false or right way?

thx
Stephan

link publish delete flag offensive edit

answered 2008-11-20 07:51:17 +0800

ziccardi gravatar image ziccardi
321 7

Hi erdem.

I think you need server push.
This link should be useful : http://www.zkoss.org/smalltalks/listmodelsharer/

link publish delete flag offensive edit

answered 2008-11-20 09:13:31 +0800

hkn gravatar image hkn
246 3

@terrytornado (Stephan)

Hi Stephan,

yes I am german and I am a enthusiastic learner of zk.
If you like I will have a look on your approach (hopefully I can learn something :D).
You can contact me directly via hne at nbcon dot de

by

link publish delete flag offensive edit

answered 2008-11-20 10:57:28 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

@hkn

thx Horst,
nice to hear that.
I would contact you in the next days.
First a friend must check the cvs account that you can checkout my test project.

Stephan
sge at forsthaus dot de

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: 2008-11-18 11:37:13 +0800

Seen: 582 times

Last updated: Nov 21 '08

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