1 5 package com.opensymphony.webwork.views.jsp; 6 7 import com.opensymphony.xwork.ObjectFactory; 8 import com.opensymphony.xwork.util.OgnlUtil; 9 import com.opensymphony.xwork.util.OgnlValueStack; 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 13 import javax.servlet.jsp.JspException ; 14 import java.util.Map ; 15 16 17 50 public class BeanTag extends WebWorkTagSupport implements ParamTag.Parametric { 51 53 protected static Log log = LogFactory.getLog(BeanTag.class); 54 55 57 protected Object bean; 58 protected String name; 59 60 62 public void setName(String name) { 63 this.name = name; 64 } 65 66 public Map getParameters() { 67 return null; 68 } 69 70 public void addParameter(String key, Object value) { 71 OgnlUtil.setProperty(key, value, bean, getStack().getContext()); 72 } 73 74 public int doEndTag() throws JspException { 75 OgnlValueStack stack = getStack(); 76 stack.pop(); 77 78 return SKIP_BODY; 79 } 80 81 public int doStartTag() throws JspException { 82 if (name == null) { 83 throw new JspException ("Bean name must be specified."); 84 } 85 86 try { 87 bean = ObjectFactory.getObjectFactory().buildBean(Class.forName(findString(name))); 88 } catch (Exception e) { 89 log.error("Could not instantiate bean", e); 90 91 return SKIP_PAGE; 92 } 93 94 OgnlValueStack stack = getStack(); 95 96 stack.push(bean); 98 99 if (getId() != null) { 101 pageContext.setAttribute(getId(), bean); 102 getStack().getContext().put(getId(), bean); 103 } 104 105 return EVAL_BODY_INCLUDE; 106 } 107 } 108 | Popular Tags |