Replacing processing window, getting SpringUtil can be called only under ZK environment error

asked 2017-03-15 17:58:15 +0800

davidzhaos gravatar image davidzhaos

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); 

    <cell align="center" Colspan="2">   
         <button label="Search" id="SearchButton" >
            <attribute name="onClick">

<script type="text/javascript"><![CDATA[
        function showBusy () {
            // show busy mask
            // move abort button under busy message
        function clearBusy () {
            // move abort button back under abort div
            // clear busy mask
        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
            new Thread(ar).start();
        void abort () {
            // abort
            // reset
            ar = new AbortableRunnable();
        void finish () {
            // finish
            // reset
            ar = new AbortableRunnable();

   <div id="abortDiv" style="position: absolute; left: -1000px; top: -1000px">
        <button id="abortButton" label="Cancel">
            <attribute name="onClick">
                // abort the running process
                // move self element back to abort div
                // and clear the busy mask

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);


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?

delete flag offensive retag edit


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

2 Answers

Sort by ยป oldest newest most voted

answered 2017-03-16 02:14:46 +0800

cor3000 gravatar image cor3000
4887 2 7
ZK Team

updated 2017-03-16 02:15:06 +0800

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.


link publish delete flag offensive edit

answered 2019-11-06 19:43:08 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2621 3 8

I had the same problem

link publish delete flag offensive edit


thanks for sharing ...

cor3000 ( 2019-11-06 21:49:05 +0800 )edit

that's better, thanks!

cor3000 ( 2019-11-07 10:12:12 +0800 )edit
Your answer
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

1 follower



Asked: 2017-03-15 17:58:15 +0800

Seen: 50 times

Last updated: Nov 06

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