Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/RuntimeCollective/webapps/tag/ExamBoardInputTag.java


1   /*
2    * ExamBoardInputTag.java
3    *
4    * Created on July 31, 2003, 3:40 PM
5    */
6   
7   package com.RuntimeCollective.webapps.tag;
8   
9   /**
10   *
11   * @author  criss
12   */
13  import com.RuntimeCollective.webapps.RuntimeDataSource;
14  import com.RuntimeCollective.webapps.ExamBoards;
15  
16  import java.util.Iterator;
17  import java.sql.SQLException;
18  import java.io.IOException;
19  import java.io.PrintStream;
20  import javax.servlet.jsp.JspWriter;
21  import javax.servlet.jsp.PageContext;
22  import javax.servlet.jsp.JspException;
23  import javax.servlet.jsp.JspTagException;
24  import javax.servlet.jsp.tagext.Tag;
25  import javax.servlet.jsp.tagext.TagSupport;
26  import org.apache.struts.taglib.html.BaseHandlerTag;
27  import org.apache.struts.util.RequestUtils;
28  
29  /**A custom JSP tag that displays the Exam Board codes */
30  
31  public class ExamBoardInputTag extends BaseHandlerTag{
32      
33      protected StringBuffer options = new StringBuffer(10000);
34      
35      /** Creates a new instance of ExamBoardInputTag */
36      public ExamBoardInputTag() throws SQLException{
37          super();
38          Iterator codes = ExamBoards.codes();
39          String code = null;
40          options.append("<option value=\"Edexcel\">Edexcel</option>");
41          while(codes.hasNext()){
42              code = (String)codes.next();
43              options.append("<option value=\"");
44              options.append(code);
45              options.append("\">");
46              options.append(code);
47              options.append("</option>");
48          }
49      }
50          
51      
52      /*#### Properties ###################*/
53      /** The property name for the Board specified */
54      protected String property = "";
55      
56      /**Accessor method for the specified Board */
57      public String getProperty(){return this.property;}
58      
59      /**Mutator method for the specified Board */
60      public void setProperty(String property){this.property = property;}
61      
62        /** The form bean name. */
63      protected String name = "";
64      /** Get the form bean name. */
65      public String getName() { return this.name; }
66      /** Set the form bean name. */
67      public void setName( String name ) { this.name = name; }
68  
69       // == Tag methods ==================================
70  
71      public int doStartTag() throws JspException { 
72  
73    // Find the default country if the form is defined.
74    String def = "";
75    if (!name.equals("")) {
76        Object defObject = RequestUtils.lookup( pageContext, name, property, null );
77        if ( defObject!=null ) def = defObject.toString();
78    }
79  
80    // Generate the input tags for this property.
81    StringBuffer html = new StringBuffer(10000);
82    html.append("<select name=\""); html.append(getProperty()); html.append("\""); html.append(prepareStyles()); html.append(prepareEventHandlers()); html.append(">");
83  
84    // If there is a default then put it at the top of the list.
85    if ( !def.equals("") ) {
86        html.append("<option value=\"");
87        html.append(def);
88        html.append("\">");
89        html.append( def );
90        html.append("</option>");
91    } else {
92        // Else put a null option at the top of the list.
93        html.append("<option value=\"\">Select Exam Board</option>");
94    }
95    html.append(options.toString());
96    html.append("</select>");
97  
98    // And write the html to the jsp page.
99    try {
100       pageContext.getOut().println( html.toString() );
101   } catch (IOException e) {
102       throw new JspTagException("I/O Exception "+e.getMessage() );
103   }
104 
105   return SKIP_BODY;
106     }
107 
108     public void release() {
109   super.release();
110   property="";
111   name="";
112     }
113 
114 }
115 
116 
117