1 23 24 package org.dbforms.taglib; 25 26 import org.dbforms.config.ResultSetVector; 27 28 import org.dbforms.util.Util; 29 30 import java.io.UnsupportedEncodingException ; 31 32 import java.util.Map ; 33 34 import javax.servlet.jsp.JspException ; 35 36 37 38 48 public class DbBodyTag extends DbBaseHandlerTag 49 implements javax.servlet.jsp.tagext.TryCatchFinally { 50 private String allowNew = "true"; 51 52 57 public void setAllowNew(String allowNew) { 58 this.allowNew = allowNew; 59 } 60 61 62 67 public String getAllowNew() { 68 return allowNew; 69 } 70 71 72 79 public int doAfterBody() throws JspException { 80 DbFormTag myParent = getParentForm(); 81 82 try { 83 if (myParent.getTable() != null) { 90 String curKeyString = myParent.getTable() 91 .getKeyPositionString(myParent 92 .getResultSetVector()); 93 94 if (!Util.isNull(curKeyString)) { 95 curKeyString = Util.encode(curKeyString, 96 pageContext.getRequest().getCharacterEncoding()); 97 myParent.appendToChildElementOutput("<input type=\"hidden\" name=\"k_" 98 + myParent.getTable().getId() 99 + "_" 100 + myParent.getPositionPath() 101 + "\" value=\"" 102 + curKeyString + "\"/>"); 103 } 104 } 105 } catch (UnsupportedEncodingException uee) { 106 throw new JspException (uee.toString()); 107 } 108 if (myParent.isSubForm() && myParent.isFooterReached() && Util.getTrue(getAllowNew())) { 111 myParent.appendToChildElementOutput(myParent.produceLinkedTags()); } 113 114 115 return SKIP_BODY; 116 } 117 118 119 126 public void doCatch(Throwable t) throws Throwable { 127 throw t; 128 } 129 130 131 138 public int doEndTag() throws JspException { 139 try { 140 if (bodyContent != null) { 141 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 142 bodyContent.clearBody(); 143 144 } 146 } catch (java.io.IOException e) { 147 throw new JspException ("IO Error: " + e.getMessage()); 148 } 149 150 return EVAL_PAGE; 151 } 152 153 154 156 159 public void doFinally() { 160 allowNew = "true"; 161 } 162 163 164 169 public int doStartTag() throws javax.servlet.jsp.JspException { 170 DbFormTag myParent = getParentForm(); 171 ResultSetVector rsv = myParent.getResultSetVector(); 172 if ( 176 (!ResultSetVector.isNull(rsv) && myParent.isFooterReached()) 177 || 178 (ResultSetVector.isNull(rsv) && Util.getFalse(allowNew)) 179 ) { 180 return SKIP_BODY; 181 } 182 183 myParent.updatePositionPath(); 184 190 if (!ResultSetVector.isNull(rsv)) { 191 Map dbforms = (Map ) pageContext.getAttribute("dbforms"); 192 193 if (dbforms != null) { 194 DbFormContext dbContext = (DbFormContext) dbforms.get(myParent 195 .getName()); 196 if (dbContext != null) { 197 dbContext.setCurrentRow(rsv.getCurrentRowAsMap()); 198 try { 199 dbContext.setPosition(Util.encode(myParent.getTable().getPositionString(rsv), 200 pageContext.getRequest().getCharacterEncoding())); 201 } catch (Exception e) { 202 throw new JspException (e.getMessage()); 203 } 204 } 205 } 206 207 if (!rsv.isLast()) { 208 rsv.moveNext(); 210 pageContext.setAttribute("currentRow_" 215 + myParent.getTableName().replace('.', '_'), 216 rsv.getCurrentRowAsMap()); 217 218 try { 219 pageContext.setAttribute("position_" 220 + myParent.getTableName().replace('.', 221 '_'), 222 Util.encode(myParent.getTable().getPositionString(rsv), 223 pageContext.getRequest().getCharacterEncoding())); 224 } catch (Exception e) { 225 throw new JspException (e.getMessage()); 226 } 227 228 rsv.movePrevious(); } 230 } 231 232 return EVAL_BODY_BUFFERED; 233 } 234 } 235 | Popular Tags |