0

Fileupload and event processing thread

asked 2009-04-15 09:36:27 +0800

paoloa gravatar image paoloa
24 1 2

I'm trying to use Fileupload.get() to upload an image from a detail-edit section of a web page
generated with the ZETA form builder,
which I have modified, trying to adapt the code found in the Fileupload example of the zkdemo application.
The page manages an "album" table, representing a collection of audio files.
The image is the cover image of the album.

In album.ZUL I have:

<button id="imageUpload" label="Upload" />

In AlbumControllerBase.java:

	@Resource
	protected Button imageUpload;
	@Resource
	protected Vbox image;

	........
	
	@EventHandler("imageUpload.onClick")
	public void doImageUpload(Event event)
	{
		try
		{
			Media media = Fileupload.get();
		
			if (media instanceof org.zkoss.image.Image) 
			{
				org.zkoss.zul.Image image = new org.zkoss.zul.Image();
				image.setContent((org.zkoss.image.Image)media);
				image.setParent(this.image);
			} 
			else if (media != null)
			{
				Messagebox.show("Not an image: " + media, "Error", Messagebox.OK, Messagebox.ERROR);
			}
		}
		catch (InterruptedException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

When I press the image upload button, i get the following exception:

15-Apr-2009 11:02:50 org.zkoss.zk.ui.impl.UiEngineImpl handleError:1108
SEVERE: >>org.zkoss.zk.ui.SuspendNotAllowedException: Event processing thread is disabled
>>	at org.zkoss.zul.Window.doModal(Window.java:539)
>>	at org.zkoss.zul.Fileupload.get(Fileupload.java:335)
>>	at org.zkoss.zul.Fileupload.get(Fileupload.java:300)
>>	at org.zkoss.zul.Fileupload.get(Fileupload.java:233)
>>	at org.zkoss.zul.Fileupload.get(Fileupload.java:187)
>>...

Should not be event processing thread enabled by default?

Anyway, I tried to manually enable the event thread by adding the following lines
at the beginning of the try block in the event handler method:

Desktop desktop = Executions.getCurrent().getDesktop();
desktop.getWebApp().getConfiguration().enableEventThread(true);

and i got the following exception instead:

15-Apr-2009 11:21:11 org.zkoss.zk.ui.impl.UiEngineImpl handleError:1108
SEVERE: >>org.zkoss.zk.ui.UiException: This method can be called only in an event listener, not in paging loading.
>>	at org.zkoss.zk.ui.impl.UiEngineImpl.wait(UiEngineImpl.java:1246)
>>	at org.zkoss.zk.ui.Executions.wait(Executions.java:347)
>>	at org.zkoss.zul.Window.enterModal(Window.java:619)
>>	at org.zkoss.zul.Window.doModal(Window.java:555)
>>	at org.zkoss.zul.Fileupload.get(Fileupload.java:335)
>>...

delete flag offensive retag edit

13 Replies

Sort by ยป oldest newest

answered 2009-04-15 11:05:15 +0800

hideokidd gravatar image hideokidd
750 1 2

updated 2009-04-15 11:07:56 +0800

hi,

The error seems occurred from

else if (media != null)
{
	Messagebox.show("Not an image: " + media, "Error", Messagebox.OK, Messagebox.ERROR);
}

and that's because you disable event processing threads

from the page,
http://docs.zkoss.org/wiki/Performance_tip#Use_the_Servlet_Thread_to_Process_Events
There are two options to solve this
1.Remove following setting from zk.xml(this will enable event processing threads)

<system-config>
    <disable-event-thread/>
</system-config>

2.Overwrite the messagebox (following is just an example from the page)

Messagebox.show("Delete?", "Prompt", Messagebox.YES|Messagebox.NO,
     Messagebox.QUESTION,
     new EventListener() {
         public void onEvent(Event evt) {
             switch (((Integer)evt.getData()).intValue()) {
             case Messagebox.YES: doYes(); break; //the Yes button is pressed
             case Messagebox.NO: doNo(); break; //the No button is pressed
             }
         }
     }
 );

link publish delete flag offensive edit

answered 2009-04-18 09:14:32 +0800

paoloa gravatar image paoloa
24 1 2

Hi hideokidd,
1) as you can see in the stacktrace, the exception occurred
from the doModal() method called by Fileupload.get().
2) I have no disable-event-thread element in my zk.xml file.
The file, automatically created by ZK Studio,
contains only an empty <zk></zk> root element.
So the event thread should be enabed by default.
3) when I enabled the event thread by code (see my previous message),
another exception was thrown, with message
"This method can be called only in an event listener, not in paging loading."
But the method from which I call Fileupload.get(), and indirecly do Modal(),
*is* an event listener, and is called in response to the button click event.

link publish delete flag offensive edit

