You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2010/01/01 23:05:56 UTC
svn commit: r895083 - in /myfaces/tobago/trunk:
core/src/main/java/org/apache/myfaces/tobago/model/
example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/
example/demo/src/main/java/org/apache/myfaces/tobago/example/reference/
example/demo/...
Author: weber
Date: Fri Jan 1 22:05:55 2010
New Revision: 895083
URL: http://svn.apache.org/viewvc?rev=895083&view=rev
Log:
(TOBAGO-842) Multi field update from tc:in autoSuggest
<https://issues.apache.org/jira/browse/TOBAGO-842>
(TOBAGO-843) Make tc:in autoSuggest independent from the used ajax library and improve the behavior
<https://issues.apache.org/jira/browse/TOBAGO-843>
Added:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestExtensionItem.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestItem.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestItems.java
myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/reference/InputSuggestController.java
myfaces/tobago/trunk/example/demo/src/main/webapp/reference/inputSuggest.jsp
myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/style/style.css
Modified:
myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/Navigation.java
myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/faces-config.xml
myfaces/tobago/trunk/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java
myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/inputSuggest.js
myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestExtensionItem.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestExtensionItem.java?rev=895083&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestExtensionItem.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestExtensionItem.java Fri Jan 1 22:05:55 2010
@@ -0,0 +1,22 @@
+package org.apache.myfaces.tobago.model;
+
+public class AutoSuggestExtensionItem {
+ private String id;
+ private String value;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestItem.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestItem.java?rev=895083&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestItem.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestItem.java Fri Jan 1 22:05:55 2010
@@ -0,0 +1,36 @@
+package org.apache.myfaces.tobago.model;
+
+import java.util.List;
+
+public class AutoSuggestItem extends AutoSuggestExtensionItem {
+
+ private String label;
+
+ private String nextFocusId;
+
+ private List<AutoSuggestExtensionItem> extensionItems;
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getNextFocusId() {
+ return nextFocusId;
+ }
+
+ public void setNextFocusId(String nextFocusId) {
+ this.nextFocusId = nextFocusId;
+ }
+
+ public List<AutoSuggestExtensionItem> getExtensionItems() {
+ return extensionItems;
+ }
+
+ public void setExtensionItems(List<AutoSuggestExtensionItem> extensionItems) {
+ this.extensionItems = extensionItems;
+ }
+}
Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestItems.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestItems.java?rev=895083&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestItems.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/AutoSuggestItems.java Fri Jan 1 22:05:55 2010
@@ -0,0 +1,36 @@
+package org.apache.myfaces.tobago.model;
+
+import java.util.List;
+
+public class AutoSuggestItems {
+
+ private List<AutoSuggestItem> items;
+
+ private String nextFocusId;
+
+ private int maxSuggestedCount = 25;
+
+ public List<AutoSuggestItem> getItems() {
+ return items;
+ }
+
+ public void setItems(List<AutoSuggestItem> items) {
+ this.items = items;
+ }
+
+ public String getNextFocusId() {
+ return nextFocusId;
+ }
+
+ public void setNextFocusId(String nextFocusId) {
+ this.nextFocusId = nextFocusId;
+ }
+
+ public int getMaxSuggestedCount() {
+ return maxSuggestedCount;
+ }
+
+ public void setMaxSuggestedCount(int maxSuggestedCount) {
+ this.maxSuggestedCount = maxSuggestedCount;
+ }
+}
Modified: myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/Navigation.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/Navigation.java?rev=895083&r1=895082&r2=895083&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/Navigation.java (original)
+++ myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/Navigation.java Fri Jan 1 22:05:55 2010
@@ -76,6 +76,7 @@
reference.add(new DefaultMutableTreeNode(new Node("reference_command", "reference/command")));
reference.add(new DefaultMutableTreeNode(new Node("reference_container", "reference/container")));
reference.add(new DefaultMutableTreeNode(new Node("reference_input", "reference/input")));
+ reference.add(new DefaultMutableTreeNode(new Node("reference_inputSuggest", "reference/inputSuggest")));
reference.add(new DefaultMutableTreeNode(new Node("reference_menu", "reference/menu")));
reference.add(new DefaultMutableTreeNode(new Node("reference_output", "reference/output")));
reference.add(new DefaultMutableTreeNode(new Node("reference_object", "reference/object")));
Added: myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/reference/InputSuggestController.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/reference/InputSuggestController.java?rev=895083&view=auto
==============================================================================
--- myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/reference/InputSuggestController.java (added)
+++ myfaces/tobago/trunk/example/demo/src/main/java/org/apache/myfaces/tobago/example/reference/InputSuggestController.java Fri Jan 1 22:05:55 2010
@@ -0,0 +1,165 @@
+package org.apache.myfaces.tobago.example.reference;
+
+import org.apache.myfaces.tobago.model.AutoSuggestExtensionItem;
+import org.apache.myfaces.tobago.model.AutoSuggestItem;
+import org.apache.myfaces.tobago.model.AutoSuggestItems;
+
+import javax.faces.model.SelectItem;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class InputSuggestController {
+
+ private static final Log LOG = LogFactory.getLog(InputSuggestController.class);
+
+ private String simpleValue;
+ private String zipValue;
+ private String cityValue;
+
+ private List<SelectItem> regionItems;
+
+ private String region;
+
+ private String[][] suggestData = {
+ {"26127 Oldenburg", "26127", "Oldenburg", "Niedersachsen"},
+ {"26203 Wardenburg", "26203", "Wardenburg", "Niedersachsen"},
+ {"26160 Bad Zwischenahn", "26160", "Bad Zwischenahn", "Niedersachsen"},
+ {"26655 Westerstede", "26655", "Westerstede", "Niedersachsen"},
+ {"26919 Brake (Unterweser)", "26919", "Brake", "Niedersachsen"},
+ {"57462 Olpe", "57462", "Olpe", "Nordrhein-Westfalen"},
+ {"23758 Oldenburg (Holstein)", "23758", "Oldenburg", "Schleswig Holstein"},
+ {"99628 Olbersleben", "99628", "Olbersleben", "Tueringen"},
+ {"25860 Olderup", "25860", "Olderup", "Schleswig Holstein"},
+ {"66851 Olenkorb", "66851", "Olenkorb", "Rheinland-Pfalz"}
+ };
+
+
+ public String getSimpleValue() {
+ return simpleValue;
+ }
+
+ public void setSimpleValue(String simpleValue) {
+ this.simpleValue = simpleValue;
+ }
+
+ public String getZipValue() {
+ return zipValue;
+ }
+
+ public void setZipValue(String zipValue) {
+ this.zipValue = zipValue;
+ }
+
+ public String getCityValue() {
+ return cityValue;
+ }
+
+ public void setCityValue(String cityValue) {
+ this.cityValue = cityValue;
+ }
+
+ public List<SelectItem> getRegionItems() {
+ if (regionItems == null) {
+ regionItems = new ArrayList<SelectItem>(17);
+ regionItems.add(new SelectItem("Please select"));
+ regionItems.add(new SelectItem("Baden-Württemberg"));
+ regionItems.add(new SelectItem("Bayern"));
+ regionItems.add(new SelectItem("Berlin"));
+ regionItems.add(new SelectItem("Brandenburg"));
+ regionItems.add(new SelectItem("Bremen"));
+ regionItems.add(new SelectItem("Hamburg"));
+ regionItems.add(new SelectItem("Hessen"));
+ regionItems.add(new SelectItem("Mecklenburg-Vorpommern"));
+ regionItems.add(new SelectItem("Niedersachsen"));
+ regionItems.add(new SelectItem("Nordrhein-Westfalen"));
+ regionItems.add(new SelectItem("Rheinland-Pfalz"));
+ regionItems.add(new SelectItem("Saarland"));
+ regionItems.add(new SelectItem("Sachsen"));
+ regionItems.add(new SelectItem("Sachsen-Anhalt"));
+ regionItems.add(new SelectItem("Schleswig Holstein"));
+ regionItems.add(new SelectItem("Tueringen"));
+ }
+ return regionItems;
+ }
+
+ public String getRegion() {
+ return region;
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+
+ public List<String> getSimpleSuggestItems(String prefix) {
+ LOG.info("createing items for prefix :\"" + prefix + "\"");
+ List<String> li = new ArrayList<String>();
+ li.add(prefix+1);
+ li.add(prefix+2);
+ li.add(prefix+3);
+ li.add(prefix+4);
+ li.add(prefix+5);
+ li.add(prefix+6);
+ return li;
+ }
+
+ public AutoSuggestItems getZipSuggestItems(String prefix) {
+ AutoSuggestItems item = new AutoSuggestItems();
+ item.setItems(getSuggestItems(prefix, true));
+ item.setNextFocusId("page:txarea");
+ return item;
+ }
+
+
+
+ public AutoSuggestItems getCitySuggestItems(String prefix) {
+ AutoSuggestItems item = new AutoSuggestItems();
+ item.setItems(getSuggestItems(prefix, false));
+ item.setNextFocusId("page:txarea");
+ return item;
+ }
+
+ private List<AutoSuggestItem> getSuggestItems(String prefix, boolean zip) {
+ List<AutoSuggestItem> items = new ArrayList<AutoSuggestItem>();
+ for (String[] dataRow : suggestData) {
+ if (zip) {
+ if (dataRow[1].startsWith(prefix)) {
+ AutoSuggestItem item = new AutoSuggestItem();
+ item.setLabel(dataRow[0]);
+ item.setValue(dataRow[1]);
+ List<AutoSuggestExtensionItem> extensionItems = new ArrayList<AutoSuggestExtensionItem>(2);
+ extensionItems.add(createExtensionItem("page:isCity", dataRow[2]));
+ if (dataRow[3] != null) {
+ extensionItems.add(createExtensionItem("page:isCountry", dataRow[3]));
+ }
+ item.setExtensionItems(extensionItems);
+ items.add(item);
+ }
+ } else {
+ if (dataRow[2].toLowerCase().startsWith(prefix.toLowerCase())) {
+ AutoSuggestItem item = new AutoSuggestItem();
+ item.setLabel(dataRow[0]);
+ item.setValue(dataRow[2]);
+ List<AutoSuggestExtensionItem> extensionItems = new ArrayList<AutoSuggestExtensionItem>(2);
+ extensionItems.add(createExtensionItem("page:isZip", dataRow[1]));
+ if (dataRow[3] != null) {
+ extensionItems.add(createExtensionItem("page:isCountry", dataRow[3]));
+ }
+ item.setExtensionItems(extensionItems);
+ items.add(item);
+ }
+ }
+ }
+
+ return items;
+ }
+
+ private AutoSuggestExtensionItem createExtensionItem(String id, String value) {
+ AutoSuggestExtensionItem extItem = new AutoSuggestExtensionItem();
+ extItem.setId(id);
+ extItem.setValue(value);
+ return extItem;
+ }
+}
Modified: myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/faces-config.xml?rev=895083&r1=895082&r2=895083&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/faces-config.xml Fri Jan 1 22:05:55 2010
@@ -340,6 +340,12 @@
</managed-bean>
<managed-bean>
+ <managed-bean-name>inputSuggestController</managed-bean-name>
+ <managed-bean-class>org.apache.myfaces.tobago.example.reference.InputSuggestController</managed-bean-class>
+ <managed-bean-scope>session</managed-bean-scope>
+ </managed-bean>
+
+ <managed-bean>
<managed-bean-name>upload</managed-bean-name>
<managed-bean-class>org.apache.myfaces.tobago.example.reference.Upload</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
@@ -363,6 +369,10 @@
<to-view-id>/reference/input.jsp</to-view-id>
</navigation-case>
<navigation-case>
+ <from-outcome>reference/inputSuggest</from-outcome>
+ <to-view-id>/reference/inputSuggest.jsp</to-view-id>
+ </navigation-case>
+ <navigation-case>
<from-outcome>reference/menu</from-outcome>
<to-view-id>/reference/menu.jsp</to-view-id>
</navigation-case>
Added: myfaces/tobago/trunk/example/demo/src/main/webapp/reference/inputSuggest.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/demo/src/main/webapp/reference/inputSuggest.jsp?rev=895083&view=auto
==============================================================================
--- myfaces/tobago/trunk/example/demo/src/main/webapp/reference/inputSuggest.jsp (added)
+++ myfaces/tobago/trunk/example/demo/src/main/webapp/reference/inputSuggest.jsp Fri Jan 1 22:05:55 2010
@@ -0,0 +1,85 @@
+<%--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+--%>
+<%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc" %>
+<%@ taglib uri="http://myfaces.apache.org/tobago/extension" prefix="tx" %>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
+<%@ taglib tagdir="/WEB-INF/tags/layout" prefix="layout" %>
+
+<layout:overview>
+ <jsp:body>
+ <tc:box label="InputSuggest">
+ <f:facet name="layout">
+ <tc:gridLayout rows="fixed;fixed;fixed;150px;fixed;1*"/>
+ </f:facet>
+
+ <tc:separator label="Simple"/>
+
+ <tc:panel >
+ <f:facet name="layout">
+ <tc:gridLayout columns="350px;1*"/>
+ </f:facet>
+
+ <tx:in value="#{inputSuggestController.simpleValue}"
+ label="Suggest test:"
+ tip="test"
+ suggestMethod="#{inputSuggestController.getSimpleSuggestItems}"/>
+
+ <tc:cell/>
+
+ </tc:panel>
+
+ <tc:separator label="Multi field suggest"/>
+
+ <tc:panel >
+ <f:facet name="layout">
+ <tc:gridLayout rows="fixed;fixed;1*" columns="350px;1*"/>
+ </f:facet>
+
+ <tc:panel>
+ <f:facet name="layout">
+ <tc:gridLayout columns="200px;1*"/>
+ </f:facet>
+ <tx:in id="isZip" value="#{inputSuggestController.zipValue}"
+ label="ZIP/City:"
+ tip="test"
+ suggestMethod="#{inputSuggestController.getZipSuggestItems}"/>
+ <tc:in id="isCity" value="#{inputSuggestController.cityValue}"
+ tip="test"
+ suggestMethod="#{inputSuggestController.getCitySuggestItems}"/>
+ </tc:panel>
+
+ <tc:cell spanY="3"/>
+
+ <tx:selectOneChoice label="Country:"
+ id="isCountry"
+ value="#{inputSuggestController.region}">
+ <f:selectItems value="#{inputSuggestController.regionItems}"/>
+ </tx:selectOneChoice>
+
+ <tc:textarea id="txarea"/>
+
+
+ </tc:panel>
+
+
+ <tc:separator/>
+
+ <tc:cell/>
+
+ </tc:box>
+ </jsp:body>
+</layout:overview>
\ No newline at end of file
Modified: myfaces/tobago/trunk/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml?rev=895083&r1=895082&r2=895083&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml (original)
+++ myfaces/tobago/trunk/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml Fri Jan 1 22:05:55 2010
@@ -61,6 +61,7 @@
<entry key="reference_command">Command</entry>
<entry key="reference_container">Container</entry>
<entry key="reference_input">Input</entry>
+ <entry key="reference_inputSuggest">Input suggest</entry>
<entry key="reference_menu">Menu</entry>
<entry key="reference_output">Output</entry>
<entry key="reference_object">Object</entry>
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java?rev=895083&r1=895082&r2=895083&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/InRenderer.java Fri Jan 1 22:05:55 2010
@@ -26,6 +26,9 @@
import org.apache.myfaces.tobago.component.UIInput;
import org.apache.myfaces.tobago.component.UIInputBase;
import org.apache.myfaces.tobago.context.TobagoFacesContext;
+import org.apache.myfaces.tobago.model.AutoSuggestExtensionItem;
+import org.apache.myfaces.tobago.model.AutoSuggestItem;
+import org.apache.myfaces.tobago.model.AutoSuggestItems;
import org.apache.myfaces.tobago.renderkit.InputRendererBase;
import org.apache.myfaces.tobago.renderkit.css.Style;
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
@@ -42,6 +45,7 @@
import javax.faces.validator.LengthValidator;
import javax.faces.validator.Validator;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@@ -157,18 +161,16 @@
// input suggest
if (renderAjaxSuggest) {
-
-
final String[] cmds = {
"new Tobago.AutocompleterAjax(",
" '" + id + "',",
- " '" + required + "',",
+ " " + required + ",",
" '" + StyleClasses.PREFIX + rendererName + "',",
" { });"
};
- HtmlRendererUtils.writeStyleLoader(facesContext, STYLES);
+// HtmlRendererUtils.writeStyleLoader(facesContext, STYLES);
HtmlRendererUtils.writeScriptLoader(facesContext, SCRIPTS, cmds);
}
@@ -206,28 +208,88 @@
}
TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(context);
- int maxSuggestedCount = 25; //input.getMaxSuggestedItems()!=null
+// int maxSuggestedCount = 25; //input.getMaxSuggestedItems()!=null
// ? input.getMaxSuggestedItems().intValue()
// : DEFAULT_MAX_SUGGESTED_ITEMS;
- List suggesteds
- = (List) mb.invoke(context, new Object[]{(String) input.getSubmittedValue()});
+ Object object = mb.invoke(context, new Object[]{(String) input.getSubmittedValue()});
+
+ AutoSuggestItems items = null;
+ if (object instanceof AutoSuggestItems) {
+ items = (AutoSuggestItems) object;
+ } else {
+ items = createAutoSuggestItems(object);
+ }
+ List<AutoSuggestItem> suggesteds = items.getItems();
+
+
writer.startJavascript();
writer.write("return {items: [");
- int suggestedCount = 0;
- for (Iterator i = suggesteds.iterator(); i.hasNext(); suggestedCount++) {
- if (suggestedCount > maxSuggestedCount) {
- break;
- }
- if (suggestedCount > 0) {
+ for (int i = 0; i < suggesteds.size() && i < items.getMaxSuggestedCount(); i++) {
+ AutoSuggestItem suggestItem = suggesteds.get(i);
+ if (i > 0) {
writer.write(", ");
}
writer.write("{label: \"");
- writer.write(AjaxUtils.encodeJavascriptString(i.next().toString()));
- writer.write("\"}");
+ writer.write(AjaxUtils.encodeJavascriptString(suggestItem.getLabel()));
+ writer.write("\", value: \"");
+ writer.write(AjaxUtils.encodeJavascriptString(suggestItem.getValue()));
+ writer.write("\"");
+ if (suggestItem.getExtensionItems() != null) {
+ writer.write(", values: [");
+ for (int j = 0; j < suggestItem.getExtensionItems().size(); j++) {
+ AutoSuggestExtensionItem item = suggestItem.getExtensionItems().get(j);
+ if (j > 0) {
+ writer.write(", ");
+ }
+ writer.write("{id: \"");
+ writer.write(item.getId());
+ writer.write("\", value: \"");
+ writer.write(AjaxUtils.encodeJavascriptString(item.getValue()));
+ writer.write("\"}");
+ }
+ writer.write("]");
+ }
+ if (suggestItem.getNextFocusId() != null) {
+ writer.write(", nextfocusId: \"");
+ writer.write(AjaxUtils.encodeJavascriptString(suggestItem.getNextFocusId()));
+ writer.write("\"");
+ }
+
+ writer.write("}");
+
+ }
+
+ writer.write("]");
+ if (items.getNextFocusId() != null) {
+ writer.write(", nextFocusId: \"");
+ writer.write(items.getNextFocusId());
+ writer.write("\"");
}
- writer.write("]};");
+ writer.write("};");
writer.endJavascript();
}
+
+ private AutoSuggestItems createAutoSuggestItems(Object object) {
+ AutoSuggestItems autoSuggestItems = new AutoSuggestItems();
+ if (object instanceof List && !((List) object).isEmpty()) {
+ if (((List) object).get(0) instanceof AutoSuggestItem) {
+ //noinspection unchecked
+ autoSuggestItems.setItems((List<AutoSuggestItem>) object);
+ } else if (((List) object).get(0) instanceof String) {
+ List<AutoSuggestItem> items = new ArrayList<AutoSuggestItem>(((List) object).size());
+ for (int i = 0; i < ((List) object).size(); i++) {
+ AutoSuggestItem item = new AutoSuggestItem();
+ item.setLabel((String) ((List) object).get(i));
+ item.setValue((String) ((List) object).get(i));
+ items.add(item);
+ }
+ autoSuggestItems.setItems(items);
+ } else {
+ throw new IllegalArgumentException("Cant create AutoSuggestItems from " + object);
+ }
+ }
+ return autoSuggestItems;
+ }
}
Modified: myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/inputSuggest.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/inputSuggest.js?rev=895083&r1=895082&r2=895083&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/inputSuggest.js (original)
+++ myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/inputSuggest.js Fri Jan 1 22:05:55 2010
@@ -15,112 +15,295 @@
* limitations under the License.
*/
-dojo.require("dojo.data.ItemFileReadStore");
-dojo.require("dijit.form.ComboBox");
-dojo.require("dojo.parser"); // scan page for widgets and instantiate them
Tobago.AutocompleterAjax = function(elementId, required, cssPrefix, options) {
LOG.debug("new Tobago.AutocompleterAjax " + elementId);
this.id = elementId;
this.required = required;
this.cssPrefix = cssPrefix;
- this.options = {};
+ this.setup();
+
+ this.options = {
+ minPrefixLength: 2,
+ eventDelay: 500,
+ createOverlay: false
+ };
+
+ this.requestActive = false;
+ this.rerequest = false;
+
+ this.currentTimeout = undefined;
this.index = 0;
Tobago.extend(this.options, options);
-
- this.store = new Tobago.AutocompleterAjaxStore(this);
var input = Tobago.element(elementId);
- var className = input.className;
- var width = input.style.width;
- var height = input.style.height.replace(/\D/g, "");
- var left = input.style.left;
- var onTop = input.style.top;
- var combo = new dijit.form.ComboBox({
- name: elementId,
- autocomplete: false,
- store: this.store,
- searchAttr: "label",
- hasDownArrow: false
- }, input);
- var table = Tobago.element("widget_" + elementId);
- combo.staticClass = table.className.replace("dijitTextBox", className);
- table.className = combo.staticClass + " dijitTextBox";
- table.style.width = width;
- table.style.height = (height - 2) + "px";
- table.style.position = "absolute";
- table.style.left = left;
- table.style.top = onTop;
- input = Tobago.element(elementId);
- input.className = className;
- input.style.width = width;
- input.style.height = (height - 2) + "px";
- var vdiv = input.parentNode.nextSibling.firstChild;
- vdiv.style.width = "1px;";
+ input.setAttribute("autocomplete", "off");
+ this.oldValue = input.value;
- if (this.required) {
- this.setup();
- }
+ Tobago.addBindEventListener(input, "keyup", this, "doCheckSuggest");
Tobago.addAjaxComponent(this.id, this);
};
Tobago.extend(Tobago.AutocompleterAjax.prototype, Tobago.In.prototype);
+Tobago.AutocompleterAjax.prototype.doCheckSuggest = function(event) {
+// LOG.show();
+// LOG.info("AutocompleterAjax.doCheckSuggest()");
+
+ var input = Tobago.element(this.id);
+
+ var code = event.which;
+ if (code == 0) {
+ code = event.keyCode;
+ }
+
+// LOG.info(" code = " + code);
+// LOG.info(" type = " + event.type);
+
+ switch (code) {
+ case 27: // escape
+ this.closeSuggest(true);
+ return false;
+ case 40: // cursor down
+ var div = Tobago.element(this.id + "_suggestDiv");
+ if (div) {
+ div.style.display = "block";
+ try {
+ // focus() on not visible elements breaks IE
+ div.firstChild.firstChild.firstChild.focus();
+ } catch(ex) {}
+ return false;
+ }
+ }
+
+ if (this.oldValue == input.value) {
+ return;
+ }
+ this.oldValue = input.value;
+
+ if (input.value.length < this.options.minPrefixLength) {
+ return;
+ }
+
+ if (this.currentTimeout !== undefined) {
+ clearTimeout(this.currentTimeout);
+ }
+
+ var self = this;
+ this.currentTimeout = setTimeout(function() {
+ self.fetchSuggestions(input);
+ }, this.options.eventDelay);
+
+};
+
+Tobago.AutocompleterAjax.prototype.fetchSuggestions = function(input) {
+ if (!this.requestActive) {
+ this.requestActive = true;
+ LOG.debug("fetchSuggestions() request Suggestions for " + input.value);
+ Tobago.Updater.update(input, input.id, input.id, this.options);
+ } else {
+ this.rerequest = true;
+ }
+};
+
+
Tobago.AutocompleterAjax.prototype.doUpdate = function(data) {
-
- if (this.nextRequest) {
- var request = this.nextRequest;
- this.nextRequest = undefined;
- this.request = undefined;
- var self = this;
- setTimeout(function() {self.fetchSuggestItems(request)}, 50);
+
+ if (this.rerequest) {
+ this.rerequest = false;
+ this.requestActive = true;
+ LOG.debug("doUpdate() request Suggestions for " + input.value);
+ Tobago.update(input, input.id, input.id, this.options);
+ } else {
+ if (data.responseCode == Tobago.Updater.CODE_SUCCESS) {
+ LOG.debug("doUpdate() CODE_SUCCESS");
+ LOG.debug("doUpdate() data.script() : " + data.script);
+ this.suggest(data.script())
+ }
+ this.requestActive = false;
+ }
+ this.currentTimeout = undefined;
+ };
+
+Tobago.AutocompleterAjax.prototype.suggest = function(suggestObject) {
+ var div = Tobago.element(this.id + "_suggestDiv");
+ if (!div) {
+ div = this.createSuggestDiv();
} else {
- if (data.responseCode == Tobago.Updater.CODE_SUCCESS) {
- this.store._jsonData = data.script();
- this.store._loadFinished = false;
- this.store.fetchOrig(this.request);
- }
- this.request = undefined;
+ div.style.display = "block";
+ }
+// div.style.height = "120px";
+
+ var ul = document.createElement('ul');
+
+ for (var i = 0; i < suggestObject.items.length; i++) {
+ var item = suggestObject.items[i];
+
+ var li = document.createElement('li');
+ var a = document.createElement('a');
+ a.innerHTML = item.label;
+ a.sugggestItem = item;
+ if (item.nextFocusId) {
+ a.nextFocusId = item.nextFocusId;
+ } else if (suggestObject.nextFocusId) {
+ a.nextFocusId = suggestObject.nextFocusId;
+ }
+// a.id = this.id + "_suggestItem_" + i;
+ a.href = Tobago.EMPTY_HREF;
+ li.appendChild(a);
+ Tobago.addBindEventListener(a, "keyup", this, "suggestKeyUp");
+ Tobago.addBindEventListener(a, "focus", this, "suggestFocus");
+ Tobago.addBindEventListener(a, "click", this, "selectSuggest");
+ Tobago.addBindEventListener(li, "mouseover", this, "setFocus");
+ Tobago.addBindEventListener(li, "click", this, "selectSuggest");
+ ul.appendChild(li);
+ }
+
+
+ if (div.firstChild) {
+ div.removeChild(div.firstChild);
}
+ div.appendChild(ul);
+ if (div.clientWidth < div.scrollWidth) {
+ var runtimeStyle = Tobago.getRuntimeStyle(div);
+ var leftBorder = runtimeStyle.borderLeftWidth.replace(/\D/g, "") - 0;
+ var rightBorder = runtimeStyle.borderRightWidth.replace(/\D/g, "") - 0;
+ div.style.width = (div.scrollWidth + leftBorder + rightBorder) + "px";
+ }
+
};
-Tobago.AutocompleterAjax.prototype.fetchSuggestItems = function(request) {
-
- if (!request.ajaxId) {
- request.ajaxId = this.id;
- }
- if (!request.index) {
- request.index = this.index++;
- }
-
- if (!this.request) {
- this.request = request;
- request.abort = function() {self.doUpdate({ajaxId: request.ajaxId, responseCode: Tobago.Updater.CODE_ERROR})};
- Tobago.Updater.update(null, request.ajaxId, request.ajaxId, {createOverlay: false});
- } else {
- this.nextRequest = request;
- request = {abort: function() {}};
+
+Tobago.AutocompleterAjax.prototype.setFocus = function(event) {
+ try {
+ Tobago.element(event).firstChild.focus();
+ } catch(e) {}
+};
+
+Tobago.AutocompleterAjax.prototype.selectSuggest = function(event) {
+
+ var a = Tobago.element(event);
+ if (a.tagName == "LI") {
+ a = a.firstChild;
+ try {
+ a.focus();
+ } catch(e) {}
}
- return request;
-}
+ this.closeSuggest(false);
+
+ var suggestItem = a.sugggestItem;
+ LOG.debug("item.value : " + suggestItem.value);
-Tobago.AutocompleterAjaxStore = function(autoCompleter) {
-// this.autoCompleter = autoCompleter;
-// var store = new dojo.data.ItemFileReadStore({data: {items: []}});
- Tobago.extend(this, new dojo.data.ItemFileReadStore({data: {items: []}}));
-
- this.fetchOrig = this.fetch;
-
- this.fetch = function(data) {
- return autoCompleter.fetchSuggestItems(data);
+ var input = Tobago.element(this.id);
+ input.value = suggestItem.value;
+ this.oldValue = input.value;
+
+ try {
+ if (suggestItem.values) {
+ for (var i = 0; i < suggestItem.values.length; i++) {
+ var item = suggestItem.values[i];
+ LOG.debug(item.id + " = " + item.value);
+ Tobago.element(item.id).value = item.value;
+ }
+ }
+ } catch(e) {}
+
+ var nextFocusElement = input;
+ LOG.debug(" suggestItem.nextFocusId = " + a.nextFocusId);
+ if (a.nextFocusId) {
+ var element = Tobago.element(a.nextFocusId);
+ if (element) {
+ nextFocusElement = element;
+ }
}
+ try {
+ nextFocusElement.focus();
+ } catch(e) {}
+
+ Tobago.stopEventPropagation(event);
+ return false;
};
+Tobago.AutocompleterAjax.prototype.suggestFocus = function(event) {
+
+
+ var a = Tobago.element(event);
+ var ul = a.parentNode.parentNode;
+ for (var i = 0; i < ul.childNodes.length; i++) {
+ Tobago.removeCssClass(ul.childNodes[i], "selected");
+ }
+ Tobago.addCssClass(a.parentNode, "selected");
+};
+
+Tobago.AutocompleterAjax.prototype.suggestKeyUp = function(event) {
+
+ var li = Tobago.element(event).parentNode;
+
+ var code = event.which;
+ if (code == 0) {
+ code = event.keyCode;
+ }
+
+ var handled = false;
+
+ switch (code) {
+ case 27: // escape
+ this.closeSuggest(true);
+ handled = true;
+ break;
+ case 38: // cursor up
+ if (li.previousSibling) {
+ try {
+ // focus() on not visible elements breaks IE
+ li.previousSibling.firstChild.focus();
+ } catch(ex) {}
+ }
+ handled = true;
+ break;
+ case 40: // cursor down
+ if (li.nextSibling) {
+ try {
+ // focus() on not visible elements breaks IE
+ li.nextSibling.firstChild.focus();
+ } catch(ex) {}
+ }
+ handled = true;
+ break;
+ default:
+ break;
+ }
+ return !handled;
+};
+
+
+Tobago.AutocompleterAjax.prototype.closeSuggest = function(focus) {
+ var div = Tobago.element(this.id + "_suggestDiv");
+ div.style.display = "none";
+ if (focus) {
+ try {
+ Tobago.element(this.id).focus();
+ } catch(e) {}
+ }
+};
+
+Tobago.AutocompleterAjax.prototype.createSuggestDiv = function() {
+
+ var input = Tobago.element(this.id);
+
+ var div = document.createElement('div');
+ div.style.top = (Tobago.getAbsoluteTop(input) + Tobago.getHeight(input)) + "px";
+ div.style.left = Tobago.getAbsoluteLeft(input) + "px";
+ div.style.width = Tobago.getWidth(input) + "px";
+ div.className = "tobago-in-suggest-popup";
+ div.id = this.id + "_suggestDiv";
+ Tobago.page.appendChild(div);
+ return div;
+};
Modified: myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=895083&r1=895082&r2=895083&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js (original)
+++ myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js Fri Jan 1 22:05:55 2010
@@ -2525,8 +2525,8 @@
var data;
for (var i = 0; i < requestedIds.length; i++) {
var id = requestedIds[i];
- LOG.debug("handleMissingResponse id = " + id) ;
if (! doneIds[id]) {
+ LOG.debug("handleMissingResponse id = " + id) ;
if (!data) {
data = {responseCode: Tobago.Updater.CODE_NOT_MODIFIED, html: "error", script: function() {}};
}
Added: myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/style/style.css
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/style/style.css?rev=895083&view=auto
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/style/style.css (added)
+++ myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/style/style.css Fri Jan 1 22:05:55 2010
@@ -0,0 +1,4 @@
+.tobago-in-suggest-popup a {
+ text-decoration: none;
+ color: black;
+}
\ No newline at end of file