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.ObjectUtils; 23 import org.springframework.web.servlet.support.BindStatus; 24 import org.springframework.web.util.TagUtils; 25 26 36 public class OptionsTag extends AbstractFormTag { 37 38 42 private Object items; 43 44 48 private String itemValue; 49 50 54 private String itemLabel; 55 56 57 66 public void setItems(Object items) { 67 this.items = items; 68 } 69 70 75 protected Object getItems() { 76 return this.items; 77 } 78 79 86 public void setItemValue(String itemValue) { 87 Assert.hasText(itemValue, "'itemValue' must not be empty"); 88 this.itemValue = itemValue; 89 } 90 91 protected String getItemValue() { 92 return this.itemValue; 93 } 94 95 100 public void setItemLabel(String itemLabel) { 101 Assert.hasText(itemLabel, "'itemLabel' must not be empty"); 102 this.itemLabel = itemLabel; 103 } 104 105 110 protected String getItemLabel() { 111 return this.itemLabel; 112 } 113 114 115 protected int writeTagContent(TagWriter tagWriter) throws JspException { 116 assertUnderSelectTag(); 117 Object items = getItems(); 118 Object itemsObject = (items instanceof String ? evaluate("items", (String ) items) : items); 119 120 if (itemsObject != null) { 121 String itemValue = getItemValue(); 122 String itemLabel = getItemLabel(); 123 124 String valueProperty = 125 (itemValue != null ? ObjectUtils.getDisplayString(evaluate("itemValue", itemValue)) : null); 126 String labelProperty = 127 (itemLabel != null ? ObjectUtils.getDisplayString(evaluate("itemLabel", itemLabel)) : null); 128 129 OptionWriter optionWriter = 130 new OptionWriter(itemsObject, getBindStatus(), valueProperty, labelProperty, isHtmlEscape()); 131 optionWriter.writeOptions(tagWriter); 132 } 133 134 return EVAL_PAGE; 135 } 136 137 138 private void assertUnderSelectTag() { 139 TagUtils.assertHasAncestorOfType(this, SelectTag.class, "options", "select"); 140 } 141 142 private BindStatus getBindStatus() { 143 return (BindStatus) this.pageContext.getAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE); 144 } 145 146 } 147 | Popular Tags |