Author: musachy Date: Sat Feb 17 08:36:08 2007 New Revision: 508777 URL: http://svn.apache.org/viewvc?view=rev&rev=508777 Log: WW-1633 Add "keyName" attribute to autocompleter (defaults to "${name}Key")
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Autocompleter.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AutocompleterTag.java struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js struts/struts2/trunk/core/src/main/resources/template/ajax/autocompleter.ftl struts/struts2/trunk/core/src/main/resources/template/simple/autocompleter.ftl struts/struts2/trunk/core/src/site/resources/tags/autocompleter.html struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/AutocompleterTest.java struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Autocompleter-1.txt struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Autocompleter-2.txt Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Autocompleter.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Autocompleter.java?view=diff&rev=508777&r1=508776&r2=508777 ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Autocompleter.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Autocompleter.java Sat Feb 17 08:36:08 2007 @@ -72,6 +72,9 @@ * 'loadMinimumCount' minimum number of characters that will force the content to be loaded<p/> * 'showDownError' show or hide the down arrow button * 'searchType' how the search must be performed, options are: "startstring", "startword" and "substring"<p/> + * 'keyName' name of the field to which the selected key will be assigned<p/> + * 'iconPath' path of icon used for the dropdown + * 'templateCssPath' path to css file used to customize Dojo's widget * 'notifyTopics' comma separated list of topics names, that will be published. Three parameters are passed:<p/> * <ul> * <li>data: selected value when type='valuechanged'</li> @@ -103,6 +106,7 @@ protected String showDownArrow; protected String templateCssPath; protected String iconPath; + protected String keyName; public Autocompleter(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { @@ -165,11 +169,15 @@ addParameter("templateCssPath", findString(templateCssPath)); if(iconPath != null) addParameter("iconPath", findString(iconPath)); - //get the key value - if(name != null) { - String keyNameExpr = "%{" + name + "Key}"; - addParameter("key", findString(keyNameExpr)); + if(keyName != null) + addParameter("keyName", findString(keyName)); + else { + keyName = name + "Key"; + addParameter("keyName", findString(keyName)); } + + String keyNameExpr = "%{" + keyName + "}"; + addParameter("key", findString(keyNameExpr)); } protected Object findListValue() { @@ -271,5 +279,10 @@ @StrutsTagAttribute(description="Path to icon used for the dropdown") public void setIconPath(String iconPath) { this.iconPath = iconPath; + } + + @StrutsTagAttribute(description="Name of the field to which the selected key will be assigned") + public void setKeyName(String keyName) { + this.keyName = keyName; } } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AutocompleterTag.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AutocompleterTag.java?view=diff&rev=508777&r1=508776&r2=508777 ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AutocompleterTag.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/views/jsp/ui/AutocompleterTag.java Sat Feb 17 08:36:08 2007 @@ -52,7 +52,8 @@ protected String showDownArrow; protected String templateCssPath; protected String iconPath; - + protected String keyName; + public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { return new Autocompleter(stack, req, res); } @@ -79,6 +80,7 @@ autocompleter.setShowDownArrow(showDownArrow); autocompleter.setTemplateCssPath(templateCssPath); autocompleter.setIconPath(iconPath); + autocompleter.setKeyName(keyName); } public void setAutoComplete(String autoComplete) { @@ -155,5 +157,9 @@ public void setIconPath(String iconPath) { this.iconPath = iconPath; + } + + public void setKeyName(String keyName) { + this.keyName = keyName; } } Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js?view=diff&rev=508777&r1=508776&r2=508777 ============================================================================== --- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js (original) +++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/static/dojo/struts/widget/ComboBox.js Sat Feb 17 08:36:08 2007 @@ -205,6 +205,7 @@ //dojo has "stringstart" which is invalid searchType: "STARTSTRING", + keyName: "", templateCssPath: dojo.uri.dojoUri("struts/ComboBox.css"), //from Dojo's ComboBox showResultList: function() { @@ -315,7 +316,7 @@ } //better name - this.comboBoxSelectionValue.name = this.name + "Key"; + this.comboBoxSelectionValue.name = dojo.string.isBlank(this.keyName) ? this.name + "Key" : this.keyName; //init values this.comboBoxValue.value = this.initialValue; Modified: struts/struts2/trunk/core/src/main/resources/template/ajax/autocompleter.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/template/ajax/autocompleter.ftl?view=diff&rev=508777&r1=508776&r2=508777 ============================================================================== --- struts/struts2/trunk/core/src/main/resources/template/ajax/autocompleter.ftl (original) +++ struts/struts2/trunk/core/src/main/resources/template/ajax/autocompleter.ftl Sat Feb 17 08:36:08 2007 @@ -38,6 +38,9 @@ <#if parameters.get("size")?exists> size="${parameters.get("size")?html}"<#rt/> </#if> +<#if parameters.keyName?if_exists != ""> + keyName="${parameters.keyName?html}"<#rt/> +</#if> <#if parameters.maxlength?exists> maxlength="${parameters.maxlength?string?html}"<#rt/> </#if> Modified: struts/struts2/trunk/core/src/main/resources/template/simple/autocompleter.ftl URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/template/simple/autocompleter.ftl?view=diff&rev=508777&r1=508776&r2=508777 ============================================================================== --- struts/struts2/trunk/core/src/main/resources/template/simple/autocompleter.ftl (original) +++ struts/struts2/trunk/core/src/main/resources/template/simple/autocompleter.ftl Sat Feb 17 08:36:08 2007 @@ -35,6 +35,9 @@ <#if parameters.name?if_exists != ""> name="${parameters.name?html}"<#rt/> </#if> +<#if parameters.keyName?if_exists != ""> + keyName="${parameters.keyName?html}"<#rt/> +</#if> <#if parameters.get("size")?exists> size="${parameters.get("size")?html}"<#rt/> </#if> Modified: struts/struts2/trunk/core/src/site/resources/tags/autocompleter.html URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/site/resources/tags/autocompleter.html?view=diff&rev=508777&r1=508776&r2=508777 ============================================================================== --- struts/struts2/trunk/core/src/site/resources/tags/autocompleter.html (original) +++ struts/struts2/trunk/core/src/site/resources/tags/autocompleter.html Sat Feb 17 08:36:08 2007 @@ -180,6 +180,14 @@ <td align="left" valign="top">Set the key (name, value, label) for this particular component</td> </tr> <tr> + <td align="left" valign="top">keyName</td> + <td align="left" valign="top">false</td> + <td align="left" valign="top"></td> + <td align="left" valign="top">true</td> + <td align="left" valign="top">String</td> + <td align="left" valign="top">Name of the field to which the selected key will be assigned</td> + </tr> + <tr> <td align="left" valign="top">label</td> <td align="left" valign="top">false</td> <td align="left" valign="top"></td> Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/AutocompleterTest.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/AutocompleterTest.java?view=diff&rev=508777&r1=508776&r2=508777 ============================================================================== --- struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/AutocompleterTest.java (original) +++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/ui/AutocompleterTest.java Sat Feb 17 08:36:08 2007 @@ -43,6 +43,7 @@ tag.setName("f"); tag.setValue("g"); tag.setIndicator("h"); + tag.setKeyName("i"); tag.setLoadOnTextChange("true"); tag.setLoadMinimumCount("3"); tag.setShowDownArrow("false"); Modified: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Autocompleter-1.txt URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Autocompleter-1.txt?view=diff&rev=508777&r1=508776&r2=508777 ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Autocompleter-1.txt (original) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Autocompleter-1.txt Sat Feb 17 08:36:08 2007 @@ -9,6 +9,7 @@ dropdownWidth="10" dropdownHeight="10" name="f" + keyName="i" initialValue="g" indicator="h" loadOnType="true" Modified: struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Autocompleter-2.txt URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Autocompleter-2.txt?view=diff&rev=508777&r1=508776&r2=508777 ============================================================================== --- struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Autocompleter-2.txt (original) +++ struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Autocompleter-2.txt Sat Feb 17 08:36:08 2007 @@ -9,6 +9,7 @@ dropdownWidth="10" dropdownHeight="10" name="f" + keyName="fKey" buttonSrc="i" templateCssPath="j" >