Humbly submitted for your approval:
Wanting to be able to have checkboxes automatically be set correctly by
form submissions, I propose to add a method to ActionForm called
getBooleanProperties, which will return an array of strings, which
correspond to properties that are boolean in nature. RequestUtils.populate
uses this list to clear all the properties to false before processing the
request parameters, ensuring that if a checkbox is set, and then cleared on
a resubmit, the bean property is appropriately updated to false.
And yes, I've coded around this by examining the request in the validate
method and hand-setting the properties if they aren't found in the request,
but it limits the utility of validate then, since I can't use it on final
submission (I use 4 different forms in a larger transaction) to validate
each form one last time.
Whaddya think?
James
Index: ActionForm.java
===================================================================
RCS file:
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/action/ActionForm.java,v
retrieving revision 1.10
diff -u -r1.10 ActionForm.java
--- ActionForm.java 21 Nov 2001 13:59:28 -0000 1.10
+++ ActionForm.java 12 May 2002 05:24:42 -0000
@@ -120,6 +120,16 @@
/**
+ * Define any form fields properties associated with booleans such as
checkboxes, which
+ * will not be cleared by normal HTTP request processing. These
properties will be set to
+ * false manually by RequestUtils.populate
+ */
+
+ public String[] getBooleanProperties() {
+ return null;
+ }
+
+ /**
* Return the controller servlet instance to which we are attached.
*/
protected ActionServlet getServlet() {
Index: RequestUtils.java
===================================================================
RCS file:
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v
retrieving revision 1.35
diff -u -r1.35 RequestUtils.java
--- RequestUtils.java 8 Apr 2002 04:30:41 -0000 1.35
+++ RequestUtils.java 12 May 2002 05:25:06 -0000
@@ -934,6 +934,20 @@
request.removeAttribute(Action.MAPPING_KEY);
}
+ /* Set any boolean fields to false before iterating over properties */
+ String[] booleanProperties = ((ActionForm)bean).getBooleanProperties();
+ if (booleanProperties != null) {
+ for (int i = 0; i < booleanProperties.length; i++) {
+ properties.put(booleanProperties[i], "false");
+ }
+ try {
+ BeanUtils.populate(bean, properties);
+ } catch (Exception e) {
+ throw new ServletException("BeanUtils.populate", e);
+ }
+ properties.clear();
+ }
+
if (!isMultipart) {
names = request.getParameterNames();
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>