On Fri, Mar 08, 2002 at 12:55:01AM -0800, Struts Newsgroup wrote:
> What we wanted was exactly the same as you: insert, update, delete,
> different actions with different validations. If I want different
> validations I want different formbeans (formbean for insert, one for
> update and one for delete). The problem is that the html form
> section (<html:form action = "youraction">)can only contain one
> action and so you can only go to one formbean. If this form has
> multiple buttons then what do you do?

We've encountered the same problem, and here's how we chose to solve
it (using only one formbean):

-For each submit button, assign a different property name:
  <html:submit property="insertSubmit">
    <bean:message key="button.newRecord"/>
  </html:submit>

  <html:submit property="updateSubmit">
    <bean:message key="button.updateRecord"/>
  </html:submit>

  <html:submit property="deleteSubmit">
    <bean:message key="button.deleteRecord"/>
  </html:submit>

-Then in your validate(mapping,request) method of the form bean:
  public ActionErrors validate(ActionMapping mapping, HttpServletRequest req){
    boolean doInsert=(req.getParameter("insertSubmit") != null);
    boolean doUpdate=(req.getParameter("updateSubmit") != null);
    boolean doDelete=(req.getParameter("deleteSubmit") != null);

    // Check for always-required fields here

    if(doInsert || doUpdate) {
      //Check for some special-case required fields here
    }
    if(doDelete) {
      //Check for different set of required fields here
    }
  }

-This method has worked really well for us: it's easy to implement,
 and easy to understand for new people who join the project.

> The area we haven't checked is the area of using hyperlinks instead of
> submit buttons, so the solution might be there.

This could work if you required your users to have a
javascript-enabled browser, but the method I'm using works with all
forms-enabled browsers... which is most (but not all) of them. :)

-- 
Jonathan Fuerth - SQL Power Group Inc.
(416)218-5551 (Toronto); 1-866-SQL-POWR (Toll-Free)
Unleash the Power of your Corporate Data - www.sqlpower.ca

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to