1 package fr.improve.struts.taglib.layout.util; 2 3 import java.util.List ; 4 import java.util.MissingResourceException ; 5 6 import javax.servlet.jsp.JspException ; 7 import javax.servlet.jsp.PageContext ; 8 9 import org.apache.struts.Globals; 10 11 import fr.improve.struts.taglib.layout.field.AbstractLayoutFieldTag; 12 import fr.improve.struts.taglib.layout.skin.Skin; 13 14 18 public class BasicField implements FieldInterface { 19 22 public int getColumnNumber() { 23 return 2; 24 } 25 26 29 public void doStartField(StringBuffer in_buffer, AbstractLayoutFieldTag in_tag, String in_label, Object in_value) throws JspException { 30 in_buffer.append("<th valign=\"top"); 32 33 if (in_tag.getStyleClass()!=null) { 35 in_buffer.append("\" class=\""); 36 in_buffer.append(in_tag.getStyleClass()); 37 } 38 39 String lc_layoutId = in_tag.getLayoutId(); 41 if (lc_layoutId!=null) { 42 in_buffer.append("\" id=\""); 43 in_buffer.append(lc_layoutId); 44 in_buffer.append("L"); 45 } 46 47 in_buffer.append("\"><span"); 49 if (in_tag.getStyleClass()!=null) { 50 in_buffer.append(" class=\""); 51 in_buffer.append(in_tag.getStyleClass()); 52 in_buffer.append("\""); 53 } 54 55 if (in_tag.getHint()!=null) { 57 in_buffer.append(" title=\""); 58 in_buffer.append(LayoutUtils.getLabel(in_tag.getPageContext(), in_tag.getBundle(), in_tag.getHint(), null, false)); 59 in_buffer.append("\""); 60 } 61 62 if (in_tag.getStyle()!=null) { 64 in_buffer.append(" style=\""); 65 in_buffer.append(in_tag.getStyle()); 66 in_buffer.append("\""); 67 } 68 in_buffer.append(">"); 69 70 if (in_label!=null) { 72 StringBuffer lc_label = new StringBuffer (in_label); 73 for (int i=0;i<lc_label.length();i++) { 74 if (lc_label.charAt(i)==' ') lc_label.replace(i,i+1," "); 75 } 76 in_buffer.append(lc_label.toString()); 77 } else { 78 in_buffer.append(" "); 79 } 80 in_buffer.append("</span></th>"); 81 82 in_buffer.append("<td valign=\"top\" class=\""); 84 in_buffer.append(in_tag.getStyleClass()); 85 86 if (lc_layoutId!=null) { 88 in_buffer.append("\" id=\""); 89 in_buffer.append(lc_layoutId); 90 in_buffer.append("F"); 91 } 92 93 String lc_style = LayoutUtils.getSkin(in_tag.getPageContext().getSession()).getFormUtils().getFieldValueStyle(in_tag.getPageContext()); 95 if (lc_style!=null) { 96 in_buffer.append("\" style=\""); 97 in_buffer.append(lc_style); 98 } 99 in_buffer.append("\">"); 100 } 101 102 public void doEndField(StringBuffer in_buffer, AbstractLayoutFieldTag in_tag, Object in_value) throws JspException { 103 String lc_property = in_tag.getProperty(); 105 PageContext lc_pageContext = in_tag.getPageContext(); 106 Skin lc_skin = LayoutUtils.getSkin(lc_pageContext.getSession()); 107 108 boolean lc_valueSet = in_tag.isFill(in_value); 109 110 if (in_tag.isRequired() && !lc_valueSet) { 111 in_buffer.append("<img name=\"" + lc_property + "required\" SRC=\"" + lc_skin.getImageDirectory(lc_pageContext.getRequest()) + "/ast.gif\" alt=\"required\">"); 112 } else { 113 in_buffer.append("<img name=\"" + lc_property + "required\" SRC=\"" + lc_skin.getImageDirectory(lc_pageContext.getRequest()) + "/clearpixel.gif\" alt=\"required\">"); 114 } 115 116 in_buffer.append("</td>"); 118 in_tag = null; 119 } 120 121 public void doStartErrors(StringBuffer in_buffer, AbstractLayoutFieldTag in_tag, List in_errors) { 122 in_buffer.append("<table><tr><td class=\""); 123 in_buffer.append(in_tag.getErrorStyleClass()); 124 in_buffer.append("\">"); 125 } 126 127 public void doEndErrors(StringBuffer in_buffer, AbstractLayoutFieldTag in_tag, List in_errors) throws JspException { 128 boolean useErrorsMessages = false; 129 try { 130 useErrorsMessages = "true".equalsIgnoreCase(LayoutUtils.getSkin(in_tag.getPageContext().getSession()).getProperty("error.format")); 131 } catch (MissingResourceException e) { 132 } 134 boolean headerPresent = useErrorsMessages && TagUtils.present(in_tag.getPageContext(), in_tag.getBundle(), Globals.LOCALE_KEY, "errors.header"); 135 boolean footerPresent = useErrorsMessages && TagUtils.present(in_tag.getPageContext(), in_tag.getBundle(), Globals.LOCALE_KEY, "errors.footer"); 136 boolean prefixPresent = useErrorsMessages && TagUtils.present(in_tag.getPageContext(), in_tag.getBundle(), Globals.LOCALE_KEY, "errors.prefix"); 137 boolean suffixPresent = useErrorsMessages && TagUtils.present(in_tag.getPageContext(), in_tag.getBundle(), Globals.LOCALE_KEY, "errors.suffix"); 138 139 if (headerPresent && in_errors.size()>0) { 140 in_buffer.append(TagUtils.message(in_tag.getPageContext(),in_tag.getBundle(),Globals.LOCALE_KEY,"errors.header")); 141 } 142 for (int i=0;i<in_errors.size();i++) { 143 if (prefixPresent) { 144 in_buffer.append(TagUtils.message(in_tag.getPageContext(),in_tag.getBundle(),Globals.LOCALE_KEY,"errors.prefix")); 145 } 146 in_buffer.append(in_errors.get(i)); 147 if (suffixPresent) { 148 in_buffer.append(TagUtils.message(in_tag.getPageContext(),in_tag.getBundle(),Globals.LOCALE_KEY,"errors.suffix")); 149 } else { 150 if (i<in_errors.size()) in_buffer.append("<br />"); 151 } 152 } 153 if (suffixPresent && in_errors.size()>0) { 154 in_buffer.append(TagUtils.message(in_tag.getPageContext(),in_tag.getBundle(),Globals.LOCALE_KEY,"errors.footer")); 155 } 156 in_buffer.append("</td></tr></table>"); 157 } 158 } | Popular Tags |