Umaa Mahi<br />--SCJP1.4
Umaa Mahi<br />--SCJP1.4
Error: Keyboard not attached. Press F1 to continue.
My issue was that I wanted to be able to read request parameters inside the reset() method in the action form, which is before the form bean is populated by the request processor.
I wanted to do this here to control the clearing of boolean properties used by check boxes.
Merrill
Consultant, Sima Solutions
You can certainly clear the boolean values in an ActionForm without reading the request. All you need to do is clear them, and then let the RequestProcessor populate them later on. Is it really necessary to work this hard? or is there something else you are doing besides just clearing the values?
Error: Keyboard not attached. Press F1 to continue.
Travis Hein wrote:I was always getting null request parameters inside the actionForm's reset() method when I had enctype="multipart/form-data.
I was using struts 1.2.8, and have a form with multiple fields on it and recently added a <html:file> tag.
When i do not have the enctype="multipart/form-data" in the <html:form> tag, the request parameters contain all of the values on the form, and the file upload does not work, as expected.
When I add the enctype="multipart/form-data" to the <html:form> so that the <html:file> tag will work, the file upload is working, but now the request parameters (at least from the point of view of the reset() method in the actionForm do not contain any values for the form fields. It seems that the form bean properties are being set, in that if i change a value in the field and call the getter method for this field from my form bean, it returns the correct value. Further investigation revealed that struts RequestProcessor calls RequestUtils.populate() which will extract multipart form data if it is present into request parameters, that get set onto the bean, so that is why the bean has its values by the time it got to execute().
So, if things aren't working for you, i.e. your form bean.getProperty() is not working then make sure your commons upload jar files are available.
My issue was that I wanted to be able to read request parameters inside the reset() method in the action form, which is before the form bean is populated by the request processor.
I wanted to do this here to control the clearing of boolean properties used by check boxes.
After a bit (okay, a lot) of tinkering, I came up with this method so that my action form get the request parameters inside the reset() method for multipart/form-data type requests.
Struts will wrap the request with its own MultipartRequest wrapper when it detects the multipart content type (from struts' request processor code):
So when the request object passed into the action form is an instance of the MultipartRequestWrapper, it means the form has enctype="multipart/form-data".
and request parameters are available on the http header according to RFC 1867. We can then use a the commons file upload to extract text value elements and set them onto the request wrapper.
Here is my action form that does this:
Note that in the event the form is not a multipart encoding type, the normal request.getParameter should still work.
Also note that this solution may be specific to struts 1.2(.8)
[ July 03, 2006: Message edited by: Travis Hein ]
Sunil George wrote:Now I working on a struts application. I want to change the form enctype to "multipart/form-data" for uploding some file to server. After this the request.getParameter() give only NULL values? How could i solve this to get the request.getParameter() values in action.
Thanks in advance
Sunil
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |