You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2004/02/28 23:53:10 UTC
DO NOT REPLY [Bug 27321] New: -
Automatic invalid format handling for form bean
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=27321>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=27321
Automatic invalid format handling for form bean
Summary: Automatic invalid format handling for form bean
Product: Struts
Version: 1.1RC2
Platform: All
OS/Version: All
Status: NEW
Severity: Enhancement
Priority: Other
Component: Controller
AssignedTo: struts-dev@jakarta.apache.org
ReportedBy: enzhongfu@adelphia.net
Currently, Struts recommends all fields of ActionForm be of type String. If you
use other type (such as Date), and user inputs the value in an invalid format
so the value could not convert to the suitable type, BeanUtils would throw an
exception and it would propagate back to the user. Use only String type for
ActionForm fields can display to the user the original values they input, but
in Action class code is needed to transform from String type to type used in
business objects.
Not all people like this. Today one more developer posted it as a bug. Ideally,
we hope to use more types in a form bean while still able to display the
original inputs to the user when a validation error occurs. I think the
following solution can achieve it,
0. Basic validation, "Valid Format" and "Required", should be handled before
populating form bean.
1. In RequestProcessor class, processPopulate() should mimic processValidate().
It returns a boolean to indicate whether processPopulate is successful or not.
If not successful, it should forward to the input page like processValidate
does.
2. Instead of throwing exception, BeanUtils class should catch the exception
for populating error and continue. It returns a list of the fields that have
problem (normally invalid format). Error messages constructed based on these
fields will be stored in Globals.ERROR_KEY.
3. When there is populating error, a HashMap is created to hold the original
request parameters (all Strings, nested fields can have nested HashMaps). The
HashMap is stored at a global key (Globals.xxx) in the request.
4. The html:form tag will get the stored HashMap and put it to
Constants.BEAN_KEY for field tags to use (when there is populating error).
Thus, you can use other types in form bean (nest business objects in form bean,
for example) and Struts can still display the user's original input when in
error. I tried it on Struts1.1-rc2 and it worked.
An alternative solution is that in RequestProcessor, process() can catch the
exception and call processException(). It's up to the developer to provide
handler to deal with the invalid format. They can implement this proposal there.
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org