KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > dialoglayout > www > SingleLineEditControlTag


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: SingleLineEditControlTag.java,v 1.14 2007/01/07 06:14:28 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21  
22 package org.opensubsystems.patterns.dialoglayout.www;
23
24 import javax.servlet.jsp.JspException JavaDoc;
25
26 import org.opensubsystems.core.www.BlockElementTag;
27 import org.opensubsystems.core.www.TagUtils;
28 import org.opensubsystems.patterns.tabbeddialog.www.TabbedDialogTag;
29
30 /**
31  * Custom tag to generate all HTML code necessary to display single line edit
32  * control displayed in the dialog row.
33  *
34  * @version $Id: SingleLineEditControlTag.java,v 1.14 2007/01/07 06:14:28 bastafidli Exp $
35  * @author Miro Halas
36  * @code.reviewer Miro Halas
37  * @code.reviewed 1.7 2006/02/18 05:29:32 bastafidli
38  */

39 public class SingleLineEditControlTag extends BlockElementTag
40 {
41    // Attributes ///////////////////////////////////////////////////////////////
42

43    /**
44     * Generated serial version id for this class.
45     */

46    private static final long serialVersionUID = -662954227640347489L;
47
48    /**
49     * Name of the input tag used to identify submitted data
50     */

51    protected String JavaDoc m_strName;
52    
53    /**
54     * Size of the input tag used to limit viewable area.
55     */

56    protected String JavaDoc m_strSize;
57
58    /**
59     * Size of the input tag used to limit amount of entered data.
60     */

61    protected String JavaDoc m_strMaxlength;
62
63    /**
64     * Is this control a password control or just a regular edit control.
65     */

66    protected String JavaDoc m_strPassword;
67
68    /**
69     * Class for the input control representing this single line edit.
70     */

71    protected String JavaDoc m_strInputcssclass;
72
73    /**
74     * Does this control have focus when it is displayed on the page or not.
75     * Only one control on a page or tab can be marked as focus at a time.
76     * If multiple controls are marked this way, then the first one on the page
77     * or tab will get the focus.
78     */

79    protected String JavaDoc m_strFocus;
80
81    /**
82     * Flag specifying if this input control is disabled therefore preventing
83     * user to enter or modify value it contain.
84     */

85    protected String JavaDoc m_strDisabled;
86
87    /**
88     * Initial value to display in the edit control.
89     */

90    protected String JavaDoc m_strValue;
91
92    /**
93     * JavaScript code to execute when the content of the edit field changes.
94     */

95    protected String JavaDoc m_strOnChange;
96
97    /**
98     * JavaScript code to execute when the key was pressed while entering data
99     * into the edit field.
100     */

101    protected String JavaDoc m_strOnKeyPress;
102
103    /**
104     * JavaScript code to execute on key up event while entering data into the
105     * edit field.
106     */

107    protected String JavaDoc m_strOnKeyUp;
108
109    // Constructors /////////////////////////////////////////////////////////////
110

111    /**
112     * Constructor for custom tag.
113     */

114    public SingleLineEditControlTag()
115    {
116       super("clsStrechControl", BlockElementTag.DIV_BLOCK_ELEMENT);
117       
118       m_strName = null;
119       m_strSize = null;
120       m_strMaxlength = null;
121       m_strPassword = Boolean.FALSE.toString();
122       m_strInputcssclass = "clsStretchSingleLineEdit";
123       m_strDisabled = Boolean.FALSE.toString();
124       m_strValue = null;
125       m_strOnChange = null;
126       m_strOnKeyPress = null;
127       m_strOnKeyUp = null;
128    }
129    
130    // Business logic ///////////////////////////////////////////////////////////
131

132    /**
133     * {@inheritDoc}
134     */

135    public int doStartTag(
136    ) throws JspException JavaDoc
137    {
138       StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
139
140       /*
141       <div id="newpassword2control" class="clsStrechControl">
142          <input id="newpassword2" class="clsStretchSingleLineEdit"
143                 type="password" name="LOGIN_NEW_PASSWORD_2" size="25" maxlength="30"
144                 onKeyPress="checkIt(event, false)">
145       </div>
146       */

147
148       // generate content of start tag
149
doStartTag(sbHtml, "control", "");
150       
151       TagUtils.write(pageContext, sbHtml.toString());
152       
153       if (isFocusedControl())
154       {
155          // Cache the content since it should be inserted at a row
156
// boundary and not at a field boundary
157
sbHtml.delete(0, sbHtml.length());
158          sbHtml.append(getCurrentId());
159          sbHtml.append(m_strId);
160    
161          cache(TabbedDialogTag.FOCUSED_CONTROL_ID, sbHtml.toString());
162       }
163       
164       return (EVAL_BODY_INCLUDE);
165    }
166
167    /**
168     * {@inheritDoc}
169     */

170    public int doEndTag(
171    ) throws JspException JavaDoc
172    {
173       // Finish the label
174
StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
175       // generate content
176
doEndTag(sbHtml);
177
178       TagUtils.write(pageContext, sbHtml.toString());
179       
180       return (EVAL_PAGE);
181    }
182
183    /**
184     * Generate content of the buffer within the start tag
185     *
186     * @param sbHtml - string buffer the content will be generated to
187     * @param strPostfix1 - postfix added to the div id
188     * @param strPostfix2 - postfix added to the edit input control id
189     */

190    protected void doStartTag(
191       StringBuffer JavaDoc sbHtml,
192       String JavaDoc strPostfix1,
193       String JavaDoc strPostfix2
194    )
195    {
196       // Generate the start of the tabbed dialog
197
sbHtml.append("<");
198       sbHtml.append(m_strType);
199       sbHtml.append(" id=\"");
200       sbHtml.append(getCurrentId());
201       sbHtml.append(m_strId);
202       sbHtml.append(strPostfix1);
203       sbHtml.append("\"");
204       if ((m_strCssclass != null) && (m_strCssclass.length() > 0))
205       {
206          sbHtml.append(" class=\"");
207          sbHtml.append(m_strCssclass);
208          sbHtml.append("\"");
209       }
210       sbHtml.append(">\n");
211       sbHtml.append("<input id=\"");
212       sbHtml.append(getCurrentId());
213       sbHtml.append(m_strId);
214       sbHtml.append(strPostfix2);
215       sbHtml.append("\"");
216       if ((m_strInputcssclass != null) && (m_strInputcssclass.length() > 0))
217       {
218          sbHtml.append(" class=\"");
219          sbHtml.append(m_strInputcssclass);
220          sbHtml.append("\"");
221       }
222       sbHtml.append(" type=\"");
223       if (isPasswordControl())
224       {
225          sbHtml.append("password");
226       }
227       else
228       {
229          sbHtml.append("text");
230       }
231       sbHtml.append("\"");
232       if ((m_strName != null) && (m_strName.length() > 0))
233       {
234          sbHtml.append(" name=\"");
235          sbHtml.append(m_strName);
236          sbHtml.append("\"");
237       }
238       if ((m_strSize != null) && (m_strSize.length() > 0))
239       {
240          sbHtml.append(" size=\"");
241          sbHtml.append(m_strSize);
242          sbHtml.append("\"");
243       }
244       if ((m_strMaxlength != null) && (m_strMaxlength.length() > 0))
245       {
246          sbHtml.append(" maxlength=\"");
247          sbHtml.append(m_strMaxlength);
248          sbHtml.append("\"");
249       }
250       if (isDisabledControl())
251       {
252          sbHtml.append(" disabled=\"disabled\"");
253       }
254       if ((m_strValue != null) && (m_strValue.length() > 0))
255       {
256          sbHtml.append(" value=\"");
257          sbHtml.append(m_strValue);
258          sbHtml.append("\"");
259       }
260       if ((m_strOnChange != null) && (m_strOnChange.length() > 0))
261       {
262          sbHtml.append(" onChange=\"");
263          sbHtml.append(m_strOnChange);
264          sbHtml.append("\"");
265       }
266       if ((m_strOnKeyPress != null) && (m_strOnKeyPress.length() > 0))
267       {
268          sbHtml.append(" onKeyPress=\"");
269          sbHtml.append(m_strOnKeyPress);
270          sbHtml.append("\"");
271       }
272       if ((m_strOnKeyUp != null) && (m_strOnKeyUp.length() > 0))
273       {
274          sbHtml.append(" onKeyUp=\"");
275          sbHtml.append(m_strOnKeyUp);
276          sbHtml.append("\"");
277       }
278       sbHtml.append(">");
279    }
280
281    /**
282     * Generate content of the buffer within the end tag
283     *
284     * @param sbHtml - generated string buffer
285     */

286    protected void doEndTag(
287       StringBuffer JavaDoc sbHtml
288    )
289    {
290       // Finish the label
291
sbHtml.append("</");
292       sbHtml.append(m_strType);
293       sbHtml.append(">");
294    }
295
296    /**
297     * @return String - Class for the input control representing this single line edit
298     */

299    public String JavaDoc getInputcssclass()
300    {
301       return m_strInputcssclass;
302    }
303    
304    /**
305     * @return String - Size of the input tag used to limit amount of entered data.
306     */

307    public String JavaDoc getMaxlength()
308    {
309       return m_strMaxlength;
310    }
311    
312    /**
313     * @return String - Name of the input tag used to identify submitted data
314     */

315    public String JavaDoc getName()
316    {
317       return m_strName;
318    }
319    
320    /**
321     * @return String - Is this control a password control or just a regular edit
322     * control.
323     */

324    public String JavaDoc getPassword()
325    {
326       return m_strPassword;
327    }
328    
329    /**
330     * @return String - Size of the input tag used to limit viewable area.
331     */

332    public String JavaDoc getSize()
333    {
334       return m_strSize;
335    }
336    
337    /**
338     * @return String - Does this control have focus when it si displayed on the
339     * page or not.
340     */

341    public String JavaDoc getFocus()
342    {
343       return m_strFocus;
344    }
345    
346    /**
347     * @param strInputcssclass - Class for the input control representing this
348     * single line edit
349     */

350    public void setInputcssclass(
351       String JavaDoc strInputcssclass
352    )
353    {
354       m_strInputcssclass = strInputcssclass;
355    }
356    
357    /**
358     * @param strMaxLength - size of the input tag used to limit amount of entered
359     * data.
360     */

361    public void setMaxlength(
362       String JavaDoc strMaxLength
363    )
364    {
365       m_strMaxlength = strMaxLength;
366    }
367    
368    /**
369     * @param iMaxLength - size of the input tag used to limit amount of entered
370     * data.
371     */

372    public void setMaxlength(
373       int iMaxLength
374    )
375    {
376       m_strMaxlength = Integer.toString(iMaxLength);
377    }
378    
379    /**
380     * @param strName - Name of the input tag used to identify submitted data
381     */

382    public void setName(
383       String JavaDoc strName
384    )
385    {
386       m_strName = strName;
387    }
388    
389    /**
390     * @param strPassword - If this control a password control this attribute should
391     * say true or 1.
392     */

393    public void setPassword(
394       String JavaDoc strPassword
395    )
396    {
397       m_strPassword = strPassword;
398    }
399    
400    /**
401     * @param bPassword - is this control a password control or just a regular
402     * edit control.
403     */

404    public void setPassword(
405       boolean bPassword
406    )
407    {
408       m_strPassword = Boolean.toString(bPassword);
409    }
410    
411    /**
412     * @param strFocus - If this control have focus when it is displayed on the
413     * page say true or 1.
414     */

415    public void setFocus(
416       String JavaDoc strFocus
417    )
418    {
419       m_strFocus = strFocus;
420    }
421    
422    /**
423     * @param bFocus - Does this control have focus when it si displayed on the
424     * page or tab.
425     */

426    public void setFocus(
427       boolean bFocus
428    )
429    {
430       m_strFocus = Boolean.toString(bFocus);
431    }
432
433    /**
434     * @param strSize - Size of the input tag used to limit viewable area.
435     */

436    public void setSize(
437       String JavaDoc strSize
438    )
439    {
440       m_strSize = strSize;
441    }
442
443    /**
444     * @return boolean - true if this control represents a password control
445     */

446    public boolean isPasswordControl(
447    )
448    {
449       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strPassword))
450              || ("1".equals(m_strPassword)));
451    }
452
453    /**
454     * @return boolean - true if this control has focus when it is displayed
455     * on a page or tab
456     */

