1 7 package com.inversoft.verge.mvc.view.jsp.actionflow; 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.config.BaseFormConfig; 21 import com.inversoft.verge.mvc.controller.actionflow.ActionFlowMetaData; 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 String namespace = data.getAttributeString("namespace"); 47 if (namespace == null) { 48 valid = false; 49 } else { 50 ActionFlowMetaData metaData = new ActionFlowMetaData(namespace, form); 51 try { 52 BaseFormConfig config = metaData.findFormConfig(null); 53 Collection formBeans = config.getFormBeans(); 54 String var = data.getAttributeString("var"); 55 if (formBeans.size() > 1 && var != null) { 56 logger.error("The var attribute of the form tag should " + 57 "only be used when the form has a single form bean"); 58 valid = false; 59 } 60 } catch (MVCException mvce) { 61 logger.error(mvce); 62 valid = false; 63 } 64 } 65 } 66 67 valid &= super.isValid(data); 69 return valid; 70 } 71 72 77 public VariableInfo [] getVariableInfo(TagData data) { 78 VariableInfo [] infos = null; 79 String form = data.getAttributeString("form"); 80 if (form != null) { 81 String namespace = data.getAttributeString("namespace"); 82 ActionFlowMetaData metaData = new ActionFlowMetaData(namespace, form); 83 84 BaseFormConfig config = null; 85 try { 86 config = metaData.findFormConfig(null); 87 } catch (MVCException mvce) { 88 logger.fatal(mvce); 89 throw new IllegalArgumentException ("Invalid form name: " + form); 90 } 91 92 Collection formBeans = config.getFormBeans(); 93 infos = new VariableInfo [formBeans.size()]; 94 Iterator iter = formBeans.iterator(); 95 WebBean webBean; 96 int count = 0; 97 String var = data.getAttributeString("var"); 98 while (iter.hasNext()) { 99 webBean = (WebBean) iter.next(); 100 101 if (StringTools.isEmpty(var)) { 102 var = webBean.getID(); 103 } 104 105 infos[count] = new VariableInfo (var, webBean.getClassName(), true, 106 VariableInfo.NESTED); 107 } 108 } 109 110 return infos; 111 } 112 } | Popular Tags |