1 package xpetstore.web.taglib; 2 3 import java.util.Iterator ; 4 5 import javax.servlet.jsp.JspException ; 6 import javax.servlet.jsp.tagext.TagSupport ; 7 8 import xpetstore.util.CreditCardNames; 9 10 11 22 public class CreditCardTag 23 extends TagSupport 24 { 25 27 private String _name; 28 private String _css; 29 private String _value; 30 31 33 36 public int doEndTag( ) 37 throws JspException 38 { 39 try 40 { 41 StringBuffer buff = new StringBuffer ( ); 42 43 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 it = CreditCardNames.all( ).iterator( ); 54 55 while ( it.hasNext( ) ) 56 { 57 String cc = it.next( ).toString( ); 58 59 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 70 buff.append( cc ); 71 72 73 buff.append( "</option>" ); 74 } 75 76 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 e ) 86 { 87 throw new JspException ( e ); 88 } 89 } 90 91 97 public String getCss( ) 98 { 99 return _css; 100 } 101 102 109 public String getName( ) 110 { 111 return _name; 112 } 113 114 121 public String getValue( ) 122 { 123 return _value; 124 } 125 126 130 public void setCss( String css ) 131 { 132 _css = css; 133 } 134 135 139 public void setName( String name ) 140 { 141 _name = name; 142 } 143 144 148 public void setValue( String value ) 149 { 150 _value = value; 151 } 152 } 153 | Popular Tags |