457    public boolean isFocusedControl(
458    )
459    {
460       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strFocus))
461              || ("1".equals(m_strFocus)));
462    }
463
464    /**
465     * @return String - If this control should be disabled then this attribute
466     * should say true or 1.
467     */

468    public String JavaDoc getDisabled(
469    )
470    {
471       return m_strDisabled;
472    }
473
474    /**
475     * @param strDisabled - If this control should be disabled then this attribute
476     * should say true or 1.
477     */

478    public void setDisabled(
479       String JavaDoc strDisabled
480    )
481    {
482       m_strDisabled = strDisabled;
483    }
484    
485    /**
486     * @param bDisabled - If this control should be disabled then this attribute
487     * should say true or 1.
488     */

489    public void setDisabled(
490       boolean bDisabled
491    )
492    {
493       m_strDisabled = Boolean.toString(bDisabled);
494    }
495
496    /**
497     * @return boolean - true if this control should be disabled
498     */

499    public boolean isDisabledControl(
500    )
501    {
502       return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strDisabled))
503              || ("1".equals(m_strDisabled)));
504    }
505
506    /**
507     * @return String - Value of the input tag used to display in the edit box
508     */

509    public String JavaDoc getValue()
510    {
511       return m_strValue;
512    }
513    
514    /**
515     * @param strValue - Value of the input tag used to display in the edit box
516     */

