0

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
1

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?

delete flag offensive retag edit

Comments

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
0

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.

Robert

link publish delete flag offensive edit
-1

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

Senthilchettyin gravatar image Senthilchettyin flag of India
2621 3 8
http://emrpms.blogspot.in...

I had the same problem

link publish delete flag offensive edit

Comments

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

Follow
1 follower

RSS

Stats

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

Seen: 50 times

Last updated: Nov 06

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