1 21 package net.mlw.vlh.web.tag; 22 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.jsp.JspException ; 25 26 import net.mlw.vlh.ValueList; 27 import net.mlw.vlh.ValueListHandler; 28 import net.mlw.vlh.ValueListInfo; 29 import net.mlw.vlh.web.ValueListRequestUtil; 30 import net.mlw.vlh.web.util.JspUtils; 31 32 import org.apache.commons.logging.Log; 33 import org.apache.commons.logging.LogFactory; 34 import org.springframework.web.context.WebApplicationContext; 35 import org.springframework.web.context.support.WebApplicationContextUtils; 36 37 39 46 public class ValueListRetriever extends ConfigurableTag 47 { 48 private static final long serialVersionUID = 8975676126886164801L; 49 50 53 private static final Log LOGGER = LogFactory.getLog(ValueListRetriever.class); 54 55 private String valueListName = null; 56 57 private String focusProperty = null; 58 59 private String focusValue = null; 60 61 64 public int doStartTag() throws JspException 65 { 66 getCellAttributes().getMap().clear(); 67 return super.doStartTag(); 68 } 69 70 73 public int doEndTag() throws JspException 74 { 75 ValueListSpaceTag rootTag = (ValueListSpaceTag) JspUtils.getParent(this, ValueListSpaceTag.class); 76 77 ValueListInfo info = ValueListRequestUtil.buildValueListInfo((HttpServletRequest ) pageContext.getRequest(), rootTag.getTableInfo() 78 .getId()); 79 info.getFilters().putAll(getCellAttributes().getMap()); 80 81 WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(pageContext.getServletContext()); 82 83 if (context == null) 84 { 85 final String message = "Cannot locate the spring WebApplicationContext. Is it configured in your web.xml?"; 86 LOGGER.error(message); 87 throw new JspException (message); 88 } 89 90 ValueListHandler vlh = (ValueListHandler) context.getBean(ValueListHandler.DEFAULT_SERVICE_NAME, ValueListHandler.class); 91 if (vlh == null) 92 { 93 final String message = "Cannot locate the ValueListHanlder in the WebApplicationContext, under the name: \"" 94 + ValueListHandler.DEFAULT_SERVICE_NAME + "\""; 95 LOGGER.error(message); 96 throw new JspException (message); 97 } 98 99 info.setFocusValue(focusValue); 100 info.setFocusProperty(focusProperty); 101 102 if (LOGGER.isDebugEnabled()) 103 { 104 LOGGER.debug("Focus settings was setted up. Focus property '" + focusProperty + "', focus value '" + focusValue + "'"); 105 } 106 107 ValueList list = vlh.getValueList(valueListName, info); 108 pageContext.getRequest().setAttribute(rootTag.getTableInfo().getName(), list); 109 rootTag.setValueList(list); 110 111 if (LOGGER.isDebugEnabled()) 112 { 113 LOGGER.debug("ValueList was retrieved from adapter inside of the jsp."); 114 } 115 116 release(); 117 118 return EVAL_PAGE; 119 } 120 121 125 public void setName(String valueListName) 126 { 127 this.valueListName = valueListName; 128 } 129 130 133 public String getName() 134 { 135 return valueListName; 136 } 137 138 143 public void setFocusProperty(String focusProperty) 144 { 145 this.focusProperty = focusProperty; 146 } 147 148 153 public void setFocusValue(String focusValue) 154 { 155 this.focusValue = focusValue; 156 } 157 158 private void reset() 159 { 160 this.focusProperty = null; 161 this.focusValue = null; 162 this.valueListName = null; 163 } 164 165 173 public void release() 174 { 175 super.release(); 176 reset(); 177 } 178 } | Popular Tags |