0

Executions.getCurrent().getDesktop() problem

asked 2007-12-19 17:09:05 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4683116

By: davetam

Hello,

It seems that with this code (compiled) the WebApp return is null and hence I get a NullPointerException. However the desktop I get from zscript (put the code in zscript block in zul, replace Executions.getCurrent().getDesktop() with desktop ) ran ok.

Am I doing something wrong?


import java.io.InputStream;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.WebApp;
import org.zkoss.zul.Window;

public class GenericListBoxWindow extends Window{


public RerunConsoleWindow() {
super();
this.init();
}

public RerunConsoleWindow(String title,
String border,
boolean closable) {
super(title, border, closable);
this.init();
}

private void init(){
Desktop desktop = Executions.getCurrent().getDesktop();
WebApp webapp = desktop.getWebApp();
InputStream iStream = webapp.getResourceAsStream("/sql/query.sql");

}

}

delete flag offensive retag edit

11 Replies

Sort by ยป oldest newest

answered 2007-12-20 01:09:32 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4683996

By: jebberwocky

Dear Dave

Is there any reason that you don't use composer? Take a look at http://www.zkoss.org/smalltalks/mvc/

link publish delete flag offensive edit

answered 2007-12-21 23:10:51 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4687311

By: davetam

hi jebberwocky,

RTis is what I am doing but it is still giving me NullPointerException. (on the desktop.getWebApp() line)

Here is my Composer:

public class MyController extends GenericComposer{

public void onMakeWindow(Event evt){
Desktop desktop = Executions.getCurrent().getDesktop();
WebApp webapp = desktop.getWebApp();
InputStream iStream = webapp.getResourceAsStream("/sql/query.sql");
}

}

And the zul:


<zk>
<vbox width="100%" id="div">
<window apply="MyController "
forward="onCreate=onMakeWindow"/>
</vbox>
</zk>

Should I be using other event rather than create?

link publish delete flag offensive edit

answered 2008-01-02 17:47:46 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4698309

By: davetam

Anyone has the same problem?

I have also try to put the block:

WebApp webapp = desktop.getWebApp();
InputStream iStream = webapp.getResourceAsStream("/sql/query.sql");

into doAfterCompose but I am still getting the same error.

Any input are welcome!

Dave

link publish delete flag offensive edit

answered 2008-01-03 00:58:39 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4698822

By: henrichen

You cannot call getDesktop() directly or indirectly (init()) in GenericListBoxWindow consturctor; or you will always get a null desktop.

ZK engine new a GenericListBoxWindow (where the constructor is called) then
setPage() or setParent to connect the window object to the desktop. You have to move your code to onCreate() codes.

/henri

link publish delete flag offensive edit

answered 2008-01-03 09:54:06 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4699271

By: davetam

hi actually I have tried to put it inside both onCreate and doAfterCompose but still I am getting the same error and it seems that I can get the desktop without problem but NullPointerException on this:

WebApp webapp = desktop.getWebApp();

when I try to get the webapp it is null.


Dave

link publish delete flag offensive edit

answered 2008-01-04 00:35:02 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4700558

By: henrichen

Then please provide sample code that will replicate the issue. Help us to help you.

/henri

link publish delete flag offensive edit

answered 2008-01-04 10:43:35 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4701030

By: davetam

hi I have already post the code but I can repost (with the doAfterCompose).
In both cases (change zul to test) desktop.getWebApp() will return a null WebApp


public class MyController extends GenericComposer{

public void onMakeWindow(Event evt){
Desktop desktop = Executions.getCurrent().getDesktop();
WebApp webapp = desktop.getWebApp();
InputStream iStream = webapp.getResourceAsStream("/sql/query.sql");
}


public void doAfterCompose(Component comp) throws Exception{ Desktop desktop = Executions.getCurrent().getDesktop();
WebApp webapp = desktop.getWebApp();
InputStream iStream = webapp.getResourceAsStream("/sql/query.sql");
}
}

And the zul:


<zk>
<vbox width="100%" id="div">
<window apply="MyController "
forward="onCreate=onMakeWindow"/>
</vbox>
</zk>

link publish delete flag offensive edit

answered 2008-01-07 08:01:54 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4706998

By: henrichen

try this

/henri
----
<zk>
<zscript>

public class MyController extends org.zkoss.zk.ui.util.GenericComposer{
public void onCreate(){
Desktop desktop = Executions.getCurrent().getDesktop();
WebApp webapp = desktop.getWebApp();
alert("onCreate:"+webapp);
}
}
</zscript>
<window apply="MyController" />
</zk>


link publish delete flag offensive edit

answered 2008-01-09 10:08:47 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4711464

By: davetam

Hi Henri,

I think you missed my point here. If I put the code in zscript it would work but when I moved it inside a compiled Composer method it fails over.

So are you suggesting Executions.getCurrent().getDesktop().getWebApp() will not return a valid webapp in a compiled Composer?

regards,

Dave

link publish delete flag offensive edit

answered 2008-01-09 11:19:45 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4711565

By: henrichen

What I mean is that "It works for me". Yes, I have moved the code inside a compiled Composer and it WORKS perfect. I tend to give example code in zscipt because it is easier for testing (since you don't have to compile the java code :)).
However, "it WORKS".

---
MyController.java
---
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.WebApp;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zul.Messagebox;

public class MyController extends org.zkoss.zk.ui.util.GenericComposer{
public void onCreate(){
Desktop desktop = Executions.getCurrent().getDesktop();
WebApp webapp = desktop.getWebApp();
try {
Messagebox.show("onCreate:"+webapp);
} catch (InterruptedException ex) {
System.out.println(ex);
}
}
}

---
mycontroller.zul
---
<window apply="MyController" />


You should see a Messagebox appear with a "NONE-NULL" WebApp object.
Maybe you want to download the lastest version of ZK and try again. I guess that is the only difference between your environment and mine.

/henri


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: 2007-12-19 17:09:05 +0800

Seen: 1,483 times

Last updated: Jan 09 '08

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