1 12 package org.displaytag.tags; 13 14 import javax.servlet.jsp.JspException ; 15 import javax.servlet.jsp.tagext.BodyTagSupport ; 16 17 import org.displaytag.exception.MissingAttributeException; 18 import org.displaytag.exception.TagStructureException; 19 20 21 26 public class SetPropertyTag extends BodyTagSupport 27 { 28 29 32 private static final long serialVersionUID = 899149338534L; 33 34 37 private String name; 38 39 42 private String value; 43 44 47 private boolean firstIteration; 48 49 53 public void setName(String propertyName) 54 { 55 this.name = propertyName; 56 } 57 58 62 public void setValue(String propertyValue) 63 { 64 this.value = propertyValue; 65 } 66 67 70 public int doStartTag() throws JspException 71 { 72 TableTag tableTag = (TableTag) findAncestorWithClass(this, TableTag.class); 73 74 if (tableTag == null) 75 { 76 throw new TagStructureException(getClass(), "setProperty", "table"); } 78 79 if (tableTag.isFirstIteration()) 81 { 82 this.firstIteration = true; 83 return 2; 85 } 86 87 this.firstIteration = false; 88 return SKIP_BODY; 89 90 } 91 92 102 public int doEndTag() throws MissingAttributeException 103 { 104 105 if (this.firstIteration) 106 { 107 TableTag tableTag = (TableTag) findAncestorWithClass(this, TableTag.class); 108 109 if (this.value == null) 111 { 112 if (getBodyContent() == null) 113 { 114 throw new MissingAttributeException(getClass(), new String []{"value", "body content"}); } 117 this.value = getBodyContent().getString(); 118 } 119 120 tableTag.setProperty(this.name, this.value); 121 122 this.name = null; 123 this.value = null; 124 } 125 return EVAL_PAGE; 126 } 127 128 } | Popular Tags |