KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > formview > test > FormViewTestSelectMultiple


1 package net.sourceforge.formview.test;
2
3 import java.io.IOException JavaDoc;
4 import java.io.InputStream JavaDoc;
5
6 import net.sourceforge.formview.FormView;
7 import net.sourceforge.formview.FormViewException;
8 import net.sourceforge.formview.FormViewResources;
9 import net.sourceforge.formview.displayer.DisplayersConfigResources;
10 import net.sourceforge.formview.util.ApplicationFormViewUtil;
11
12 import org.xml.sax.SAXException JavaDoc;
13
14 public class FormViewTestSelectMultiple {
15
16     /**
17      * @param args
18      */

19     public static void main(String JavaDoc[] args)
20         throws FormViewException, IOException JavaDoc, SAXException JavaDoc {
21         InputStream JavaDoc inFomView = null;
22
23         
24         // Load Form view
25
FormViewResources resources = null;
26         try {
27             
28             // Create a new instance of a ValidatorResource, then get a stream
29
// handle on the XML file with the actions in it, and initialize the
30
// resources from it. This would normally be done by a servlet
31
// run during JSP initialization or some other application-startup
32
// routine.
33

34             inFomView = FormViewTest.class.getResourceAsStream("form-view-test.xml");
35             resources = new FormViewResources(inFomView);
36             
37         } finally {
38 // Make sure we close the input stream.
39
if (inFomView != null) {
40                 inFomView.close();
41             }
42
43         }
44
45         InputStream JavaDoc inDisplayerConfig = null;
46         // Merge with DisplayersConfigResources
47
DisplayersConfigResources displayersResources = null;
48         try {
49             
50             inDisplayerConfig = DisplayersConfigResources.class.getResourceAsStream("displayers-config.xml");
51             displayersResources = new DisplayersConfigResources(inDisplayerConfig);
52             
53         } finally {
54 // Make sure we close the input stream.
55
if (inDisplayerConfig != null) {
56                 inDisplayerConfig.close();
57             }
58         }
59         resources.mergeDisplayersWithDisplayerConfig(displayersResources);
60         
61         String JavaDoc formName = "/user/identite_collaborateur";
62         String JavaDoc state = "READ";
63         ApplicationFormViewUtil.init(resources);
64         
65         FormView form = ApplicationFormViewUtil.getFormView(formName, state);
66         //defaultBehaviour = FormViewUtil.getDefaultBehaviour(defaultState);
67

68         
69         // Test role with buttonSave
70
String JavaDoc htmlContent = getHtmlContent();
71         String JavaDoc htmlContentProcess = ApplicationFormViewUtil.processHtmlContent(form, state, null, htmlContent);
72         System.out.println(htmlContentProcess);
73         
74
75     }
76     
77     private static String JavaDoc getHtmlContent() {
78         StringBuffer JavaDoc htmlContent = new StringBuffer JavaDoc("");
79         htmlContent.append("<select name=\"HTMLSelect\" multiple=\"multiple\" >\n");
80         for (int i=0; i< 10; i++) {
81             String JavaDoc selected = "";
82             if (i<5) {
83                 selected = "selected=\"selected\"";
84             }
85             
86             htmlContent.append("<option value=\"HTMLSelect value " + i + "\" " + selected + " >HTMLSelect label " + i + "</option>\n");
87         }
88         htmlContent.append("</select>\n");
89         return htmlContent.toString();
90     }
91     
92     
93 }
94
Popular Tags