Problem with p:fileUpload in a @ConversationScoped context

UI Components for JSF
andersaa
Posts: 20
Joined: 11 May 2010, 16:16

18 Jun 2010, 10:10

Hi guys
We have converted our controllers from using @SessionScoped to @ConversationScoped. This means that all conversations get a unique id (cid) that needs
to be passed around on the url so that the server knows the active conversation (one user can have multiple active conversations).

This seems to cause problems with the p:fileUpload component. When a user uploads a file, the POST request seems to trigger a new conversation and
hence a new instance of our controller. We suspect that this happens because the fileUpload flash component is not aware of the cid parameter and does
not pass it back to the server. Does anyone know if this could be the case? It is a bit difficult to debug this since Firebug does not capture the requests
from Flash components.

Any suggestions for workarounds?
And another thing.. If a parameter for disabling flash upload was implemented as suggested here:
http://code.google.com/p/primefaces/iss ... ail?id=622

Would that fix the problem? I will try to remove flash to see if this is the case.

By the way, we are using PF 2.0.2 and Glassfish 3.0.1.

Regards,
Anders

andersaa
Posts: 20
Joined: 11 May 2010, 16:16

18 Jun 2010, 10:59

Maybe I found the root of the problem.. When I do request.getParameter("cid") in a filter after the POST operation, I get this string:
2;jsessionid=a42e6f4100c73bf78434b514b323

So maybe the ; is escaped somewhere, or the param string is parsed incorrectly in the swf? Will try to remove the jsessionid param and
see what happens then.

Regards,
Anders

andersaa
Posts: 20
Joined: 11 May 2010, 16:16

18 Jun 2010, 11:15

Some more info after debugging.. In the html source, it looks loke parameters are passed correctly to the FileUpload JS widget:

fileUploadWidget = new PrimeFaces.widget.Uploader('fwMainContentForm:fileUpload', {uploader:'/admin/primefaces_resource/2.0.1/jquery/plugins/uploadify/uploadify.swf',script:'/admin/editListProposal.xhtml?cid=2',cancelImg:'/admin/primefaces_resource/2.0.1/jquery/plugins/uploadify/cancel.png',formId:'fwMainContentForm',fileDataName:'fwMainContentForm_fileUpload_file',multi:false,auto:true,inputFileId:'fwMainContentForm_fileUpload_file',update:'fwMainContentForm:msg,fwMainContentForm:candidatesDataTable,fwMainContentForm:columnDialog',buttonImg:'resources/images/tmpLinkUploadButton.png',fileExt:'*.xls;*.xlsx;',fileDesc:'Excel'});});

But when I look at the Object tag using Firebug, it has a flashvars param:

<param name="flashvars" value="uploadifyID=fwMainContentForm_fileUpload_file&pagepath=/admin/&buttonImg=resources/images/tmpLinkUploadButton.png&script=/admin/editListProposal.xhtml?cid=2;jsessionid=a42e6f4100c73bf78434b514b323&folder=&scriptData=primefacesPartialRequest%3Dtrue%26primefacesPartialProcess%3DfwMainContentForm%3AfileUpload%26javax.faces.ViewState%3D-8263407675654580702%3A-2571155772809828821%26primefacesPartialUpdate%3DfwMainContentForm%3Amsg%2CfwMainContentForm%3AcandidatesDataTable%2CfwMainContentForm%3AcolumnDialog&width=110&height=30&wmode=opaque&method=POST&queueSizeLimit=999&simUploadLimit=1&fileDesc=Excel&fileExt=*.xls;*.xlsx;&auto=true&fileDataName=fwMainContentForm_fileUpload_file">

Not very readable, but it looks like the jsessionid parameter is somehow inserted in the process of injecting the flash component.

-Anders

andersaa
Posts: 20
Joined: 11 May 2010, 16:16

18 Jun 2010, 17:33

I think I found the bug.. The jsessionid=xxx is appended to the URL in uploader.js. This works as long as there are no parameters in the URL, but in our case there is a ?cid=xxx present so that the appended url becomes like this:
/admin/editListProposal.xhtml?cid=2;jsessionid=a42e6f4100c73bf78434b514b323

I have patched uploader.js to check for a ? in the url, and in this case append ;jssessionid before ?. I have changed the if-test in uploader.js line 53 to:

Code: Select all

	if(this.cfg.script.indexOf('jsessionid') == -1) {
		paramIndex = this.cfg.script.indexOf('?');
		if (paramIndex != -1) {
			this.cfg.script = this.cfg.script.substring(0, paramIndex) + ";jsessionid=" + jsessionid + this.cfg.script.substring(paramIndex);
		}
		else {
			this.cfg.script = this.cfg.script + ";jsessionid=" + jsessionid; 
		}
	}
If you're reading this Cagatay, does this look like something that can be added to to the next build?

Regards,
Anders

cerdiogenes
Posts: 1
Joined: 24 Jun 2010, 16:35

24 Jun 2010, 16:56

This solution worked for you andersaa? I'm doing exactly what you are doing, moving a bean from @SessionScoped to @ConverstaionScoped.

With your patch now I'm able to submit the file when a conversation is active, but after this, when I call other method in my conversational bean, the file is not there anymore. Do you also have this issue?

Best regards,
Carlos.

andersaa
Posts: 20
Joined: 11 May 2010, 16:16

29 Jun 2010, 13:16

We have now found out that although the fileUpload is working, somehow the file ends up in the wrong conversation. I suspected the problem was with our handling of conversations, but if you have the same problem then there must be something else strange going on.. Will try to strip it down to a very simple controller to try to reproduce the problem once I get time.

But the patch above at least solves one problem.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

29 Jun 2010, 13:54

Hi anders,

Can you please create an issue ticket in our issue tracker? Sure we can add the fix targeting upcoming version.

andersaa
Posts: 20
Joined: 11 May 2010, 16:16

30 Jun 2010, 10:07

Great!

http://code.google.com/p/primefaces/iss ... ail?id=963

We are still investigating the problem and have now made a simple project with one template and one controller that provokes the next error. Suspect this is a problem in Glassfish/Weld and not in Primefaces, but would like to test fileUpload in non-flash mode to see if this works. Posted another forum topic about this:
http://primefaces.prime.com.tr/forum/vi ... f=3&t=3067

Thanks for helping!

-Anders

andersaa
Posts: 20
Joined: 11 May 2010, 16:16

30 Jun 2010, 12:35

I have now reproduced the problem on Tomcat 7.0 Beta 1 where we have more control over the libraries (not easy to replace Weld in Glassfish for instance). So it's not a Glassfish issue.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

01 Jul 2010, 18:56

Thanks for the issue and detailed description, I still don't know even you've tried with your patch, it ends up in wrong conversation.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 40 guests