1 package jodd.servlet.tags.basic; 2 3 import java.io.IOException; 4 5 import javax.servlet.http.HttpServletRequest; 6 import javax.servlet.jsp.JspWriter; 7 import javax.servlet.jsp.tagext.TagSupport; 8 9 import jodd.bean.BeanUtil; 10 import jodd.util.StringUtil; 11 12 16 public class GetPropertyTag extends TagSupport { 17 18 private String beanName = null; 19 24 public void setBean(String v) { 25 beanName = v; 26 } 27 32 protected String getBean() { 33 return beanName; 34 } 35 36 private String name = ""; 37 42 public void setName(String v) { 43 name = v; 44 } 45 50 protected String getName() { 51 return name; 52 } 53 54 private String scope = "page"; 55 63 public void setScope(String v) { 64 scope = v; 65 } 66 67 72 protected Object getBeanObject() { 73 Object bean = null; 74 if (scope.equals("page")) { 75 bean = pageContext.getAttribute(beanName); 76 } else if (scope.equals("request")) { 77 bean = ((HttpServletRequest)pageContext.getRequest()).getAttribute(beanName); 78 } else if (scope.equals("session")) { 79 bean = ((HttpServletRequest)pageContext.getRequest()).getSession().getAttribute(beanName); 80 } 81 return bean; 82 } 83 84 public int doStartTag() { 85 try { 86 JspWriter out = pageContext.getOut(); 87 Object bean = getBeanObject(); 88 if (bean != null) { 89 out.print(StringUtil.toString(BeanUtil.getProperty(bean, name))); 90 } 91 } catch (IOException ioe) { 92 } 93 return SKIP_BODY; 94 } 95 } 96 | Popular Tags |