View Javadoc

1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.control.form;
16  
17  import org.figure8.join.control.JoinForm;
18  import org.figure8.join.control.action.TargetActions;
19  
20  import org.apache.struts.action.ActionMapping;
21  
22  import javax.servlet.http.HttpServletRequest;
23  /**
24   * Form object used for manipulating Targets into Join application.
25   * @author <a href="mailto:jerome.evrard@gmail.com">Jerome Evrard</a>
26   * @version $Revision: 1.1 $
27   *
28   * @struts.form name="targetForm"
29   */
30  public class TargetForm extends JoinForm{
31  
32     // Attributes ---------------------------------------------------------------
33  
34     /** The name of current target */
35     private String name;
36     /** The description of current target */
37     private String description;
38  
39  
40     // Constructors -------------------------------------------------------------
41  
42     /** Creates a new instance of TargetForm */
43     public TargetForm(){
44     }
45  
46  
47     // Public -------------------------------------------------------------------
48  
49     /** @return name of current target */
50     public String getName(){
51        return name;
52     }
53     /** @param name Name of current target */
54     public void setName(String name){
55        this.name = name;
56     }
57     /** @return Description of current target */
58     public String getDescription(){
59        return description;
60     }
61     /** @param description Description of current target */
62     public void setDescription(String description){
63        this.description = description;
64     }
65  
66  
67     // Implementation of JoinForm -----------------------------------------------
68  
69     /**
70      * Validation of the form attributes.
71      * @param operation String representing the operation to invoke on Action
72      * @param mapping Mapping between forwards name and path for this action
73      * @param request The servlet container request wrapper
74      */
75     public void doValidate(String operation, ActionMapping mapping, HttpServletRequest request){
76  
77        if (TargetActions.LOAD_OP.equals(operation)){
78           // Check and see if name is missing.
79           if (name == null || name.length() == 0)
80              addActionError("errors.required", getGuiMessageResources().getMessage("label.target.name"));
81        }
82        else if (TargetActions.SAVE_OP.equals(operation)){
83           // Check and see if name is missing.
84           if (name == null || name.length() == 0)
85              addActionError("errors.required", getGuiMessageResources().getMessage("label.target.name"));
86           // Check and see if description is missing.
87           if (description == null || description.length() == 0)
88              addActionError("errors.required", getGuiMessageResources().getMessage("label.target.description"));
89        }
90     }
91  
92  
93     // Override of ActionForm ---------------------------------------------------
94  
95     /**
96      * Reset form attributes.
97      * @param mapping Mapping between forwards name and path for this action
98      * @param request The servlet container request wrapper
99      */
100    public void reset(ActionMapping mapping, HttpServletRequest request){
101       super.reset(mapping, request);
102       name = null;
103       description = null;
104    }
105 }