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 FormViewSeveralFormViewConfig { 16 17 20 public static void main(String [] args) 21 throws FormViewException, IOException , SAXException { 22 InputStream [] inSeveralFomView = new InputStream [2]; 23 24 25 FormViewResources resources = null; 27 try { 28 29 35 inSeveralFomView[0] = FormViewSeveralFormViewConfig.class.getResourceAsStream("form-view-test1.xml"); 36 inSeveralFomView[1] = FormViewSeveralFormViewConfig.class.getResourceAsStream("form-view-test2.xml"); 37 resources = new FormViewResources(inSeveralFomView); 38 39 } finally { 40 if (inSeveralFomView != null) { 42 for (int streamIndex = 0;streamIndex < inSeveralFomView.length;streamIndex++) { 43 InputStream inFormView = (InputStream ) inSeveralFomView[streamIndex]; 44 inFormView.close(); 45 } 46 } 47 } 48 49 InputStream inDisplayerConfig = null; 50 DisplayersConfigResources displayersResources = null; 52 try { 53 54 inDisplayerConfig = DisplayersConfigResources.class.getResourceAsStream("displayers-config.xml"); 55 displayersResources = new DisplayersConfigResources(inDisplayerConfig); 56 57 } finally { 58 if (inDisplayerConfig != null) { 60 inDisplayerConfig.close(); 61 } 62 } 63 resources.mergeDisplayersWithDisplayerConfig(displayersResources); 64 65 InputStream inValidator = null; 67 ExtendedValidatorResources validatorResources = null; 68 69 try { 70 71 inValidator = FormViewSeveralFormViewConfig.class.getResourceAsStream("validation.xml"); 77 validatorResources = new ExtendedValidatorResources(inValidator); 78 79 } finally { 80 if (inValidator != null) { 82 inValidator.close(); 83 } 84 } 85 86 resources.mergeFormSetWithValidator(validatorResources); 87 88 resources.addContextValue("contextPath", "myapplication"); 90 91 String formName = "/user/identite_collaborateur"; 92 String state = "CREATE"; 93 94 ApplicationFormViewUtil.init(resources); 95 96 FormView form = ApplicationFormViewUtil.getFormView(formName, state); 97 99 101 IPermissionsAdapter permissionsAdapter = new TestRolesPermissionAdapter(); 102 103 104 105 String htmlContent = getHtmlContent(); 107 String htmlContentProcess = ApplicationFormViewUtil.processHtmlContent(form, state, permissionsAdapter, htmlContent); 108 System.out.println(htmlContentProcess); 109 110 111 } 112 113 private static String getHtmlContent2() { 114 StringBuffer htmlContent = new StringBuffer (""); 115 htmlContent.append("<html>\n"); 116 htmlContent.append("<input name=\"buttonSave\" type=\"button\" >\n"); 117 htmlContent.append("</html>\n"); 118 return htmlContent.toString(); 119 } 120 121 private static String getHtmlContent() { 122 StringBuffer htmlContent = new StringBuffer (""); 123 htmlContent.append("<html>\n"); 124 htmlContent.append("<input name=\"buttonSave\" type=\"button\" >\n"); 125 htmlContent.append("<input name=\"nom\" type=\"text\" >\n"); 126 htmlContent.append("<input name=\"prenom\" type=\"text\" maxlength=\"200\" >\n"); 127 htmlContent.append("<input name=\"dateNaissance\" type=\"text\" maxlength=\"8\" >\n"); 128 htmlContent.append("<input name=\"lieuNaissance\" type=\"text\" >\n"); 129 htmlContent.append("<input name=\"INPUT_NOT_IN_FORM\" type=\"text\" >\n"); 130 htmlContent.append("<select name=\"selectList\" >\n"); 131 htmlContent.append("<option value=\"ITEM0\" >Item0</option>"); 132 htmlContent.append("<option value=\"ITEM1\" selected=\"selected\">Item1</option>"); 133 htmlContent.append("</select>\n"); 134 135 htmlContent.append("</html>\n"); 136 return htmlContent.toString(); 137 } 138 139 } 140 | Popular Tags |