You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2006/05/04 18:36:58 UTC
svn commit: r399757 - in /myfaces/tomahawk/trunk/sandbox:
core/src/main/java/org/apache/myfaces/custom/suggestajax/tablesuggestajax/
core/src/main/resources/org/apache/myfaces/custom/ajax/util/resource/
core/src/main/resources/org/apache/myfaces/custom...
Author: mmarinschek
Date: Thu May 4 09:36:56 2006
New Revision: 399757
URL: http://svn.apache.org/viewcvs?rev=399757&view=rev
Log:
tableSuggest: fixed request locking bug; slight changes to improve handling of js
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/tablesuggestajax/TableSuggestAjaxRenderer.java
myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/ajax/util/resource/inputAjax.js
myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/suggestajax/tablesuggestajax/resource/tableSuggest.js
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/tableSuggestAjax.jsp
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/tablesuggestajax/TableSuggestAjaxRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/tablesuggestajax/TableSuggestAjaxRenderer.java?rev=399757&r1=399756&r2=399757&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/tablesuggestajax/TableSuggestAjaxRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/suggestajax/tablesuggestajax/TableSuggestAjaxRenderer.java Thu May 4 09:36:56 2006
@@ -50,7 +50,7 @@
private static final Log log = LogFactory.getLog(TableSuggestAjaxRenderer.class);
public static final int DEFAULT_START_REQUEST = 0;
- public static final int DEFAULT_BETWEEN_KEY_UP = 0;
+ public static final int DEFAULT_BETWEEN_KEY_UP = 200;
/**
* Encodes any stand-alone javascript functions that are needed.
@@ -116,12 +116,6 @@
tableSuggestAjax.getAttributes().put("autocomplete","off");
- /* String oldStyleClass = tableSuggestAjax.getStyleClass();
- tableSuggestAjax.setStyleClass(
- (oldStyleClass!=null && oldStyleClass.length()>=0 ? oldStyleClass : "")+" myFacesTableSuggestAjax");
-
- tableSuggestAjax.setStyleClass(oldStyleClass);*/
-
String clientId = component.getClientId(context);
String actionURL = getActionUrl(context);
@@ -208,19 +202,12 @@
String tableSuggestVar = "tableSuggest"+clientId.replace(':','_');
//doing ajax request and handling the response
- buf.append( "var "+tableSuggestVar+" = new org_apache_myfaces_TableSuggest();\n"
+ buf.append( "var "+tableSuggestVar+" = new org_apache_myfaces_TableSuggest(\""+ ajaxUrl + "\", "+ betweenKeyUp +", "+ startRequest +");\n"
- + "dojo.event.connect(dojo.byId(\"" + clientId + "\"), \"onkeyup\", function(evt) {\n"
- + " if( (evt.keyCode == 13) || (evt.keyCode == 9) )\n" //enter,tab
- + " document.onclick();\n"
- + " else\n"
- + tableSuggestVar+".decideRequest(\""+ clientId +"\", \""+ ajaxUrl +"\", "+ betweenKeyUp +","+ startRequest +", evt);\n"
- +" });\n");
+ + "dojo.event.connect(dojo.byId(\"" + clientId + "\"), \"onkeyup\", function(evt) { "+ tableSuggestVar+".decideRequest(evt); });\n");
//if setting the focus outside the input field, popup should not be displayed
- buf.append("dojo.event.connect(document, \"onclick\", function(evt) {\n"
- + " "+tableSuggestVar+".resetSettings(\"" + clientId+"_auto_complete\");\n"
- + "});\n");
+ buf.append("dojo.event.connect(document, \"onclick\", function(evt) { "+tableSuggestVar+".resetSettings(); });\n");
return buf;
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/ajax/util/resource/inputAjax.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/ajax/util/resource/inputAjax.js?rev=399757&r1=399756&r2=399757&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/ajax/util/resource/inputAjax.js (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/ajax/util/resource/inputAjax.js Thu May 4 09:36:56 2006
@@ -97,7 +97,7 @@
{
var summaryAndDetail = summary;
if (detail) summaryAndDetail += ": " + detail;
- var ajaxMessagesSpan = document.getElementById("_idJsp1:_idJsp23");
+ var ajaxMessagesSpan = document.getElementById("_id1:_id23");
if (ajaxMessagesSpan)
{
ajaxMessagesSpan.innerHTML += summaryAndDetail + '<br/>';
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/suggestajax/tablesuggestajax/resource/tableSuggest.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/suggestajax/tablesuggestajax/resource/tableSuggest.js?rev=399757&r1=399756&r2=399757&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/suggestajax/tablesuggestajax/resource/tableSuggest.js (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/suggestajax/tablesuggestajax/resource/tableSuggest.js Thu May 4 09:36:56 2006
@@ -15,22 +15,28 @@
*/
-org_apache_myfaces_TableSuggest = function()
+org_apache_myfaces_TableSuggest = function(ajaxUrl,
+ millisBetweenKeyUps,
+ startChars)
{
this.tablePagesCollection = new dojo.collections.ArrayList();
this.inputField = null;
-
this.popUp = null;
- this.popUpStyle = null;
+ this.url = ajaxUrl;
this.firstHighlightedElem = null;
this.actualHighlightedElem = null;
this.iframe = null;
+
this.requestLocker = false;
+ this.startChars = startChars;
+
this.lastKeyPressTime = new Date();
+ this.millisBetweenKeyUps = millisBetweenKeyUps;
+
this.scrollingRow = 0;
//puting the values from the choosen row into the fields
@@ -120,14 +126,11 @@
}
};
- org_apache_myfaces_TableSuggest.prototype.handleRequestResponse = function(url, tableSuggest, keyCode)
+ org_apache_myfaces_TableSuggest.prototype.handleRequestResponse = function(event)
{
- if(!this.popUpStyle)
- this.popUpStyle = this.popUp.style.cssText;
- else
- this.popUp.style.cssText = this.popUpStyle;
+ var tableSuggest = this;
- if(keyCode == 40) //down key
+ if(event.keyCode == 40) //down key
{
if(!this.firstHighlightedElem)
{
@@ -173,7 +176,7 @@
}
}
}
- else if(keyCode == 38) //up key
+ else if(event.keyCode == 38) //up key
{
var prevElem = dojo.dom.prevElement(this.actualHighlightedElem);
@@ -203,14 +206,19 @@
dojo.debug("could not move to next item in table, wrong item is");dojo.debug(nextElem);
}
}
- else
+ else if( !this.requestLocker && this.requestBetweenKeyUpEvents() )
{
+ this.requestLocker = true;
+ dojo.debug("taking lock, starting AJAX request");
+
+ var idValuePair = "&" + this.inputField.id + "=" + this.inputField.value;
+
this.firstHighlightedElem = null;
this.actualHighlightedElem = null;
dojo.io.bind
({
- url: url,
+ url: this.url + idValuePair,
handle: function(type, data, evt)
{
dojo.debug("after response");
@@ -251,12 +259,16 @@
}
tableSuggest.handleIFrame();
+
+ dojo.debug("releasing lock");
+ tableSuggest.requestLocker = false;
}
else if(type == "error")
{
dojo.debug("error during response");
//dojo.debug(data);
// here, data is our error object
+ tableSuggest.requestLocker = false;
}
},
mimetype: "text/plain"
@@ -346,11 +358,11 @@
dojo.html.addClass(elem,"tableSuggestOut");
};
- org_apache_myfaces_TableSuggest.prototype.requestBetweenKeyUpEvents = function(millisBetweenKeyPress)
+ org_apache_myfaces_TableSuggest.prototype.requestBetweenKeyUpEvents = function()
{
var currentTime = new Date();
- if( (currentTime - this.lastKeyPressTime) > millisBetweenKeyPress)
+ if( (currentTime - this.lastKeyPressTime) > this.millisBetweenKeyUps)
{
dojo.debug(currentTime - this.lastKeyPressTime);
this.lastKeyPressTime = currentTime;
@@ -397,27 +409,10 @@
}
};
- org_apache_myfaces_TableSuggest.prototype.lastKeyUpEvent = function()
- {
- //dojo.lang.setTimeout('',4000);
- var currentTime = new Date();
- dojo.debug("last keyUpEvent?");
- dojo.debug(currentTime - this.lastKeyPressTime);
- if( (currentTime - this.lastKeyPressTime) > 250)
- {
- dojo.debug("was last keyUpEvent");
- return true;
- }
- else return false;
- };
-
org_apache_myfaces_TableSuggest.prototype.resetSettings = function()
{
if(this.popUp)
- {
dojo.dom.removeChildren(this.popUp);
- this.popUp.style.cssText = "";
- }
if(this.iframe && this.popUp)
this.popUp.parentNode.removeChild(this.popUp.parentNode.childNodes[0])
@@ -429,31 +424,31 @@
this.scrollingRow = 0;
};
- org_apache_myfaces_TableSuggest.prototype.decideRequest = function(clientId, ajaxUrl,
- millisBetweenKeyUps, startChars, event)
+ org_apache_myfaces_TableSuggest.prototype.decideRequest = function(event)
{
- if( !this.requestLocker && (this.requestBetweenKeyUpEvents(millisBetweenKeyUps) || this.lastKeyUpEvent()) )
+ if( (event.keyCode == 13) || (event.keyCode == 9) ) //enter,tab
+ this.resetSettings();
+ else
{
- this.requestLocker = true;
+ this.inputField = dojo.byId(event.target.id);
+ this.popUp = dojo.byId(event.target.id+"_auto_complete");
- this.inputField = dojo.byId(clientId);
- this.popUp = dojo.byId(clientId+"_auto_complete");
- var inputValue = this.inputField.value;
- var url = ajaxUrl + "&" + clientId + "=" + inputValue;
+ var inputValue = event.target.value;
- if(startChars)
+ if(this.startChars)
{
- if(inputValue.length >= startChars)
- this.handleRequestResponse(url, this, event.keyCode);
+ if(inputValue.length >= this.startChars)
+ this.handleRequestResponse(event);
+ else
+ this.resetSettings();
}
else if(inputValue != "" )
- this.handleRequestResponse(url, this, event.keyCode);
+ this.handleRequestResponse(event);
if(inputValue == "" )
this.resetSettings();
-
- this.requestLocker = false;
}
+ dojo.debug("leaving decide function");
};
}
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/tableSuggestAjax.jsp
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/tableSuggestAjax.jsp?rev=399757&r1=399756&r2=399757&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/tableSuggestAjax.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/tableSuggestAjax.jsp Thu May 4 09:36:56 2006
@@ -30,16 +30,16 @@
<f:view>
- <h:form>
+ <h:form id="ajaxform">
<f:verbatim><br/><br/><br/><br/></f:verbatim>
<h:panelGrid columns="2">
<h:panelGrid columns="4">
<f:verbatim> City Field TableSuggest <br/> (Paginator) <br/> Suggest starts with 2. char </f:verbatim>
- <s:tableSuggestAjax var="address" id="cityField" startRequest="2"
+ <s:tableSuggestAjax var="address" id="suggest" startRequest="2"
nextPageFieldClass="ajaxNextTablePageField"
- value="#{inputSuggestAjax.suggestValue}"
+ value="#{inputSuggestAjax.suggestValue}" betweenKeyUp="300"
columnOutClass="tableSuggestOut" columnHoverClass="tableSuggestHover"
suggestedItemsMethod="#{inputSuggestAjax.getAddressList}"
maxSuggestedItems="10" tableStyleClass="ajaxTable">
@@ -63,10 +63,10 @@
</t:column>
</s:tableSuggestAjax>
<f:verbatim> City Field TableSuggest <br/> (Scrolling) <br/> If first chars are "as" scrolling list appears </f:verbatim>
- <s:tableSuggestAjax var="address" id="cityField2" tableStyleClass="ajaxTable"
- nextPageFieldClass="ajaxNextTablePageField"
+ <s:tableSuggestAjax var="address" id="cityField2" tableStyleClass="ajaxTableWidth"
+ nextPageFieldClass="ajaxNextTablePageField" betweenKeyUp="300"
columnOutClass="tableSuggestOut" columnHoverClass="tableSuggestHover"
- maxSuggestedItems="50" popupStyle="position:absolute; z-index:100000; overflow:auto;height:200px;"
+ maxSuggestedItems="50" popupStyle="position:absolute; z-index:100000; overflow:auto; height:200px;"
suggestedItemsMethod="#{inputSuggestAjax.getAddressList}">
<t:column>
<s:outputText for="cityField2" label="#{address.city}"/>
@@ -79,23 +79,21 @@
</t:column>
</s:tableSuggestAjax>
</h:panelGrid>
- <h:panelGrid>
- <h:commandButton/>
- <h:outputText value="Street"/>
- <t:inputText id="streetNameField" />
- <h:outputText value="State"/>
- <t:selectOneMenu id="stateField">
- <f:selectItem value="" itemLabel="NY" itemValue="11"/>
- <f:selectItem value="" itemLabel="IL" itemValue="12"/>
- <f:selectItem value="" itemLabel="NW" itemValue="13"/>
- <f:selectItem value="" itemLabel="SJ" itemValue="14"/>
- <f:selectItem value="" itemLabel="KL" itemValue="15"/>
- <f:selectItem value="" itemLabel="MH" itemValue="16"/>
- </t:selectOneMenu>
- </h:panelGrid>
+ <h:panelGrid>
+ <h:commandButton/>
+ <h:outputText value="Street"/>
+ <t:inputText id="streetNameField" />
+ <h:outputText value="State"/>
+ <t:selectOneMenu id="stateField">
+ <f:selectItem value="" itemLabel="NY" itemValue="11"/>
+ <f:selectItem value="" itemLabel="IL" itemValue="12"/>
+ <f:selectItem value="" itemLabel="NW" itemValue="13"/>
+ <f:selectItem value="" itemLabel="SJ" itemValue="14"/>
+ <f:selectItem value="" itemLabel="KL" itemValue="15"/>
+ <f:selectItem value="" itemLabel="MH" itemValue="16"/>
+ </t:selectOneMenu>
+ </h:panelGrid>
</h:panelGrid>
- <f:verbatim><br/><br/><br/><br/><br/></f:verbatim>
- <s:dojoInitializer debugConsole="true"/>
</h:form>
</f:view>