1 package fr.improve.struts.taglib.layout.field.ajax.select; 2 3 import javax.servlet.jsp.JspException ; 4 5 import fr.improve.struts.taglib.layout.field.SelectTag; 6 import fr.improve.struts.taglib.layout.util.LayoutUtils; 7 import fr.improve.struts.taglib.layout.util.TagUtils; 8 9 14 public class SelectDependentTag extends SelectTag { 15 16 19 protected String targetName; 20 23 protected String fillDropDownAction; 24 25 28 protected String doubleCombo; 29 30 public static final String LOADED = "fr.improve.struts.taglib.layout.field.ajax.select.SelectDependentTag.LOADED"; 31 32 35 protected boolean doBeforeValue() throws JspException { 36 37 if (doubleCombo != null && doubleCombo.equals("true")) { 38 loadScript(); 39 } 40 return super.doBeforeValue(); 41 } 42 43 46 protected void loadScript() throws JspException { 47 48 if (pageContext.getRequest().getAttribute(LOADED)==null) { 49 TagUtils.write(pageContext, "<script SRC=\""); 50 TagUtils.write(pageContext, LayoutUtils.getSkin(pageContext.getSession()).getConfigDirectory(pageContext.getRequest())); 51 TagUtils.write(pageContext, "/selectDependent.js\"></script>"); 52 pageContext.getRequest().setAttribute(LOADED, ""); 53 } 54 } 55 56 59 public String getFillDropDownAction() { 60 return fillDropDownAction; 61 } 62 63 66 public void setFillDropDownAction(String fillDropDownAction) { 67 this.fillDropDownAction = fillDropDownAction; 68 } 69 70 71 74 public String getTargetName() { 75 return targetName; 76 } 77 78 81 public void setTargetName(String targetName) { 82 this.targetName = targetName; 83 } 84 85 88 public String getDoubleCombo() { 89 return doubleCombo; 90 } 91 92 93 96 public void setDoubleCombo(String doubleCombo) { 97 this.doubleCombo = doubleCombo; 98 } 99 100 103 protected void initDynamicValues() { 104 super.initDynamicValues(); 105 106 String url = null; 107 108 try { 109 url = LayoutUtils.computeURL(pageContext, null, null, null, 110 this.getFillDropDownAction(), null, null, 111 null, false, ""); 112 } 113 catch (JspException e) { 114 TagUtils.saveException(pageContext, e); 115 throw new RuntimeException (e.getMessage()); 116 } 117 118 if (doubleCombo != null && doubleCombo.equals("true")) { 119 onchange =(onchange != null ? (onchange +";") : "") 120 + "updateDropDownList(this,'"+ getName() +"', '" 121 + getTargetName() + "', '" + url + "' )"; 122 } 123 } 124 125 128 protected void reset() { 129 super.reset(); 130 onchange = null; 131 onkeypress = null; 132 targetName = null; 133 fillDropDownAction = null; 134 doubleCombo = null; 135 } 136 137 138 } 139 | Popular Tags |