517    public void setValue(
518       String JavaDoc strValue
519    )
520    {
521       m_strValue = strValue;
522    }
523
524    /**
525     * @return String - JavaScript code to execute when the content of edit filed changes.
526     */

527    public String JavaDoc getOnchange(
528    )
529    {
530       return m_strOnChange;
531    }
532
533    /**
534     * @param strOnchange - JavaScript code to execute when the content of edit filed changes.
535     */

536    public void setOnchange(
537       String JavaDoc strOnchange
538    )
539    {
540       m_strOnChange = strOnchange;
541    }
542
543    /**
544     * @return String - JavaScript code to execute when the key was pressed.
545     */

546    public String JavaDoc getOnkeypress(
547    )
548    {
549       return m_strOnKeyPress;
550    }
551
552    /**
553     * @param strOnKeyPress - JavaScript code to execute when the key was pressed.
554     */

555    public void setOnkeypress(
556       String JavaDoc strOnKeyPress
557    )
558    {
559       m_strOnKeyPress = strOnKeyPress;
560    }
561
562    /**
563     * @return String - JavaScript code to execute on key up event.
564     */

565    public String JavaDoc getOnkeyup(
566    )
567    {
568       return m_strOnKeyUp;
569    }
570
571    /**
572     * @param strOnKeyUp - JavaScript code to execute on key up event.
573     */

574    public void setOnkeyup(
575       String JavaDoc strOnKeyUp
576    )
577    {
578       m_strOnKeyUp = strOnKeyUp;
579    }
580 }
581
Popular Tags