Here's how I do it in Struts 1.1. I'm not sure how 1.1 is different from 1.01 in the validation area so your mileage may very.
First I have a base class for all my ActionForm's called ExtendedActionBase. Among other things, this class defines some standard button name for "next", "back", "cancel", and "OK" verbs. The class will only perform validation if a "next" or "OK" button was used to submit the form. There's also some extra junk in the class that has to do with accepting either simple <input type="submit> buttons as well is <input type="image"> buttons. The only other thing you need to do is on "back" and "cancel" buttons make sure they are <html:cancel> buttons. This insures that the JavaScript validator will not validate the form. I'll include ExtendedActionBase.java below. Hope this helps, Kurt --------------- /* * ExtendedActionForm.java * * Created on July 11, 2003, 10:39 AM */ package com.kaptec.dateweb.web.struts.actionforms; import org.apache.struts.action.ActionErrors; /** The purpose of this class is to provide a base class for ActionForms that want * to prepopulate their values when they are created. This class takes advantage * of the fact that STruts calls Reset() when an ActionForm is created and in * addition to calling Reset() before populating ActionForm properties from * submitted HTML form data. * * Descenden ts of this class need to implement two methods. the onInitialize() * method is called when the ActionForm is created and the onProcessForm() method * is called before HTML form values are passed into ActionForm properties. * @author Kurt Post */ public class ExtendedActionForm extends org.apache.struts.validator.ValidatorActionForm { /** indicates if the ActionForm has been initialed yet */ private boolean isInitialized = false; /** This attribute will be set to a non-null value if the user pressed the "Submit" button on * the form. */ private String btnProcessForm; /** This attribute will be set to a non-null value if the user pressed the "Cancel" button on * the form. */ private String btnCancelForm; /** This attribute will be set to a non-null value if the user pressed the "Next" button on * the form. */ private String btnNext; /** This attribute will be set to a non-null value if the user pressed the "Back" button on * the form. */ private String btnBack; /** The X and Y attributes of this object will be set if the user clicks on a * "Submit" image button */ private ImageButtonCoordinates imgProcessForm = new ImageButtonCoordinates(); /** The X and Y attributes of this object will be set if the user clicks on a * "Submit" image button */ private ImageButtonCoordinates imgCancelForm = new ImageButtonCoordinates(); /** The X and Y attributes of this object will be set if the user clicks on a * "Next" image button */ private ImageButtonCoordinates imgNext = new ImageButtonCoordinates(); /** The X and Y attributes of this object will be set if the user clicks on a * "Back" image button */ private ImageButtonCoordinates imgBack = new ImageButtonCoordinates(); /** Simply catch the Struts framework calles to reset() and forward it to * onInitialize() or onProcessForm(). * @param mapping Action mapping that caused our ActionForm to be * created or populated * @param request HTTP request which caused this ActionForm to be * created or populated. */ public void reset(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { super.reset(mapping, request); if (isInitialized == false) { onInitialize(mapping, request); isInitialized = true; } else { onProcessForm(mapping, request); } } /** Override this method to handle ActionForm initialization * WARNING: The method in this base class should be called by descendent * classesthat override it since it handles resetting form * submit/cancel related properties. * @param mapping Action mapping that caused our ActionForm to be * created * @param request HTTP request which caused this ActionForm to be * created */ public void onInitialize(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { } /** Override this method to handle any processing needed before HTML form data is * passed to the properties of this ActionForm * WARNING: The method in this base class should be called by descendent * classesthat override it since it handles resetting form * submit/cancel related properties. * @param mapping Action mapping that caused our ActionForm to be * populated * @param request HTTP request which caused this ActionForm to be * populated. */ public void onProcessForm(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { btnProcessForm = null; btnCancelForm = null; imgProcessForm = new ImageButtonCoordinates(); imgCancelForm = new ImageButtonCoordinates(); btnNext = null; btnBack = null; imgNext = new ImageButtonCoordinates(); imgBack = new ImageButtonCoordinates(); } /** This is a convenience method that Action objects can use to determine if the * user hit a cancel button on the form being processed. This method checks for * both the standard buttons and image buttons. * @return True if the user hit a standard cancel button or an image cancel button */ public boolean isActionCancel() { if (btnCancelForm != null) return true; if (imgCancelForm.getX() != null) return true; return false; } /** This is a convenience method that Action objects can use to determine if the * user hit a submit(process) button on the form being processed. This method checks for * both the standard buttons and image buttons. * @return True if the user hit a standard submit button or an image submit button */ public boolean isActionProcess() { if (btnProcessForm != null) return true; if (imgProcessForm.getX() != null) return true; return false; } /** This is a convenience method that Action objects can use to determine if the * user hit a 'Back' button on the form being processed. This method checks for * both the standard buttons and image buttons. * @return True if the user hit a standard 'Back' button or an image 'Back' button */ public boolean isActionBack() { if (btnBack != null) return true; if (imgBack.getX() != null) return true; return false; } /** This is a convenience method that Action objects can use to determine if the * user hit a 'Next' button on the form being processed. This method checks for * both the standard buttons and image buttons. * @return True if the user hit a standard 'Next' button or an image 'Next' button */ public boolean isActionNext() { if (btnNext != null) return true; if (imgNext.getX() != null) return true; return false; } /** This method overrides the validate() method of our base class. * Validation is only performed if isActionProcess() or * isActionNext() return true (i.e. the user hit 'Submit' or 'Next' button * to submit the form) * @return List of ActionErrors or null if no errors */ public org.apache.struts.action.ActionErrors validate(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request) { ActionErrors retValue = null; // Don't call validation if the user wants to cancel the operation if ( isActionProcess() || isActionNext() ) retValue = super.validate(mapping, request); if ( (retValue != null) && (retValue.isEmpty() == false) ) { System.err.println("ExtendedActionForm:validate: Found Errors"); } return retValue; } /** Getter for property btnProcessForm. * @return Value of property btnProcessForm. * */ public java.lang.String getBtnProcessForm() { return btnProcessForm; } /** Setter for property btnProcessForm. * @param btnProcessForm New value of property btnProcessForm. * */ public void setBtnProcessForm(java.lang.String btnProcessForm) { this.btnProcessForm = btnProcessForm; } /** Getter for property btnCancelForm. * @return Value of property btnCancelForm. * */ public java.lang.String getBtnCancelForm() { return btnCancelForm; } /** Setter for property btnCancelForm. * @param btnCancelForm New value of property btnCancelForm. * */ public void setBtnCancelForm(java.lang.String btnCancelForm) { this.btnCancelForm = btnCancelForm; } /** Getter for property imgProcessForm. * @return Value of property imgProcessForm. * */ public com.kaptec.dateweb.web.struts.actionforms.ImageButtonCoordinates getImgProcessForm() { return imgProcessForm; } /** Setter for property imgProcessForm. * @param imgProcessForm New value of property imgProcessForm. * */ public void setImgProcessForm(com.kaptec.dateweb.web.struts.actionforms.ImageButtonCoord inates imgProcessForm) { this.imgProcessForm = imgProcessForm; } /** Getter for property imgCancelForm. * @return Value of property imgCancelForm. * */ public com.kaptec.dateweb.web.struts.actionforms.ImageButtonCoordinates getImgCancelForm() { return imgCancelForm; } /** Setter for property imgCancelForm. * @param imgCancelForm New value of property imgCancelForm. * */ public void setImgCancelForm(com.kaptec.dateweb.web.struts.actionforms.ImageButtonCoordi nates imgCancelForm) { this.imgCancelForm = imgCancelForm; } /** Getter for property btnNext. * @return Value of property btnNext. * */ public java.lang.String getBtnNext() { return btnNext; } /** Setter for property btnNext. * @param btnNext New value of property btnNext. * */ public void setBtnNext(java.lang.String btnNext) { this.btnNext = btnNext; } /** Getter for property btnBack. * @return Value of property btnBack. * */ public java.lang.String getBtnBack() { return btnBack; } /** Setter for property btnBack. * @param btnBack New value of property btnBack. * */ public void setBtnBack(java.lang.String btnBack) { this.btnBack = btnBack; } /** Getter for property imgNext. * @return Value of property imgNext. * */ public com.kaptec.dateweb.web.struts.actionforms.ImageButtonCoordinates getImgNext() { return imgNext; } /** Setter for property imgNext. * @param imgNext New value of property imgNext. * */ public void setImgNext(com.kaptec.dateweb.web.struts.actionforms.ImageButtonCoordinates imgNext) { this.imgNext = imgNext; } /** Getter for property imgBack. * @return Value of property imgBack. * */ public com.kaptec.dateweb.web.struts.actionforms.ImageButtonCoordinates getImgBack() { return imgBack; } /** Setter for property imgBack. * @param imgBack New value of property imgBack. * */ public void setImgBack(com.kaptec.dateweb.web.struts.actionforms.ImageButtonCoordinates imgBack) { this.imgBack = imgBack; } } -----Original Message----- From: Andre Michel [mailto:[EMAIL PROTECTED] Sent: Friday, September 05, 2003 8:36 AM To: [EMAIL PROTECTED] Subject: Avoid Validate After Submit Hello ... I'd like to have two submit buttons on a page. Pressing no. 1 should run through validation, pressing no. 2 should avoid this. How am I able to this in a good way? I'm using Struts 1.01 thus validate method is in the form bean. Any hints would be welcomed, Andre Michel -- COMPUTERBILD 15/03: Premium-e-mail-Dienste im Test -------------------------------------------------- 1. GMX TopMail - Platz 1 und Testsieger! 2. GMX ProMail - Platz 2 und Preis-Qualitätssieger! 3. Arcor - 4. web.de - 5. T-Online - 6. freenet.de - 7. daybyday - 8. e-Post --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]