1 7 package com.inversoft.verge.mvc.view.jsp.form; 8 9 10 import java.util.Collection ; 11 import java.util.Iterator ; 12 13 import javax.servlet.jsp.tagext.TagData ; 14 import javax.servlet.jsp.tagext.VariableInfo ; 15 16 import org.apache.log4j.Logger; 17 18 import com.inversoft.util.StringTools; 19 import com.inversoft.verge.mvc.MVCException; 20 import com.inversoft.verge.mvc.controller.form.FormMVCMetaData; 21 import com.inversoft.verge.mvc.controller.form.config.FormConfig; 22 import com.inversoft.verge.util.WebBean; 23 24 25 31 public class FormTei extends com.inversoft.verge.mvc.view.jsp.html.FormTei { 32 33 36 private static final Logger logger = Logger.getLogger(FormTei.class); 37 38 39 42 public boolean isValid(TagData data) { 43 boolean valid = true; 44 String form = data.getAttributeString("form"); 45 if (form != null) { 46 FormMVCMetaData metaData = new FormMVCMetaData(form, null); 47 FormConfig config = null; 48 try { 49 config = (FormConfig) metaData.findFormConfig(null); 50 51 Collection formBeans = config.getFormBeans(); 52 String var = data.getAttributeString("var"); 53 if (formBeans.size() > 1 && var != null) { 54 logger.error("The var attribute of the form tag should " + 55 "only be used when the form has a single form bean"); 56 valid = false; 57 } 58 } catch (MVCException mvce) { 59 logger.error(mvce); 60 valid = false; 61 } 62 } else { 63 valid = false; 64 } 65 66 valid &= super.isValid(data); 68 69 return valid; 70 } 71 72 77 public VariableInfo [] getVariableInfo(TagData data) { 78 String form = data.getAttributeString("form"); 79 FormMVCMetaData metaData = new FormMVCMetaData(form, null); 80 81 FormConfig config = null; 82 try { 83 config = (FormConfig) metaData.findFormConfig(null); 84 } catch (MVCException mvce) { 85 logger.fatal(mvce); 86 throw new IllegalArgumentException ("Invalid form name: " + form); 87 } 88 89 Collection formBeans = config.getFormBeans(); 90 VariableInfo [] infos = new VariableInfo [formBeans.size()]; 91 Iterator iter = formBeans.iterator(); 92 WebBean webBean; 93 int count = 0; 94 String var = data.getAttributeString("var"); 95 while (iter.hasNext()) { 96 webBean = (WebBean) iter.next(); 97 98 if (StringTools.isEmpty(var)) { 99 var = webBean.getID(); 100 } 101 102 infos[count] = new VariableInfo (var, webBean.getClassName(), true, 103 VariableInfo.NESTED); 104 } 105 106 return infos; 107 } 108 } | Popular Tags |