1 18 package net.sf.uitags.tag.panel; 19 20 import javax.servlet.jsp.JspException ; 21 22 import net.sf.uitags.tag.AbstractUiTag; 23 import net.sf.uitags.tagutil.TaglibProperties; 24 import net.sf.uitags.tagutil.validation.DeferredValidationException; 25 import net.sf.uitags.tagutil.validation.RuntimeValidator; 26 import net.sf.uitags.util.StringUtils; 27 import net.sf.uitags.util.Template; 28 29 35 public class ShowTag extends AbstractUiTag { 36 37 41 44 private static final long serialVersionUID = 100L; 45 46 47 51 private static final String PROP_EVENT = "panel.show.on"; 52 private static final String PROP_DELAY = "panel.show.delay"; 53 private static final String PROP_POSITION = "panel.show.position"; 54 55 56 60 63 private String injectTo; 64 65 68 private String injectToName; 69 70 73 private String on; 74 75 78 private Integer delayInMillis; 79 80 83 private String position; 84 85 86 90 95 public void setInjectTo(String val) { 96 this.injectTo = val; 97 } 98 99 104 public void setInjectToName(String val) { 105 this.injectToName = val; 106 } 107 108 113 public void setOn(String val) { 114 this.on = val; 115 } 116 117 122 public void setDelay(Integer val) { 123 this.delayInMillis = val; 124 } 125 126 131 public void setPosition(String position) { 132 this.position = position; 133 } 134 135 136 140 147 public int doStartTag() throws JspException { 148 return SKIP_BODY; 149 } 150 151 158 public int doEndTag() throws JspException { 159 RuntimeValidator.assertAttributeExclusive( 160 "injectTo", this.injectTo, "injectToName", this.injectToName); 161 RuntimeValidator.assertEitherSpecified( 162 "injectTo", this.injectTo, "injectToName", this.injectToName); 163 164 TaglibProperties props = TaglibProperties.getInstance(); 165 props.setRuntimeProperty(PROP_EVENT, this.on); 166 props.setRuntimeProperty(PROP_DELAY, StringUtils.toStringOrNull(this.delayInMillis)); 167 props.setRuntimeProperty(PROP_POSITION, this.position); 168 169 Template tpl = Template.forName(Template.PANEL_SHOW); 170 tpl.map("triggerId", this.injectTo); 171 tpl.map("triggerName", this.injectToName); 172 tpl.map("triggerEvent", props.get(PROP_EVENT)); 173 tpl.map("delayInMillis", Integer.valueOf(props.get(PROP_DELAY))); 174 tpl.map("attachedToMouse", isAttachedToMouse(props.get(PROP_POSITION))); 175 176 PanelTag parent = (PanelTag) findParent(PanelTag.class); 177 parent.addChildJsCode(tpl.evalToString()); 178 179 return EVAL_PAGE; 180 } 181 182 private Boolean isAttachedToMouse(String positionValue) { 183 if ("auto".equals(positionValue)) { 184 return Boolean.FALSE; 185 } 186 else if ("mouse".equals(positionValue)) { 187 return Boolean.TRUE; 188 } 189 else { 190 throw new DeferredValidationException( 191 "Position attribute must be either 'auto' or 'mouse'. Provided: '" + 192 positionValue + "'."); 193 } 194 } 195 } 196 | Popular Tags |