1 package net.sourceforge.formview.test; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 import org.xml.sax.SAXException ; 6 7 import net.sourceforge.formview.FormView; 8 import net.sourceforge.formview.FormViewException; 9 import net.sourceforge.formview.FormViewResources; 10 import net.sourceforge.formview.displayer.DisplayersConfigResources; 11 import net.sourceforge.formview.permission.IPermissionsAdapter; 12 import net.sourceforge.formview.util.ApplicationFormViewUtil; 13 import net.sourceforge.formview.validator.ExtendedValidatorResources; 14 15 public class FormViewTest { 16 17 20 public static void main(String [] args) 21 throws FormViewException, IOException , SAXException { 22 InputStream inFomView = null; 23 24 25 FormViewResources resources = null; 27 try { 28 29 35 inFomView = FormViewTest.class.getResourceAsStream("form-view-test.xml"); 36 resources = new FormViewResources(inFomView); 37 38 } finally { 39 if (inFomView != null) { 41 inFomView.close(); 42 } 43 44 } 45 46 InputStream inDisplayerConfig = null; 47 DisplayersConfigResources displayersResources = null; 49 try { 50 51 inDisplayerConfig = DisplayersConfigResources.class.getResourceAsStream("displayers-config.xml"); 52 displayersResources = new DisplayersConfigResources(inDisplayerConfig); 53 54 } finally { 55 if (inDisplayerConfig != null) { 57 inDisplayerConfig.close(); 58 } 59 } 60 resources.mergeDisplayersWithDisplayerConfig(displayersResources); 61 62 InputStream inValidator = null; 64 ExtendedValidatorResources validatorResources = null; 65 66 try { 67 68 inValidator = FormViewTest.class.getResourceAsStream("validation.xml"); 74 validatorResources = new ExtendedValidatorResources(inValidator); 75 76 } finally { 77 if (inValidator != null) { 79 inValidator.close(); 80 } 81 } 82 83 resources.mergeFormSetWithValidator(validatorResources); 84 85 resources.addContextValue("contextPath", "myapplication"); 87 88 String formName = "/user/identite_collaborateur"; 89 String state = "ERROR"; 90 91 ApplicationFormViewUtil.init(resources); 92 93 FormView form = ApplicationFormViewUtil.getFormView(formName, state); 94 96 98 IPermissionsAdapter permissionsAdapter = new TestRolesPermissionAdapter(); 99 100 String htmlContent = getHtmlContent(); 102 String htmlContentProcess = ApplicationFormViewUtil.processHtmlContent(form, state, permissionsAdapter, htmlContent); 103 System.out.println(htmlContentProcess); 104 105 106 } 107 108 private static String getHtmlContent2() { 109 StringBuffer htmlContent = new StringBuffer (""); 110 htmlContent.append("<html>\n"); 111 htmlContent.append("<input name=\"buttonSave\" type=\"button\" >\n"); 112 htmlContent.append("</html>\n"); 113 return htmlContent.toString(); 114 } 115 116 private static String getHtmlContent() { 117 StringBuffer htmlContent = new StringBuffer (""); 118 htmlContent.append("<html>\n"); 119 htmlContent.append("<input name=\"buttonSave\" type=\"button\" >\n"); 120 htmlContent.append("<div id=\"idDiv\" >"); 121 htmlContent.append("................................."); 122 htmlContent.append("</div>\n"); 123 htmlContent.append("<label for=\"nom\" >"); 124 htmlContent.append("Nom Label"); 125 htmlContent.append("</label>\n"); 126 htmlContent.append("<input name=\"nom\" type=\"text\" >\n"); 127 htmlContent.append("<input name=\"prenom\" type=\"text\" maxlength=\"200\" >\n"); 128 htmlContent.append("<input name=\"dateNaissance\" type=\"text\" maxlength=\"8\" >\n"); 129 htmlContent.append("<input name=\"lieuNaissance\" type=\"text\" >\n"); 130 htmlContent.append("<input name=\"INPUT_NOT_IN_FORM\" type=\"text\" >\n"); 131 htmlContent.append("<select name=\"selectList\" >\n"); 132 htmlContent.append("<option value=\"ITEM0\" >Item0</option>"); 133 htmlContent.append("<option value=\"ITEM1\" selected=\"selected\">Item1</option>"); 134 htmlContent.append("</select>\n"); 135 136 htmlContent.append("</html>\n"); 137 return htmlContent.toString(); 138 } 139 140 } 141 | Popular Tags |