KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > aikp > AikpForm


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.aikp;
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24
25 import org.apache.struts.action.ActionErrors;
26 import org.apache.struts.action.ActionMapping;
27
28 import org.apache.struts.validator.DynaValidatorForm;
29 import org.apache.commons.lang.StringUtils;
30
31 public class AikpForm extends DynaValidatorForm {
32
33   // constructors /////////////////////////////////////////////////////////////
34

35   // constants ////////////////////////////////////////////////////////////////
36

37   // classes //////////////////////////////////////////////////////////////////
38

39   // methods //////////////////////////////////////////////////////////////////
40

41   /**
42    * Calls {@link #doValidate doValidate()} for <tt>save</tt> and
43    * <tt>saveNew</tt> action if the delete or cancel button was not clicked.
44    * <tt>DynaValidatorForm.validate()</tt> is called and the resulting errors
45    * are passed to {@link #doValidate doValidate()}.
46    */

47   public ActionErrors validate(
48     ActionMapping mapping,
49     HttpServletRequest JavaDoc request ) {
50
51     if ( ( "save".equals( get( "action" ) ) ||
52            "saveNew".equals( get( "action" ) ) ) &&
53          ( StringUtils.isBlank( ( String JavaDoc )get( "delete" ) ) &&
54            StringUtils.isBlank( ( String JavaDoc )get( "cancel" ) ) ) )
55       return doValidate( mapping, request, super.validate( mapping, request ) );
56
57     return new ActionErrors();
58   }
59
60   /**
61    * Returns <tt>errors</tt>; subclasses should override this method and
62    * perform their own validation. <tt>errors</tt> contains any errors
63    * resulting from the default validation.
64    */

65   public ActionErrors doValidate(
66     ActionMapping mapping,
67     HttpServletRequest JavaDoc request,
68     ActionErrors errors ) {
69
70     return errors;
71   }
72
73   // properties ///////////////////////////////////////////////////////////////
74

75   // attributes ///////////////////////////////////////////////////////////////
76
}
77
Popular Tags