Created another ticket here https://forum.zkoss.org/question/111727/zk-long-operation-with-hibernate-issue/
Senthilchettyin ( 2019-11-06 22:33:10 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
When my application performs a search, it might take a long time so I want to replace the standard processing window with my own processing window with a cancel option.
I added my own java-script to create my custom processing window. This is the part of the ZUL file:
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <?init class="org.zkoss.zkplusenter code here.databind.AnnotateDataBinderInit" arg0="./searchWin" ?> <window id="searchWin" title="Advanced Search" border="normal" closable="true" apply="swt.documation.ng.web.zk.SearchComposer" width="600px">
<attribute name="onOK">
Events.postEvent("onClick", imgBtn, null);
</attribute>
<row>
<cell align="center" Colspan="2">
<button label="Search" id="SearchButton" >
<attribute name="onClick">
start();
Clients.evalJavaScript("showBusy();");
</attribute>
</button>
</cell>
</row>
<script type="text/javascript"><![CDATA[
function showBusy () {
// show busy mask
zAu.cmd0.showBusy('Loading...');
// move abort button under busy message
jq('.z-loading')[0].appendChild(jq('$abortButton')[0]);
}
function clearBusy () {
// move abort button back under abort div
jq('$abortDiv')[0].appendChild(jq('$abortButton')[0]);
// clear busy mask
zAu.cmd0.clearBusy(null);
}
]]></script>
<zscript><![CDATA[
class AbortableRunnable implements Runnable {
boolean aborted = false;
int i = 0;
public void run () {
// search
var windowWidget = zk.Widget.$("$_searchWin");
zAu.send(new zk.Event(windowWidget, "onSearch",null));
}
public void abort () {
aborted = true;
}
public int getI () {
return i;
}
}
AbortableRunnable ar = new AbortableRunnable();
void start () {
// start
System.out.println("started");
new Thread(ar).start();
}
void abort () {
// abort
System.out.println("aborted");
ar.abort();
// reset
ar = new AbortableRunnable();
}
void finish () {
// finish
System.out.println("finished");
// reset
ar = new AbortableRunnable();
}
]]></zscript>
<div id="abortDiv" style="position: absolute; left: -1000px; top: -1000px">
<button id="abortButton" label="Cancel">
<attribute name="onClick">
// abort the running process
abort();
// move self element back to abort div
// and clear the busy mask
Clients.evalJavaScript("clearBusy();");
</attribute>
</button>
</div>
This is my part of my java class:
public class SearchComposer extends GenericForwardComposer {
private LibraryService libraryService = (LibraryService)SpringUtil.getBean("libraryService");
public void onSearch(ForwardEvent event) throws InterruptedException {
if (ResourceManager.getUserCabinets().size() == 0)
{
Messagebox.show("You do not have cabinet access to any cabinets.", "Documation Library", Messagebox.OK, Messagebox.EXCLAMATION);
return;
}
}
When I test this, I get "Exception in thread "Thread-38" org.zkoss.zk.ui.UiException: SpringUtil can be called only under ZK environment!", any suggestion on how I can fix this?
Hi David,
your problem seems related to ONLY this line (your complete example above is unrelated).
private LibraryService libraryService = (LibraryService)SpringUtil.getBean("libraryService");
Usually there is no such problem. The SearchComposer is instantiated by ZK during page rendering (which happens inside an active Execution - means under control of ZK) and you won't get this error. However if you try to instantiate the SearchComposer in a separate thread that's not ZK related ZK will complain about it and throw the exception you encounter. See: https://github.com/zkoss/zk/blob/v6.5.3/zkplus/src/org/zkoss/zkplus/spring/SpringUtil.java#L39
If you can provide the stack trace of your exception it might give some details on what's going on.
In the end your custom show/clear busy code has nothing to do with it.
Robert
I had the same problem
Created another ticket here https://forum.zkoss.org/question/111727/zk-long-operation-with-hibernate-issue/
Senthilchettyin ( 2019-11-06 22:33:10 +0800 )editAsked: 2017-03-15 17:58:15 +0800
Seen: 55 times
Last updated: Nov 06 '19
wrong valueException come in front of modal popup [closed]
Use parameters in a conditional @command
Problems with multiple press and onCtrlKey
MVVM @save on the fly [closed]
Unable to activate destroyed desktop
org.zkoss.zk.ui.UiException: java.lang.ClassNotFoundException
How to put a image or Letter over image on a specific XY Coordinate
btw: your AbortRunnable class doesn't make any sense, it seems to mix java and javascript code. What's the purpose of it?
cor3000 ( 2017-03-16 02:18:13 +0800 )edit