Source code: com/RuntimeCollective/webapps/form/Select2Form.java
1 /* $Header: /home/CVS/rjp/src/com/RuntimeCollective/webapps/form/Select2Form.java,v 1.4 2003/09/30 15:13:14 joe Exp $
2 * $Revision: 1.4 $
3 * $Date: 2003/09/30 15:13:14 $
4 *
5 * ====================================================================
6 *
7 * Josephine : http://www.runtime-collective.com/josephine/index.html
8 *
9 * Copyright (C) 2003 Runtime Collective
10 *
11 * This product includes software developed by the
12 * Apache Software Foundation (http://www.apache.org/).
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30 package com.RuntimeCollective.webapps.form;
31
32 import com.RuntimeCollective.webapps.form.BeanForm;
33 import com.RuntimeCollective.webapps.bean.EntityBean;
34 import javax.servlet.http.HttpServletRequest;
35 import org.apache.struts.action.ActionError;
36 import org.apache.struts.action.ActionErrors;
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionMapping;
39
40 /**
41 * A 2D version of SelectForm -- ie allows the user to select two independent variables.
42 *
43 * @author Joe Faith
44 * @version $Id: Select2Form.java,v 1.4 2003/09/30 15:13:14 joe Exp $
45 */
46 public class Select2Form extends ActionForm {
47
48 // == Properties ===================================================
49
50 /** The id of the first bean. Defaults to -1. */
51 protected int id1 = -1;
52 /** Get the id of the first bean. */
53 public int getId1() { return this.id1; }
54 /** Set the id of the first bean. */
55 public void setId1(int id1) { this.id1 = id1; }
56
57 /** The id of the second bean. Defaults to -1. */
58 protected int id2 = -1;
59 /** Get the id of the second bean. */
60 public int getId2() { return this.id2; }
61 /** Set the id of the second bean. */
62 public void setId2(int id2) { this.id2 = id2; }
63
64 /** Whether the form is being used to "add" a new bean or "remove" an existing one (or some other action). Defaults to "add". */
65 protected String formAction = "add";
66 /** Get whether the form is being used to "add" a new bean or "remove" an existing one (or some other action). */
67 public String getFormAction() { return this.formAction; }
68 /** Set whether the form is being used to "add" a new bean or "remove" an existing one (or some other action). */
69 public void setFormAction(String formAction) { this.formAction = formAction; }
70
71 // == Other Methods ===================================================
72
73 /** Validate bean selected. This returns the following error codes:
74 *<ul>
75 *<li><code>error.select.bean</code> - if either bean was unselected.
76 *</ul>
77 */
78 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
79
80 ActionErrors errors = new ActionErrors();
81 if ( id1==-1 || id2==-1 ) errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.beanSelect.id"));
82 return errors;
83
84 }
85
86 /** Reset all properties to default values.
87 * @param mapping The mapping used to select this instance
88 * @param request The servlet request we are processing
89 */
90 public void reset(ActionMapping mapping, HttpServletRequest request) {
91 setId1(-1);
92 setId2(-1);
93 setFormAction("add");
94 }
95 }