1 16 17 package org.springframework.web.servlet.tags.form; 18 19 import javax.servlet.jsp.JspException ; 20 21 import org.springframework.util.Assert; 22 import org.springframework.util.StringUtils; 23 24 37 public class LabelTag extends AbstractHtmlElementTag { 38 39 42 private static final String LABEL_TAG = "label"; 43 44 47 private static final String FOR_ATTRIBUTE = "for"; 48 49 50 54 private TagWriter tagWriter; 55 56 59 private String forId; 60 61 62 67 public void setFor(String forId) { 68 Assert.notNull(forId, "'forId' must not be null"); 69 this.forId = forId; 70 } 71 72 76 public String getFor() { 77 return this.forId; 78 } 79 80 81 86 protected int writeTagContent(TagWriter tagWriter) throws JspException { 87 tagWriter.startTag(LABEL_TAG); 88 tagWriter.writeAttribute(FOR_ATTRIBUTE, resolveFor()); 89 writeDefaultAttributes(tagWriter); 90 tagWriter.forceBlock(); 91 this.tagWriter = tagWriter; 92 return EVAL_BODY_INCLUDE; 93 } 94 95 101 protected String getName() throws JspException { 102 return ""; 104 } 105 106 109 protected final String resolveFor() throws JspException { 110 if (StringUtils.hasText(this.forId)) { 111 return getDisplayString(evaluate(FOR_ATTRIBUTE, this.forId)); 112 } 113 else { 114 return getCompletePath(); 115 } 116 } 117 118 122 public int doEndTag() throws JspException { 123 this.tagWriter.endTag(); 124 return EVAL_PAGE; 125 } 126 127 130 public void doFinally() { 131 super.doFinally(); 132 this.tagWriter = null; 133 } 134 135 } 136 | Popular Tags |