1 package albel.tags.table; 2 3 import albel.tags.table.controll.Manager; 4 import albel.tags.table.model.Column; 5 import albel.tags.table.model.ColumnType; 6 import albel.tags.table.model.Table; 7 import albel.tags.table.model.TableTagException; 8 import albel.tags.table.utils.HttpSessionAttributesMap; 9 import javax.servlet.http.HttpServletRequest ; 10 import javax.servlet.jsp.JspException ; 11 import javax.servlet.jsp.tagext.BodyTagSupport ; 12 13 17 public class ColumnTag extends BodyTagSupport 18 { 19 20 public ColumnTag() 21 { 22 super(); 23 } 24 25 private String property; 26 27 30 private String type; 31 32 35 private int width; 36 37 45 46 54 public void otherDoStartTagOperations() 55 { 56 57 75 76 } 77 78 84 public boolean theBodyShouldBeEvaluated() 85 { 86 87 return true; 93 94 } 95 96 97 105 public void otherDoEndTagOperations() 106 { 107 108 116 117 } 118 119 126 public boolean shouldEvaluateRestOfPageAfterEndTag() 127 { 128 129 return true; 136 137 } 138 139 140 149 150 153 public int doStartTag() throws JspException 154 { 155 try 156 { 157 if(this.getParent() instanceof albel.tags.table.RowsTag) 158 { 159 doContextRows(); 160 } 161 else 162 if(this.getParent() instanceof albel.tags.table.NewRowColumnsTag) 163 doContextNewRow(); 164 } 165 catch (TableTagException tex) 166 { 167 throw new JspException (tex); 168 } 169 return this.EVAL_BODY_INCLUDE; 170 } 171 174 private void doContextRows()throws TableTagException 175 { 176 HttpServletRequest request=(HttpServletRequest )pageContext.getRequest(); 177 HttpSessionAttributesMap attrs=new HttpSessionAttributesMap(request.getSession()); 178 TableTag tableTag=(TableTag)this.getParent().getParent(); 179 Table table=Manager.getTable(attrs, tableTag.getId()); 180 boolean has=table.hasColumn(getProperty()); 181 if(!has) 182 { 183 Column col=new Column(table); 184 col.setProperty(getProperty()); 185 col.setType(ColumnType.getInstance(getType())); 186 col.setWidth(getWidth()); 187 table.addColumn(col); 188 } 189 } 190 193 private void doContextNewRow()throws TableTagException 194 { 195 HttpServletRequest request=(HttpServletRequest )pageContext.getRequest(); 196 HttpSessionAttributesMap attrs=new HttpSessionAttributesMap(request.getSession()); 197 TableTag tableTag=(TableTag)this.getParent().getParent(); 198 Table table=Manager.getTable(attrs, tableTag.getId()); 199 boolean has=table.getNewRowColumns().hasColumn(getProperty()); 200 if(!has) 201 { 202 Column col=new Column(table); 203 col.setProperty(getProperty()); 204 col.setType(ColumnType.getInstance(getType())); 205 col.setWidth(getWidth()); 206 table.getNewRowColumns().addColumn(col); 207 } 208 } 209 210 213 public int doEndTag() throws JspException 214 { 215 return EVAL_PAGE; 217 } 218 219 223 public String getProperty() 224 { 225 return property; 226 } 227 228 232 public void setProperty(String property) 233 { 234 this.property=property; 235 } 236 237 241 public String getType() 242 { 243 return this.type; 244 } 245 246 250 public void setType(String type) 251 { 252 this.type = type; 253 } 254 255 259 public int getWidth() 260 { 261 return this.width; 262 } 263 264 268 public void setWidth(int width) 269 { 270 this.width = width; 271 } 272 273 } 274 | Popular Tags |