1 14 package org.compiere.wstore; 15 16 import java.util.*; 17 import java.sql.*; 18 import javax.servlet.*; 19 import javax.servlet.http.*; 20 import javax.servlet.jsp.*; 21 import javax.servlet.jsp.tagext.*; 22 23 import org.apache.ecs.*; 24 import org.apache.ecs.xhtml.*; 25 import org.apache.log4j.Logger; 26 import org.apache.taglibs.standard.tag.el.core.*; 27 import org.compiere.model.*; 28 29 import org.compiere.util.Msg; 30 31 40 public class LocationTag extends TagSupport 41 { 42 43 private Logger log = Logger.getLogger(getClass()); 44 45 private String m_countryID_el; 46 private String m_regionID_el; 47 private String m_regionName_el; 48 private String m_city_el; 49 private String m_postal_el; 50 51 private MCountry m_country; 52 53 private static final String C_MANDATORY = "Cmandatory"; 55 private static final String C_ERROR = "Cerror"; 56 57 61 public void setCountryID (String info_el) 62 { 63 m_countryID_el = info_el; 64 } 66 70 public void setRegionID (String info_el) 71 { 72 m_regionID_el = info_el; 73 } 75 79 public void setRegionName (String info_el) 80 { 81 m_regionName_el = info_el; 82 } 84 88 public void setCity (String info_el) 89 { 90 m_city_el = info_el; 91 } 93 97 public void setPostal (String info_el) 98 { 99 m_postal_el = info_el; 100 } 102 107 public int doStartTag() throws JspException 108 { 109 Properties ctx = JSPEnv.getCtx((HttpServletRequest)pageContext.getRequest()); 110 111 int C_Country_ID = 0; 113 try 114 { 115 String info = (String )ExpressionUtil.evalNotNull ("location", "countryID", 116 m_countryID_el, String .class, this, pageContext); 117 if (info != null && info.length () != 0) 118 C_Country_ID = Integer.parseInt (info); 119 } 120 catch (Exception e) 121 { 122 log.error ("Country - " + e); 123 } 124 MLocation loc = new MLocation (ctx, 0); 125 if (C_Country_ID == 0) 126 C_Country_ID = loc.getC_Country_ID(); String name = "C_Country_ID"; 129 select sel = new select (name, getCountries (loc, C_Country_ID)); 130 sel.setID("ID_" + name); 131 sel.setClass(C_MANDATORY); 132 tr tr_country = createRow (name, Msg.translate(ctx, name), sel); 133 134 int C_Region_ID = 0; 136 try 137 { 138 String info = (String )ExpressionUtil.evalNotNull ("location", "regionID", 139 m_regionID_el, String .class, this, pageContext); 140 if (info != null && info.length () != 0) 141 C_Region_ID = Integer.parseInt (info); 142 } 143 catch (Exception e) 144 { 145 log.error("RegionID - " + e); 146 } 147 if (C_Region_ID == 0) 148 C_Region_ID = loc.getC_Region_ID(); name = "C_Region_ID"; 151 tr tr_region = null; 152 String regionName = (String )ExpressionUtil.evalNotNull ("location", "regionName", 153 m_regionName_el, String .class, this, pageContext); 154 input field = new input (input.text, "RegionName", regionName); 155 field.setSize(40).setMaxlength(60).setID("ID_RegionName"); 156 if (m_country != null && m_country.isHasRegion()) 157 { 158 sel = new select (name, getRegions (loc, C_Country_ID, C_Region_ID)); 159 sel.setID("ID_" + name); 160 tr_region = createRow (name, m_country.getRegionName(), sel, field); } 162 else 163 tr_region = createRow (name, Msg.translate(ctx, name), field); 165 name = "City"; 167 String city = (String )ExpressionUtil.evalNotNull ("location", "city", 168 m_city_el, String .class, this, pageContext); 169 field = new input (input.text, name, city); 170 field.setSize(40).setMaxlength(60).setID("ID_" + name); 171 field.setClass(C_MANDATORY); 172 tr tr_city = createRow (name, Msg.translate(ctx, name), field); 173 name = "Postal"; 175 String postal = (String )ExpressionUtil.evalNotNull ("location", "postal", 176 m_postal_el, String .class, this, pageContext); 177 field = new input (input.text, name, postal); 178 field.setSize(10).setMaxlength(10).setID("ID_" + name); 179 field.setClass(C_MANDATORY); 180 tr tr_postal = createRow (name, Msg.translate(ctx, name), field); 181 182 log.debug ("C_Country_ID=" + C_Country_ID + ", C_Region_ID=" + C_Region_ID 183 + ", RegionName=" + regionName + ", City=" + city + ", Postal=" + postal); 184 185 HtmlCode html = new HtmlCode(); 187 if (m_country != null) 188 { 189 html.addElement(tr_city); 191 html.addElement(tr_postal); 192 html.addElement(tr_region); 193 html.addElement(tr_country); 194 } 195 else 196 { 197 html.addElement(tr_city); 198 html.addElement(tr_postal); 199 html.addElement(tr_region); 200 html.addElement(tr_country); 201 } 202 203 JspWriter out = pageContext.getOut(); 204 html.output(out); 205 return (SKIP_BODY); 207 } 209 214 public int doEndTag() throws JspException 215 { 216 return EVAL_PAGE; 217 } 219 227 private option[] getCountries (MLocation loc, int C_Country_ID) 228 { 229 MCountry[] countries = MCountry.getCountries(loc.getCtx()); 230 option[] options = new option[countries.length]; 231 m_country = null; 232 for (int i = 0; i < countries.length; i++) 234 { 235 options[i] = new option (String.valueOf(countries[i].getC_Country_ID())); 236 options[i].addElement(countries[i].getName()); 237 if (countries[i].getC_Country_ID() == C_Country_ID) 238 { 239 m_country = countries[i]; 240 options[i].setSelected (true); 241 } 242 } 243 return options; 245 } 247 254 private option[] getRegions (MLocation loc, int C_Country_ID, int C_Region_ID) 255 { 256 MRegion[] regions = MRegion.getRegions(loc.getCtx(), C_Country_ID); 257 option[] options = new option[regions.length+1]; 258 options[0] = new option ("0"); 260 options[0].addElement(" "); 261 for (int i = 0; i < regions.length; i++) 263 { 264 options[i+1] = new option (String.valueOf(regions[i].getC_Region_ID())); 265 options[i+1].addElement(regions[i].getName()); 266 if (regions[i].getC_Region_ID() == C_Region_ID) 267 options[i+1].setSelected(true); 268 } 269 return options; 270 } 272 273 280 private tr createRow (String name, String labelText, ConcreteElement data) 281 { 282 tr tr = new tr(); 283 284 td td = new td (); 286 tr.addElement(td); 287 td.setAlign("right"); 288 label label = new label(); 289 td.addElement(label); 290 label.setID("ID_" + name); 291 label.setFor(name); 292 label.addElement(labelText); 293 294 td = new td (); 296 tr.addElement(td); 297 td.setAlign("left"); 298 td.addElement(data); 299 return tr; 301 } 303 311 private tr createRow (String name, String labelText, ConcreteElement data, ConcreteElement data2) 312 { 313 tr tr = new tr(); 314 315 td td = new td (); 317 tr.addElement(td); 318 td.setAlign("right"); 319 label label = new label(); 320 td.addElement(label); 321 label.setID("ID_" + name); 322 label.setFor(name); 323 label.addElement(labelText); 324 325 td = new td (); 327 tr.addElement(td); 328 td.setAlign("left"); 329 td.addElement(data); 330 td.addElement(" - "); 331 td.addElement(data2); 332 return tr; 334 } 336 } | Popular Tags |