File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts ActionForm: Request parameter name beginning with upper-case letter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts ActionForm: Request parameter name beginning with upper-case letter" Watch "Struts ActionForm: Request parameter name beginning with upper-case letter" New topic
Author

Struts ActionForm: Request parameter name beginning with upper-case letter

Mahesh Babu
Greenhorn

Joined: Mar 06, 2004
Posts: 1
Hello Struts experts,
The ActionForm setter method is not being called for request parameters whose names begin with an upper-case letter. For example, my HTTP request is of the form ?Foo=1 (i.e., the HTTP request parameter name is "Foo") and my ActionForm subclass has setFoo(String) method defined. The setFoo method is not being called. On the other hand, if my HTTP request is of the form ?foo=1 then the setter is being called.
I have to convert an existing web application to use Struts, and the existing application has numerous HTTP request parameters whose names begin with an upper case-letter followed by lower-case letters. So, it is not very practical for all my HTTP request parameters named "Foo" to be renamed to "foo".
Can someone please suggest a solution?
Thank you.
Srikanth Shenoy
author
Ranch Hand

Joined: Jan 24, 2004
Posts: 184
Unfortunately your case does not have any good solution.
There isnt any out of the box solution either.
I suggest you try the following approach.

1) Create your own subclass of RequestProcessor (or of TilesRequestProcessor if you use it)
2) Override the processPopulate() method in RequestProcessor with your own implementation. This method is the one that populates the Form bean from request using RequestUtils and Commons BeanUtils.
3) Create your own subclass for RequestUtils and implement the populate() method. In that method, get the request parameter names, covnert the first char of the request parameter to lower case and then do exactly what that method is doing.

I know this isnt exactly an elegant solution. But at the end of the day it is all about trade-offs. This solution eliminates the need to change your entire application, unit test and then functional test, not to mention the dollars needed for such an elaborate process. This solution should work without a hitch. Try it out.
Also when you are done, could you please share your experiences in this forum?
Thanks,
Srikanth Shenoy
Author: Struts Survival Guide - Basics to Best Practices


Srikanth Shenoy
Author of Struts Survival Guide : Basics to Best Practices
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts ActionForm: Request parameter name beginning with upper-case letter
 
Similar Threads
struts-error
Setting up form data
Session in Struts
how values are mapped?
Tag Libraries