But in your way you are linking the presentation to the Base-Action. The original solution proposed by Marc decouples the presentation from the Action-classes. With his solution a designer can move a checkbox in a wizard-form from one page to another without any code-change. Therefor it should be a good enhancement.
regards Alexander -----Original Message----- From: Corbin, Ken [mailto:[EMAIL PROTECTED]] Sent: Donnerstag, 22. August 2002 22:21 To: [EMAIL PROTECTED] Subject: RE: solution for missing refresh of ActionForm using checkboxes The way I solved this was to have a base action class that keeps track of which fields are maintained by the current page and only resets those. That means that the data fields have to be represented by objects derived from some class or implementing an interface that accepts a reset method. And it isn't much of a step to have that interface implement common getValue and putValue methods that struts infrastructure can call to get and set text display strings. Next add some html tags to support the new data element and build the active element list and we're all set. I have this running on top of 1.02. Right now it is pretty specialized for our particular application, but it could be turned into a general feature and anyone thinks that would be a good idea. -----Original Message----- From: Christopher Book Sent: Thursday, August 22, 2002 12:05 PM To: 'Struts Developers List' Subject: RE: solution for missing refresh of ActionForm using checkboxes This doesn't work in a lot of situations though... Supposed you have a form that lives in the session (like a shopping cart). There may be several pages that submit using the same form (but different fields). Each submit will destroy your checkbox value even if you're on a page that doesn't have that checkbox. The solution below allows the value only to be cleared if a checkbox was actually on the page and not otherwise.... and it seems like a solution that is easier to program for. Instead of writing a complicated reset() method that has to detect which page you're coming from, the process would be transparent to the user. Chris -----Original Message----- From: Martin Cooper [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 22, 2002 2:56 PM To: 'Struts Developers List' Subject: RE: solution for missing refresh of ActionForm using checkboxes It's much simpler to have the reset() method in your form bean set checkbox values to false. Then, if the checkbox is checked, the value will be set to true when the form is submitted, whereas if the checkbox is not checked, then the value will be false because no matching parameter will be submitted. -- Martin Cooper > -----Original Message----- > From: van Nuffel, Marc [mailto:[EMAIL PROTECTED]] > Sent: Thursday, August 22, 2002 5:12 AM > To: '[EMAIL PROTECTED]' > Subject: solution for missing refresh of ActionForm using checkboxes > > > problem : > > a unchecked CheckBox doesent get unchecked after formSubmit.. > > problem description: > > if you uncheck a CheckBox that was checked, after submiting the form, > it remains checked, because the browser doesent post data > from unchecked > CheckBoxes. > so the ActionForm-setterMethod doesent get invoked. > > our solution: > > customTag: > > the only enhancement of the > org.apache.struts.taglib.html.CheckboxTag is > that we overwrite the doEndTag method and printing out an hiddenfield > after calling the super.doEndTag method. the hiddenfiled > consists of an > unique name, > the value is the propertyString of the CheckboxTag . > > > ActionForm: > > we made an abstract class ActionFormEnhanced that extends ActionForm. > we overwrite the method reset() and use reflection to find > the setterMethods > which we have to invoke, > to unset the checkboxes. the method names are found over a > generated hidden > field > produced from our costumTag "CheckBoxTagEnhanced" which > inherits from > org.apache.struts.taglib.html.CheckboxTag > > all this is fully transparent to the user. > > > > > > the ActionFormEnhanced.java: > > > > > package com.eenterprises.ejob.web.forms; > > import java.lang.reflect.Method; > > import javax.servlet.http.HttpServletRequest; > import org.apache.struts.action.ActionForm; > import org.apache.struts.action.ActionMapping; > > /** > * This ActionForm enhances Struts ActionForm > * @author Pierce Shah , Marc van Nuffel , Romeo Kienzler, > Reto Bachmann > */ > > public abstract class ActionFormEnhanced extends ActionForm { > > private Class actionFormClass = getClass(); > public static final String PARAMETER_TO_RESET = > "res_checkb_666"; > protected ActionFormEnhanced reference; > > public void reset(ActionMapping mapping, > HttpServletRequest request) > { > > String[] checkBoxAttributeName = > request.getParameterValues(PARAMETER_TO_RESET); > Class[] parameterTypes = new Class[1]; > parameterTypes[0] = boolean.class; > > if (checkBoxAttributeName != null) { > for (int i = 0; i < > checkBoxAttributeName.length; > i++) { > > StringBuffer buffer = new > StringBuffer("set"); > buffer.append(checkBoxAttributeName[i]); > > buffer.setCharAt(3,Character.toUpperCase(buffer.charAt(3))); > Method method; > > try { > method = > actionFormClass.getMethod(buffer.toString(), parameterTypes); > } catch (NoSuchMethodException nsmx) { > throw new > RuntimeException(nsmx.toString()); > } catch (SecurityException sx) { > throw new > RuntimeException(sx.toString()); > } > > Object[] arglist = new Object[1]; > arglist[0] = Boolean.FALSE; > try { > > method.invoke(reference, arglist); > } catch (Exception ex) { > throw new > RuntimeException(ex.toString()); > } > } > } > } > > public ActionFormEnhanced() { > this.reference = this; > System.out.println(reference.getClass()); > } > } > > > > > the CheckBoxTagEnhanced.java : > > > > > > package com.eenterprises.ejob.web.forms; > > import java.io.IOException; > > import javax.servlet.jsp.JspException; > import javax.servlet.jsp.JspWriter; > import org.apache.struts.taglib.html.CheckboxTag; > > public class CheckBoxTagEnhanced extends CheckboxTag { > > public int doEndTag() throws JspException { > int returnValue = super.doEndTag(); > JspWriter out = pageContext.getOut(); > try { > out.println( > "<input type=\"hidden\" > name=\""+ActionFormEnhanced.PARAMETER_TO_RESET+"\" value=\"" > + super.getProperty() > + "\">"); > } catch (IOException e) { > throw new JspException(e.getMessage()); > } > return returnValue; > } > > } > > the struts-htmlE.tld : > > <?xml version="1.0" encoding="UTF-8"?> > <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP > Tag Library > 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"> > <taglib> > <tlibversion>1.0</tlibversion> > <jspversion>1.1</jspversion> > <shortname>htmlE</shortname> > <uri>http://jakarta.apache.org/struts/tags-html-1.0</uri> > <tag> > <name>checkbox</name> > > <tagclass>com.eenterprises.ejob.web.forms.CheckBoxTagEnhanced< > /tagclass> > <attribute> > <name>accesskey</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>alt</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>altKey</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>disabled</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>indexed</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>name</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>onblur</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>onchange</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>onclick</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>ondblclick</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>onfocus</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>onkeydown</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>onkeypress</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>onkeyup</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>onmousedown</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>onmousemove</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>onmouseout</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>onmouseover</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>onmouseup</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>property</name> > <required>true</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>style</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>styleClass</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>styleId</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>tabindex</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>title</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>titleKey</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > <attribute> > <name>value</name> > <required>false</required> > <rtexprvalue>true</rtexprvalue> > </attribute> > </tag> > </taglib> > > > Mit freundlichen Grüssen > ( means kindly regards :-) ) > > eEnterprises Technology > > Romeo Kienzler > Reto Bachmann > Pierce Sha > Marc van Nuffel > > eProduction AG > Software Engineering > > Förrlibuckstrasse 110, 8005 Zürich - Switzerland > Telefon +41 1 448 2121/2137 | Fax +41 1 448 2122 > [EMAIL PROTECTED] | www.eproduction.ch > > > (c) by eEnterprises Holding AG, www.eenterprises.com > eProduction AG, a company of eEnterprises Holding AG > > ___________________________________________________________________ > eSitebuilder - Integration Platform for your eBusiness > CREATE, MANAGE AND RUN YOUR BUSINESS ANYWHERE > www.esitebuilder.net (c) 2000 by eProduction AG | All Rights Reserved > ___________________________________________________________________ > Licence Control System : Phantophone : Secure eMail : Phantomax > SECURE COMMUNICATION AND DATA MANAGEMENT IS OUR BUSINESS > www.esafemaker.com (c) 2002 by eSafemaker AG | All Rights Reserved > ___________________________________________________________________ > > The information in this internet email is confidential and is intended > solely for the addressee. Access, copying or re-use of > information in it by > anyone else is unauthorised. Any views or opinions presented > are solely > those of the author and do not necessarily represent those of > eEnterprises > Technology or any of its affiliates. If you are not the > intended recipient > please contact [EMAIL PROTECTED] > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>