/Users/lyon/j4p/src/net/server/servlets/ReviewForm.java

1    package net.server.servlets; 
2     
3     
4    /** 
5     * The ReviewForm class extends the functionality of the 
6     * HtmlPage class. This class is employed to create a specific 
7     * type of HTML page, the Review Form. 
8     * 
9     * @author Robert Lysik 
10    * @version 1.00 
11    */ 
12   public class ReviewForm extends net.server.servlets.HtmlPage { 
13       private net.server.servlets.HtmlTable table; 
14    
15       /** 
16        * This is the default constructor for the ReviewForm class. 
17        * The parent class, HtmlPage, constructor is called with 
18        * the title of the page to be created. 
19        */ 
20       public ReviewForm(String courseId, 
21                         String sectionId, 
22                         Course course, 
23                         Student[] studentArray) { 
24           // Call the parent class with the title string 
25           super("Competency-based Review Form"); 
26    
27           String[] studentNameArray = new String[studentArray.length]; 
28    
29           for (int index = 0; index < studentArray.length; index++) 
30               studentNameArray[index] = studentArray[index].getFullName(); 
31    
32           // The table headings to display 
33           String colHeadings[] = {"Student Name", 
34                                   "Analytical Skills", 
35                                   "Communication Skills", 
36                                   "Creative Problem Solving", 
37                                   "Life-long Learning", 
38                                   "Project Management", 
39                                   "Research Skills", 
40                                   "System Thinking", 
41                                   "Teamwork"}; 
42    
43           createTable(studentNameArray, colHeadings); 
44    
45           addHeadline(1, "Form C: Competency-based Review Form " + 
46                   "for Basic Knowledge, Skills and Abilities"); 
47           addBreak(); 
48           addText("Complete for all students in your " + 
49                   "class using a scale from 1 to 5"); 
50           addBreak(); 
51           startForm("get", 
52                   "http://localhost:8080/examples/servlet/FormProcessorServlet"); 
53           addHeadline(2, "Course Number & Name "); 
54           addText(courseId + " section: " + sectionId); 
55           addHeadline(2, "Instructor "); 
56           addText(course.getInstructor()); 
57           addHeadline(2, "Term "); 
58           addText(course.getTerm()); 
59           addBreak(); 
60    
61           addText(table.getHtml()); 
62    
63           // Hidden input controls are inserted into the HTML 
64           // page so that data can be returned. This information includes 
65           // column and row headings, the number of rows and columns, 
66           // and a flag indicating whether or not the form has 
67           // been submitted. 
68           for (int rowIndex = 0; rowIndex < studentArray.length; rowIndex++) 
69               addHidden("student" + rowIndex, studentArray[rowIndex].getFullName()); 
70    
71           for (int rowIndex = 0; rowIndex < studentArray.length; rowIndex++) 
72               addHidden("recordnum" + rowIndex, "" + studentArray[rowIndex].getStudentRecordNumber()); 
73    
74           for (int colIndex = 0; colIndex < colHeadings.length; colIndex++) 
75               addHidden("heading" + colIndex, colHeadings[colIndex]); 
76    
77           addHidden("rows", "" + studentArray.length); 
78           addHidden("cols", "" + colHeadings.length); 
79           addHidden("course", courseId); 
80           addHidden("section", sectionId); 
81           addHidden("instructor", course.getInstructor()); 
82           addHidden("term", course.getTerm()); 
83           addHidden("year", course.getYear()); 
84           addHidden("status", "evaluation_complete"); 
85    
86           addSubmit("Submit Form Data"); 
87    
88           endForm(); 
89       } 
90    
91       private void createTable(String students[], 
92                                String[] colHeadings) { 
93           int colIndex = 0, 
94                   rowIndex = 0; 
95    
96           String select = new String(); 
97    
98           // The values for the drop down list box 
99           String values[] = {"1", "2", "3", "4", "5"}; 
100   
101          // The text to be displayed in the drop down list box 
102   
103   
104          table = new net.server.servlets.HtmlTable(students.length + 1, 
105                  colHeadings.length, 1); 
106   
107          // Populate the table with the headings 
108          for (colIndex = 0; colIndex < colHeadings.length; colIndex++) 
109              table.setElement(0, colIndex, colHeadings[colIndex]); 
110   
111          // Populate the table with the students' names 
112          for (rowIndex = 0; rowIndex < students.length; rowIndex++) 
113              table.setElement(rowIndex + 1, 0, students[rowIndex]); 
114   
115          // For each element in the table grid which is not a heading or 
116          // a student name, insert a drop down list box with five 
117          // selectable values. 
118          for (rowIndex = 1; rowIndex <= students.length; rowIndex++) 
119              for (colIndex = 1; colIndex < colHeadings.length; colIndex++) { 
120                  select = "r" + rowIndex + "c" + colIndex; 
121                  table.setElement(rowIndex, 
122                          colIndex, 
123                          getSelect(select, "1", values, values)); 
124              } 
125   
126      } 
127  } 
128