answered 2009-04-20 02:45:16 +0800

hideokidd gravatar image hideokidd
750 1 2

Hi,

Ok, that seems as a bug,
could you post it to zk bug with some description or sample code?
http://sourceforge.net/tracker/?group_id=152762&atid=785191
Thanks.

link publish delete flag offensive edit

answered 2009-04-27 11:45:00 +0800

paoloa gravatar image paoloa
24 1 2

I've finally found a partially satifying solution.
I don't know if this one could be considered a bug, but surely can be considered something annoying.

The docs say that the doModal() method can only be called from inside an EventListener.
It is called by the FileUpload.get() method, which is called from the controller class.

In this case EventListener means a class registered as eventlistener in ZK configuration
(and this fact IMO should be clearly stated in doModal javadoc,
because the term 'EventListener' can easily lead to misunderstandings)

The Configuration.addListener() javadoc says:
"the listener class must implement at least one of Monitor, PerformanceMeter, EventThreadInit,
EventThreadCleanup, EventThreadSuspend, EventThreadResume, WebAppInit, WebAppCleanup, SessionInit,
SessionCleanup, DesktopInit, DesktopCleanup, ExecutionInit, ExecutionCleanup, URIInterceptor,
RequestInterceptor, UiLifeCycle, and/or EventInterceptor interfaces"

So, I declared an eventlistener in zk.xml:

<listener>
	<listener-class>artsite.album.AlbumController</listener-class>
</listener>		

and implemented the EventThreadInit interface (I choosed anyone of the listed interfaces)
in the AlbumController class, with empty interface methods

This way it works, but there is still a little problem (and maybe this is really a bug):
for a reason I can't figure out, the first time I press the 'Upload' button,
and the doModal method is called, the exception is still thrown and I see the message
"This method can be called only in an event listener, not in paging loading."
in a message box.
But the second time I click the button (and for all subsequent clicks),
the modal dialog appears correctly without exceptions.

link publish delete flag offensive edit

answered 2009-04-28 03:23:29 +0800

hideokidd gravatar image hideokidd
750 1 2

Hi,

Since I have no idea how to demostrate your case,
you could post this bug with little sample code or description to zk bugs,
thanks.

link publish delete flag offensive edit

answered 2009-05-11 08:37:53 +0800

A gravatar image A
117 2

hi,
I encountered the same problem,I've finally found a solution.
I declared an element in zk.xml:

	<system-config>
	     <ui-factory-class>org.zkoss.spring.bean.ZkSpringUiFactory</ui-factory-class>
	</system-config>

link publish delete flag offensive edit

answered 2009-06-01 04:10:42 +0800

Swallow gravatar image Swallow
3

Hi A,

I has declared an element in zk.xml:

	
<system-config>
     <ui-factory-class>org.zkoss.spring.bean.ZkSpringUiFactory</ui-factory-class>
</system-config>


but i get the following exception:
Servlet.service() for servlet zkLoader threw exception
org.zkoss.zk.ui.UiException: Callable only in the event listener
	at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:289)
	at org.zkoss.zk.ui.event.Events.sendEvent(Events.java:303)
	at org.zkoss.spring.config.ZkSpringBeanBindingComposer.bindController(ZkSpringBeanBindingComposer.java:123)
	at org.zkoss.spring.config.ZkSpringBeanBindingComposer.bindControllers(ZkSpringBeanBindingComposer.java:109)
	at org.zkoss.spring.config.ZkSpringBeanBindingComposer.bindComponent(ZkSpringBeanBindingComposer.java:92)
	at org.zkoss.spring.config.ZkSpringBeanBindingComposer.doAfterCompose(ZkSpringBeanBindingComposer.java:68)
	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:637)
	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:584)
	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:528)
	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:560)
	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:528)
	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:495)
	at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:375)
	at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:296)
	at org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:229)
	at org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:166)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:99)
	at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
	at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67)
	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)
	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:116)
	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:174)
	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:277)
	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89)
	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
	at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
	at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
	at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:175)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:619)

link publish delete flag offensive edit

answered 2009-06-17 06:05:24 +0800

xiaoran27 gravatar image xiaoran27
3

same error with me.

link publish delete flag offensive edit

answered 2009-07-03 14:50:01 +0800

anupriya gravatar image anupriya
6

hi can anyone tell me how to upload file(any format) in zk. Because in most of the links, they provided solution only for image format.

link publish delete flag offensive edit

answered 2009-07-06 03:46:27 +0800

robbiecheng gravatar image robbiecheng
1144 2
http://robbiecheng.sys-co...

@anupriya,
you can upload file of any format using fileupload component. do you have any difficulty?

/robbie

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: 2009-04-15 09:36:27 +0800

Seen: 1,740 times

Last updated: Aug 10 '09

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