View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/DbGotoButtonTag.java,v 1.24 2006/01/13 13:38:51 hkollmann Exp $
3    * $Revision: 1.24 $
4    * $Date: 2006/01/13 13:38:51 $
5    *
6    * DbForms - a Rapid Application Development Framework
7    * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8    *
9    * This library is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU Lesser General Public
11   * License as published by the Free Software Foundation; either
12   * version 2.1 of the License, or (at your option) any later version.
13   *
14   * This library is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   * Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public
20   * License along with this library; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22   */
23  
24  package org.dbforms.taglib;
25  
26  import org.dbforms.event.eventtype.EventType;
27  
28  import org.dbforms.util.Util;
29  
30  import javax.servlet.jsp.JspException;
31  
32  
33  
34  /***
35   * <p>
36   * this tag renders a Goto-button.
37   * </p>
38   *
39   * @author Joachim Peer
40   */
41  public class DbGotoButtonTag extends AbstractDbBaseButtonTag
42     implements javax.servlet.jsp.tagext.TryCatchFinally {
43     private String childField;
44     private String destPos;
45     private String destTable;
46     private String destination;
47     private String keyToDestPos;
48     private String keyToKeyToDestPos;
49     private String parentField;
50     private String singleRow = "false";
51  
52     /***
53      * DOCUMENT ME!
54      *
55      * @param string
56      */
57     public void setChildField(String string) {
58        childField = string;
59     }
60  
61  
62     /***
63      * DOCUMENT ME!
64      *
65      * @return
66      */
67     public String getChildField() {
68        return childField;
69     }
70  
71  
72     /***
73      * DOCUMENT ME!
74      *
75      * @param destPos DOCUMENT ME!
76      */
77     public void setDestPos(String destPos) {
78        this.destPos = destPos;
79     }
80  
81  
82     /***
83      * DOCUMENT ME!
84      *
85      * @return DOCUMENT ME!
86      */
87     public String getDestPos() {
88        return destPos;
89     }
90  
91  
92     /***
93      * DOCUMENT ME!
94      *
95      * @param destTable DOCUMENT ME!
96      */
97     public void setDestTable(String destTable) {
98        this.destTable = destTable;
99     }
100 
101 
102    /***
103     * DOCUMENT ME!
104     *
105     * @return DOCUMENT ME!
106     */
107    public String getDestTable() {
108       return destTable;
109    }
110 
111 
112    /***
113     * DOCUMENT ME!
114     *
115     * @param destination DOCUMENT ME!
116     */
117    public void setDestination(String destination) {
118       this.destination = destination;
119    }
120 
121 
122    /***
123     * DOCUMENT ME!
124     *
125     * @return DOCUMENT ME!
126     */
127    public String getDestination() {
128       return destination;
129    }
130 
131 
132    /***
133     * DOCUMENT ME!
134     *
135     * @param keyToDestPos DOCUMENT ME!
136     */
137    public void setKeyToDestPos(String keyToDestPos) {
138       this.keyToDestPos = keyToDestPos;
139    }
140 
141 
142    /***
143     * DOCUMENT ME!
144     *
145     * @return DOCUMENT ME!
146     */
147    public String getKeyToDestPos() {
148       return keyToDestPos;
149    }
150 
151 
152    /***
153     * DOCUMENT ME!
154     *
155     * @param keyToKeyToDestPos DOCUMENT ME!
156     */
157    public void setKeyToKeyToDestPos(String keyToKeyToDestPos) {
158       this.keyToKeyToDestPos = keyToKeyToDestPos;
159    }
160 
161 
162    /***
163     * DOCUMENT ME!
164     *
165     * @return DOCUMENT ME!
166     */
167    public String getKeyToKeyToDestPos() {
168       return keyToKeyToDestPos;
169    }
170 
171 
172    /***
173     * DOCUMENT ME!
174     *
175     * @param string
176     */
177    public void setParentField(String string) {
178       parentField = string;
179    }
180 
181 
182    /***
183     * DOCUMENT ME!
184     *
185     * @return
186     */
187    public String getParentField() {
188       return parentField;
189    }
190 
191 
192    /***
193     * DOCUMENT ME!
194     *
195     * @param string
196     */
197    public void setSingleRow(String string) {
198       singleRow = string;
199    }
200 
201 
202    /***
203     * DOCUMENT ME!
204     *
205     * @return the attribute
206     */
207    public String getSingleRow() {
208       return singleRow;
209    }
210 
211 
212    /***
213     * DOCUMENT ME!
214     */
215    public void doFinally() {
216       destination       = null;
217       destTable         = null;
218       destPos           = null;
219       keyToDestPos      = null;
220       keyToKeyToDestPos = null;
221       singleRow         = "false";
222       super.doFinally();
223    }
224 
225 
226    /***
227     * DOCUMENT ME!
228     *
229     * @return DOCUMENT ME!
230     *
231     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
232     * @throws JspException DOCUMENT ME!
233     */
234    public int doStartTag() throws javax.servlet.jsp.JspException {
235       super.doStartTag();
236 
237       try {
238          String tagName = EventType.EVENT_NAVIGATION_TRANSFER_GOTO
239                           + ((getTable() != null) ? getTable()
240                                                        .getId()
241                                                   : (-1)) + "_"
242                           + Integer.toString(getUniqueID());
243 
244          StringBuffer tagBuf = new StringBuffer();
245 
246          // mask destination as "fu" (FollowUp), so that we can use standard-event dispatching facilities
247          // from Controller and dont have to invent something new!
248          // #checkme: should we rename destination to followUp ?
249          if (destination != null) {
250             tagBuf.append(getDataTag(tagName, "fu", destination));
251          }
252 
253          if (destTable != null) {
254             tagBuf.append(getDataTag(tagName, "destTable", destTable));
255          }
256 
257          // 2004-01-13 HKK: Fix encoding
258          // 2004-05-20 HKK: destPos should be already encoded! So do not encode it twice!
259          // tagBuf.append(getDataTag(tagName, "destPos", Util.encode(destPos, pageContext.getRequest().getCharacterEncoding())));
260          tagBuf.append(getDataTag(tagName, "destPos", destPos));
261          tagBuf.append(getDataTag(tagName, "keyToDestPos",
262                                   Util.encode(keyToDestPos,
263                                               pageContext.getRequest().getCharacterEncoding())));
264          tagBuf.append(getDataTag(tagName, "keyToKeyToDestPos",
265                                   Util.encode(keyToKeyToDestPos,
266                                               pageContext.getRequest().getCharacterEncoding())));
267 
268          // 2004-01-13 HKK: Add support for childField/parentField
269          if ((getConfig()
270                        .getTableByName(destTable) != getTable())
271                    && (getParentForm()
272                                 .getTable() != null)) {
273             tagBuf.append(getDataTag(tagName, "srcTable",
274                                      getParentForm().getTable().getName()));
275             tagBuf.append(getDataTag(tagName, "childField",
276                                      Util.encode(childField,
277                                                  pageContext.getRequest().getCharacterEncoding())));
278             tagBuf.append(getDataTag(tagName, "parentField",
279                                      Util.encode(parentField,
280                                                  pageContext.getRequest().getCharacterEncoding())));
281          }
282 
283          tagBuf.append(getDataTag(tagName, "singleRow", getSingleRow()));
284 
285          tagBuf.append(getButtonBegin());
286          tagBuf.append(" name=\"");
287          tagBuf.append(tagName);
288          tagBuf.append(getButtonEnd());
289 
290          pageContext.getOut()
291                     .write(tagBuf.toString());
292       } catch (java.io.IOException ioe) {
293          throw new JspException("IO Error: " + ioe.getMessage());
294       }
295 
296       if (getChoosenFlavor() == FLAVOR_MODERN) {
297          return EVAL_BODY_BUFFERED;
298       } else {
299          return SKIP_BODY;
300       }
301    }
302 }