-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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");
}
}
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/
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?
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
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
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
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
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>
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>
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
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
Asked: 2007-12-19 17:09:05 +0800
Seen: 1,483 times
Last updated: Jan 09 '08