1 15 package fr.improve.struts.taglib.layout.expert; 16 17 import java.util.ArrayList ; 18 import java.util.List ; 19 20 import javax.servlet.jsp.JspException ; 21 22 import org.apache.struts.taglib.html.BaseHandlerTag; 23 24 import fr.improve.struts.taglib.layout.field.TextareaFieldTag; 25 import fr.improve.struts.taglib.layout.util.LayoutUtils; 26 import fr.improve.struts.taglib.layout.util.TagUtils; 27 32 public class ExpertTag extends TextareaFieldTag { 33 34 public static final String LOADED = "fr.improve.struts.taglib.layout.expert.ExpertTag.LOADED"; 35 36 public static final int DEFAULT_SUGGESTCOUNT = 10; 37 public static final int DEFAULT_MINWORDLENGTH = 1; 38 39 protected List id = null; 40 protected int minWordLength; 41 protected int suggestCount; 42 43 47 public void doReferencer(String layoutId) { 48 (this.id).add(layoutId); 49 } 50 51 54 protected boolean doBeforeValue() throws JspException { 55 super.doBeforeValue(); 56 this.id = new ArrayList (); 57 this.suggestCount = DEFAULT_SUGGESTCOUNT; 58 this.minWordLength = DEFAULT_MINWORDLENGTH; 59 loadScript(); 60 return true; 61 } 62 63 66 protected void loadScript() throws JspException { 67 if (pageContext.getRequest().getAttribute(LOADED)==null) { 68 TagUtils.write(pageContext, "<script SRC=\""); 69 TagUtils.write(pageContext, LayoutUtils.getSkin(pageContext.getSession()).getConfigDirectory(pageContext.getRequest())); 70 TagUtils.write(pageContext, "/expert.js\"></script>"); 71 pageContext.getRequest().setAttribute(LOADED, ""); 72 } 73 } 74 75 78 public int doEndLayoutTag() throws JspException { 79 StringBuffer buffer = new StringBuffer (); 80 buffer.append("<script language=\"JavaScript\">var arrayId = new Array("); 81 for(int i=0; i<(this.id).size(); i++) { 82 if(i==0) 83 buffer.append("'"+id.get(i)+"'"); 84 else 85 buffer.append(",'"+id.get(i)+"'"); 86 } 87 buffer.append(");StrutsLayoutExpert.init(arrayId);</script>"); 88 buffer.append("<br/><div id=\"expertSuggestSuggestionList\" class=\"suggestionList\"></div>"); 89 buffer.append("<input type=\"hidden\" id=\"expertSuggestSuggestionList_selectedFieldText" + "\" value=\"0\">"); 90 buffer.append("<input type=\"hidden\" id=\"expertSuggestSuggestionList_selectedSuggestionIndex" + "\" value=\"-1\">"); 91 buffer.append("<input type=\"hidden\" id=\"expertSuggestSuggestionList_typedWord" + "\" value=\"\">"); 92 TagUtils.write(pageContext, buffer.toString()); 93 return super.doEndLayoutTag(); 94 } 95 96 99 protected void copyProperties(BaseHandlerTag in_dest) throws JspException { 100 super.copyProperties(in_dest); 101 if(getAccesskey()==null || getAccesskey().length()==0) { 102 fieldTag.setAccesskey("E"); 103 } 104 fieldTag.setOnkeydown((onkeydown != null ? onkeydown : "") + 105 ";StrutsLayoutExpert.computeKeyDown(this, StrutsLayoutExpert.getKey(event.keyCode, event.which));"); 106 fieldTag.setOnkeyup((onkeyup != null ? onkeyup : "") + 107 ";StrutsLayoutExpert.expertUpdate(this.value,false);" + 108 "StrutsLayoutExpert.computeKeyUp(this, StrutsLayoutExpert.getKey(event.keyCode, event.which), '" + 109 this.suggestCount + "', '" + this.minWordLength + "');"); 110 fieldTag.setOnkeypress((onkeypress != null ? onkeypress : "") + 111 ";return StrutsLayoutExpert.computeKeyPress(this, StrutsLayoutExpert.getKey(event.keyCode, event.which));"); 112 } 113 } 114 | Popular Tags |