1

I have rich:popupPanel which contains t:dataList under one column of t:dataTable. This dataList has h:commandLink which has f:param inside it. It was working fine for richfaces 3.3 but after migration to richfaces 4, it stopped working. To mention the fact that I was using rich:modalPanel in place of rich:popupPanel over there. I went through quite a few links:

https://community.jboss.org/thread/202583

commandButton/commandLink/ajax action/listener method not invoked or input value not updated

but of no help :(. Am I missing something? Currently, bean is session-scoped and I am using getter to fetch the data model as its not possible for me to put it in constructor.

Please let me know, if someone has idea about it.

PS: Rendered HTML equivalent looks like this. It has request parameter varPath but in backing bean we get it as null.

<a onclick="return myfaces.oam.submitForm('actionForm','actionForm:j_id0',null,    [['varPath','/Link']]);" href="#" tabindex="-1" accesskey="">/Link</a>
Community
  • 1
  • 1
A.G.
  • 734
  • 2
  • 8
  • 27
  • Could you provide us with a more detailed code example? The page containing the popup panel and dataList would be very helpful – tasel Aug 28 '12 at 11:13
  • Thanks. issue got resolved by changing encType of form to "application/x-www-form-urlencoded". Not sure how it works! – A.G. Aug 28 '12 at 12:28

4 Answers4

4

Figured out that changing the encType of form to "application/x-www-form-urlencoded" from "multipart/form-data" resolves this issue. Strange though! Not sure why it didn't work with multipart encryption.

First of all, it's not an encryption, but an encoding. The difference is pretty huge. "Encrypting" is a way of changing the value in such way which is not predictable without having kind of a security key (cipher key, seed, etc). "Encoding" is a way of changing the value in such way that it's acceptable by the data transfer mechanism and/or that it's recognizeable/parseable by the other side without loss of any data. The values are not made unreadable or something, they are just arranged somewhat specific and differently.

Coming back to your concrete problem, the multipart/formdata encoding is usually only used when you need to be able to send (upload) a file along with the form, using for example <input type="file"> or the RichFaces <rich:fileUpload> component. The standard application/x-www-form-urlencoded form encoding, which basically specifies that the request parameters should be sent URL-encoded in this format

Content-Type: application/x-www-form-urlencoded;charset=UTF-8

name1=value1&name2=value2&name3=value3

isn't suitable for passing file contents around. For that the multipart/form-data encoding should be used which basically look like this:

Content-Type: multipart/form-data;boundary=SOME_BOUNDARY

--SOME_BOUNDARY
content-disposition: form-data;name="name1"
content-type: text/plain;charset=UTF-8

value1
--SOME_BOUNDARY
content-disposition: form-data;name="name2"
content-type: text/plain;charset=UTF-8

value2
--SOME_BOUNDARY
content-disposition: form-data;name="name3"
content-type: text/plain;charset=UTF-8

value3
--SOME_BOUNDARY--

This format allows room for enclosing complete file contents in the request body.

In a JSF 2.0/2.1 web application, multipart/form-data requests are normally processed by a custom Filter. In case of RichFaces 3, this is normally processed by the org.ajax4jsf.Filter which is missing in RichFaces 4.

Note that the application/x-www-form-urlencoded is already the default encoding type of HTML forms. So you don't need to explicitly specify it yourself. Just omit the enctype attribute altogether:

<h:form>

</h:form>

and you should be all set.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks a lot BalusC for the detailed explanation. It really helped. Since, there is no get away from using encoding type as "multipart/form-data" and richfaces4. I'll try to search for the way to have custom filter in place which will fill in for "org.ajax4jsf.Filter". Please let me know, if you know good source for same. – A.G. Aug 29 '12 at 04:59
  • got hold of this article of yours: http://balusc.blogspot.in/2009/12/uploading-files-in-servlet-30.html. Trying it out. – A.G. Aug 29 '12 at 05:04
  • Just adding is not returning me the parameter values in backing bean, I am still getting them as null and these are not file parameter, simple string parameters. Do I need to write down entire custom filter for this? – A.G. Aug 29 '12 at 10:13
1

Figured out that changing the encType of form to "application/x-www-form-urlencoded" from "multipart/form-data" resolves this issue. Strange though! Not sure why it didn't work with multipart encryption.

Would still like to know the explanation behind this, if anyone knows about this.

A.G.
  • 734
  • 2
  • 8
  • 27
1

Using a4j:commandLink instead of h:commandLink pass parameters correctly which resolved this issue. No need for custom filters just for parameters.

A.G.
  • 734
  • 2
  • 8
  • 27
  • This is a workaround, not a solution. You seem to totally not understand the basic HTTP concepts nor what's going on in the HTTP request. As explained in my answer, you just have to remove the `enctype` attribute from the `` altogether in order to solve your problem. You didn't need it, after all. – BalusC Nov 20 '12 at 14:01
  • Yes. I agree with you that this is a workaround and not a solution. Unfortunately, I cannot remove encType as it is needed as multipart/form-data since images and file uploads are also there in form. I understand creating a custom filter would have been the best choice in this case but due to timing restrictions, I preferred to live with workaround only. – A.G. Nov 21 '12 at 04:37
0

CommandButton should be placed in a form tag. Sounds like you have nested form or you have no form.

HRgiger
  • 2,750
  • 26
  • 37
  • Thanks for reply. I already have surrounding the entire content. – A.G. Aug 28 '12 at 10:17
  • As I mentioned earlier, it was working fine with rich:modalPanel in richfaces 3.3 but now after migrating it to rich:popupPanel, it is causing issues. – A.G. Aug 28 '12 at 10:20
  • can you add maybe there is some output – HRgiger Aug 28 '12 at 10:36
  • Nothing on h:messages as well :(. Its already there for every dialog in application. Thanks for the suggestion though. – A.G. Aug 28 '12 at 10:39
  • Important thing I forgot to mention is that if I pass the parameters as arguments of bind method of backing bean, links work like a charm. – A.G. Aug 28 '12 at 10:41
  • so BalusC has nice answer here http://stackoverflow.com/a/8334516/706695 (if jsf 1.x) – HRgiger Aug 28 '12 at 10:42
  • Thanks again. Using commandButton is not an option over here. I am already using JSF2 and as I mentioned, passing parameters as arguments resolve the issue but it is not feasible solution as is it is used at many places in application and it requires changes in backing bean method as well to have arguments in place. I am curious to know why f:param is not working with rich:popupPanel. – A.G. Aug 28 '12 at 10:47
  • Thanks HRgiger for all the inputs. Issue got resolved. Please see answer for this. May be you can throw some light on the explanation part. – A.G. Aug 28 '12 at 12:31