0

How to comunicate Java/zscript to javascript?

asked 2008-11-10 13:15:09 +0800

carlosjulioperez gravatar image carlosjulioperez
24

Hello

Congratulatios for this cool framework.

I'm new with the zk framework. I need more performance in the zul files.

I have been mapping zk with Hibernate ussing the OpenSessionInViewListener in the zk.xml and i need to show the message exception from the db to the client via javascript (no Messagebox) because i loose performance using Messagebox.show()

This is my code:

in the index.zul:
---------------
<window id="winIndex" use="com.xxx.mw.rol.controlador.IndexWindow" width="300px">


in the com.xxx.mw.rol.controlador.IndexWindow.java:
--------------------------------------------------

public void ingresar() throws Throwable{
try{

//excluded code here

}catch(Throwable ex) {
Clients.evalJavaScript("alert('STATIC MESSAGE')");
}
}

I use the Clients.evalJavaScript to show a STATIC message but i need to show the hibernate exception message.

Actual message:
Clients.evalJavaScript("alert('STATIC MESSAGE')");

Needed message:
Clients.evalJavaScript("alert(' ? ')");

where

? = ex.toString() // Exception message from hibernate java in the SERVER SIDE.

How pass the ex.toString() java message to the Clients.evalJavaScript() function as javascript code for evaluation in the CLIENT SIDE?

Thanks for your help.

Best regards.

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2008-11-10 14:02:15 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

Clients.evalJavaScript("alert('\"+ex.toString()+\"')");
doesn't this work ?
but, you still need to escape character ' if ex.toString() has it.

link publish delete flag offensive edit

answered 2008-11-10 14:04:41 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

I think create a dynamic window or popup to show the message it better than using javascript alert .

link publish delete flag offensive edit

answered 2008-11-10 16:14:59 +0800

carlosjulioperez gravatar image carlosjulioperez
24

Are the dynamic window or dynamic popup more efficient that javascript alert() y the client side? Why?

Thanks for your suggestions.

Best regards.

link publish delete flag offensive edit

answered 2008-11-10 17:04:26 +0800

carlosjulioperez gravatar image carlosjulioperez
24

The code:

Clients.evalJavaScript("alert(' \"+ex.toString()+\" ')");

Shows the next text: "+ex.toString()+"

Any suggestions?

link publish delete flag offensive edit

answered 2008-11-10 17:42:48 +0800

carlosjulioperez gravatar image carlosjulioperez
24

Cool...

I wrote this code:

String str = ex.toString();
Clients.evalJavaScript("alert(' "+str+" ')");

and fixed it...

Thanks for all dennis!

Greetings from Ecuador.
Best regards.

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-10 13:15:09 +0800

Seen: 471 times

Last updated: Nov 10 '08

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