KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > web > taglib > CreditCardTag


1 package xpetstore.web.taglib;
2
3 import java.util.Iterator JavaDoc;
4
5 import javax.servlet.jsp.JspException JavaDoc;
6 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
7
8 import xpetstore.util.CreditCardNames;
9
10
11 /**
12  * This is an example of JSP taglib.
13  * This taglib show the list of all the credit card to use for payments
14  *
15  * @author <a HREF="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
16  *
17  * @jsp.tag
18  * name="creditcard"
19  * body-content="empty"
20  * display-name="xPetStore CreditCard Tag"
21  */

22 public class CreditCardTag
23     extends TagSupport JavaDoc
24 {
25     //~ Instance fields --------------------------------------------------------
26

27     private String JavaDoc _name;
28     private String JavaDoc _css;
29     private String JavaDoc _value;
30
31     //~ Methods ----------------------------------------------------------------
32

33     /**
34      * @see javax.servlet.jsp.tagext.Tag#doEndTag()
35      */

36     public int doEndTag( )
37         throws JspException JavaDoc
38     {
39         try
40         {
41             StringBuffer JavaDoc buff = new StringBuffer JavaDoc( );
42
43             /* <select> */
44             buff.append( "<select name='" ).append( _name ).append( "'" );
45
46             if ( _css != null )
47             {
48                 buff.append( " class='" ).append( _css ).append( "'" );
49             }
50
51             buff.append( ">" );
52
53             Iterator JavaDoc it = CreditCardNames.all( ).iterator( );
54
55             while ( it.hasNext( ) )
56             {
57                 String JavaDoc cc = it.next( ).toString( );
58
59                 /* <option> */
60                 buff.append( "<option value='" ).append( cc ).append( "'" );
61
62                 if ( cc.equals( _value ) )
63                 {
64                     buff.append( " selected" );
65                 }
66
67                 buff.append( ">" );
68
69                 /* value */
70                 buff.append( cc );
71
72                 /* </option> */
73                 buff.append( "</option>" );
74             }
75
76             /* </select> */
77             buff.append( "</select>" );
78
79             pageContext.getOut( ).println( buff.toString( ) );
80
81             System.out.println( "customerForm=" + pageContext.getAttribute( "customerForm" ) );
82
83             return EVAL_PAGE;
84         }
85         catch ( Exception JavaDoc e )
86         {
87             throw new JspException JavaDoc( e );
88         }
89     }
90
91     /**
92      * Returns the css.
93      * @return String
94      *
95      * @jsp.attribute
96      */

97     public String JavaDoc getCss( )
98     {
99         return _css;
100     }
101
102     /**
103      * Returns the name.
104      * @return String
105      *
106      * @jsp.attribute
107      * required="true"
108      */

109     public String JavaDoc getName( )
110     {
111         return _name;
112     }
113
114     /**
115      * Returns the value.
116      * @return String
117      *
118      * @jsp.attribute
119      * rtexprvalue="true"
120      */

121     public String JavaDoc getValue( )
122     {
123         return _value;
124     }
125
126     /**
127      * Sets the css.
128      * @param css The css to set
129      */

130     public void setCss( String JavaDoc css )
131     {
132         _css = css;
133     }
134
135     /**
136      * Sets the name.
137      * @param name The name to set
138      */

139     public void setName( String JavaDoc name )
140     {
141         _name = name;
142     }
143
144     /**
145      * Sets the value.
146      * @param value The value to set
147      */

148     public void setValue( String JavaDoc value )
149     {
150         _value = value;
151     }
152 }
153
Popular Tags