You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ba...@apache.org on 2006/02/19 23:48:07 UTC
svn commit: r378973 - in /myfaces/tomahawk/trunk/sandbox:
core/src/main/java/org/apache/myfaces/custom/statechangednotifier/
core/src/main/resources/org/apache/myfaces/custom/statechangednotifier/resource/
examples/src/main/webapp/
Author: baranda
Date: Sun Feb 19 14:48:06 2006
New Revision: 378973
URL: http://svn.apache.org/viewcvs?rev=378973&view=rev
Log:
Should fix stateChangedNotifier lags in IE.
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifierRenderer.java
myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/statechangednotifier/resource/stateChangedNotifier.js
myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/stateChangedNotifier.jsp
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifierRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifierRenderer.java?rev=378973&r1=378972&r2=378973&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifierRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifierRenderer.java Sun Feb 19 14:48:06 2006
@@ -50,7 +50,7 @@
String javascriptLocation = (String) notifier.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
DojoUtils.addMainInclude(facesContext, javascriptLocation, new DojoConfig());
DojoUtils.addRequire(facesContext, "dojo.event.*");
- DojoUtils.addRequire(facesContext, "dojo.xml.Parse");
+ //DojoUtils.addRequire(facesContext, "dojo.xml.Parse");
AddResource addResource = AddResourceFactory.getInstance(facesContext);
addResource.addJavaScriptAtPosition(facesContext, AddResource.HEADER_BEGIN,
@@ -71,11 +71,13 @@
UIForm form = getParentForm(notifier);
String formId = form.getClientId(facesContext);
+ String notifierVar = replacedClientId+"Notifier";
+
StringBuffer sb = new StringBuffer();
sb.append("<!--\n");
sb.append("dojo.addOnLoad(window, '"+initFunctionName+"');\n");
sb.append("function "+initFunctionName+ "() {\n");
- sb.append(replacedClientId+"Notifier = new org.apache.myfaces.StateChangedNotifier('"+formId+"','"+notifierClientId+"','"+notifier.getConfirmationMessage()+"',");
+ sb.append(notifierVar+" = new org.apache.myfaces.StateChangedNotifier('"+notifierVar+"','"+formId+"','"+notifierClientId+"','"+notifier.getConfirmationMessage()+"',");
String excludedCommandIds = notifier.getExcludedIds();
if (excludedCommandIds != null)
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/statechangednotifier/resource/stateChangedNotifier.js
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/statechangednotifier/resource/stateChangedNotifier.js?rev=378973&r1=378972&r2=378973&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/statechangednotifier/resource/stateChangedNotifier.js (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/statechangednotifier/resource/stateChangedNotifier.js Sun Feb 19 14:48:06 2006
@@ -15,66 +15,95 @@
*/
dojo.provide("org.apache.myfaces.StateChangedNotifier");
-org.apache.myfaces.StateChangedNotifier = function(formId, hiddenFieldId, message, excludeCommandIdList)
+org.apache.myfaces.StateChangedNotifier = function(notifierName, formId, hiddenFieldId, message, excludeCommandIdList)
{
-
+ this.notifierName = notifierName;
this.formId = formId;
this.hiddenFieldId = hiddenFieldId;
this.message = message;
this.excludeCommandIdList = excludeCommandIdList;
var arrCommandIds = null;
- var clickedCommand = null;
+
+ var objectsToConfirmList = new Array();
+ var objectsToConfirmBeforeExclusion = new Array();
this.prepareNotifier = function ()
{
var form = document.getElementById(formId);
+ addOnChangeListener("input");
+ addOnChangeListener("textarea");
+ addOnChangeListener("select");
+
if (excludeCommandIdList != null)
{
arrCommandIds = excludeCommandIdList.split(",");
+ addObjectsToConfirmList("a");
+ addObjectsToConfirmList("input");
+ addObjectsToConfirmList("button");
+
+ putConfirmExcludingElements();
+ }
+ }
+
+ this.showMessage = function()
+ {
+ var hiddenField = getHiddenElement();
+
+ if (hiddenField.value == "true")
+ {
+ //if (!confirm(message)) return false;
+ return confirm(message);
}
- var parser = new dojo.xml.Parse();
- elementsInForm = parser.parseElement(form);
- traverseTree(elementsInForm, null);
+ return true;
- form.onsubmit = confirmSubmit;
}
- function traverseTree(x, type)
+ function addOnChangeListener(tagName)
{
- for (var y in x)
+ var arrElements = document.getElementsByTagName(tagName);
+
+ for (var i=0; i<arrElements.length; i++)
{
- if (typeof x[y] == "object" && x[y] != x.nodeRef)
- {
- traverseTree(x[y], y);
- }
+ dojo.event.browser.addListener(arrElements[i], "onchange", changeHiddenValue);
+ }
+ }
- else
+ function addObjectsToConfirmList(tagName)
+ {
+ var arrElements = document.getElementsByTagName(tagName);
+
+ for (var i=0; i<arrElements.length; i++)
+ {
+ var elementId = arrElements[i].id;
+ var onclick = arrElements[i].onclick;
+
+ if (elementId != null && onclick != null && elementId != '')
{
- if (type == "input" || type == "textarea" || type == "select")
- {
- processComponent(x[y]);
- }
-
- if (arrCommandIds != null)
- {
- var elementId = x[y].id;
- var onclick = x[y].onclick;
-
- if (elementId != null && onclick != null && elementId != '')
- {
- checkExclusion(elementId);
- }
- }
+ objectsToConfirmBeforeExclusion.push(elementId);
}
}
}
- function processComponent(inputComponent)
+ function putConfirmExcludingElements()
{
- dojo.event.browser.addListener(inputComponent, "onchange", changeHiddenValue);
+ for (var i=0; i<objectsToConfirmBeforeExclusion.length; i++)
+ {
+ var elementId = objectsToConfirmBeforeExclusion[i];
+
+ if (!isElementExcluded(elementId))
+ {
+ objectsToConfirmList.push(elementId);
+ }
+ }
+
+ for (var i=0; i<objectsToConfirmList.length; i++)
+ {
+ var objectToConfirm = objectsToConfirmList[i];
+ putConfirmInElement(objectToConfirm);
+ }
}
function changeHiddenValue()
@@ -83,18 +112,9 @@
hiddenField.value = "true";
}
- function confirmSubmit()
- {
- var hiddenField = getHiddenElement();
- if (hiddenField.value == "true")
- {
- if (!confirm(message)) return false;
- }
- }
-
- function checkExclusion(elementId)
+ function isElementExcluded(elementId)
{
- for (i=0; i<arrCommandIds.length; i++)
+ for (var i=0; i<arrCommandIds.length; i++)
{
var excludedId = arrCommandIds[i];
var idRegex = null;
@@ -108,36 +128,23 @@
idRegex = new RegExp(excludedId+"([\\d+])?")
}
- if (elementId.match(idRegex))
+ if (elementId.match(idRegex) != null)
{
- excludeCommandWithId(elementId);
+ return true;
}
}
}
- function excludeCommandWithId(commandId)
+ function putConfirmInElement(commandId)
{
var command = document.getElementById(commandId);
if (command != null)
{
- clickedCommand = command;
- command.onclick = submitWithoutConfirm;
+ var onclick = command.getAttribute("onclick");
+ command.setAttribute("onclick", "if ("+notifierName+".showMessage()) { "+onclick+" }");
}
- }
-
- function submitWithoutConfirm()
- {
- var form = document.getElementById(formId);
-
- document.forms[formId].elements[formId+':_link_hidden_'].value= clickedCommand.id;
-
- var clearFunction = "clear_"+formId;
-
- form.onsubmit = clearFunction;
- form.submit();
- return false;
}
function getHiddenElement()
Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/stateChangedNotifier.jsp
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/stateChangedNotifier.jsp?rev=378973&r1=378972&r2=378973&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/stateChangedNotifier.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/stateChangedNotifier.jsp Sun Feb 19 14:48:06 2006
@@ -29,58 +29,46 @@
<f:view>
- <p>
- There are two forms in this page. Each one has a stateChangedNotifier, so if one of the elements in the form changes
- a confirmation window will be shown when clicking on a link within each form.
- </p>
-
- <p>
- <b>FORM 1:</b>
- </p>
-
<h:form id="form1">
- <s:stateChangedNotifier id="stateChangedId"
- confirmationMessage="Are you sure?"
- disabled="false" />
+ <s:stateChangedNotifier confirmationMessage="Values have changed. Did you know it?"
+ disabled="false"
+ excludedIds="excludedLink1,excludedLink2"/>
<h:panelGrid columns="1">
- <h:inputText value=""/>
- <h:selectManyCheckbox>
+ <h:inputText id="input1" value="" required="true"/>
+ <h:message for="input1"/>
+
+ <h:inputTextarea value=""/>
+ <h:selectOneMenu value="item2">
<f:selectItem itemValue="item1" itemLabel="Item 1"/>
<f:selectItem itemValue="item2" itemLabel="Item 2"/>
<f:selectItem itemValue="item3" itemLabel="Item 3"/>
- </h:selectManyCheckbox>
+ </h:selectOneMenu>
+
+ <t:commandLink value="Submit Form (goes to the home page)" action="home"/>
+ <t:commandLink id="excludedLink1" forceId="true"
+ value="Excluded link (goes to the home page without warning)" action="home"/>
+ <t:commandButton
+ value="Submit Form (goes to the home page)" action="home"/>
+ <t:commandButton id="excludedLink2"
+ value="Excluded button (goes to the home page without warning)" action="home"/>
</h:panelGrid>
- <t:commandLink value="Submit Form 1 (goes to the home page)" action="home"/>
- </h:form>
- <f:verbatim>
- <p>
- <hr/>
- <b>FORM 2:</b>
- </p>
- </f:verbatim>
+ </h:form>
<h:form id="form2">
- <s:stateChangedNotifier confirmationMessage="Values have changed. Did you know it?"
- disabled="false"
- excludedIds="excludedLink1,excludedLink2"/>
+ <s:stateChangedNotifier confirmationMessage="Everything ok?" excluded="link3"/>
<h:panelGrid columns="1">
- <h:inputText value=""/>
+ <h:inputText id="input1" value="" />
+ <h:message for="input1"/>
+
<h:inputTextarea value=""/>
- <h:selectOneMenu value="item2">
- <f:selectItem itemValue="item1" itemLabel="Item 1"/>
- <f:selectItem itemValue="item2" itemLabel="Item 2"/>
- <f:selectItem itemValue="item3" itemLabel="Item 3"/>
- </h:selectOneMenu>
- <t:commandLink immediate="true" value="Submit Form 2 (goes to the home page)" action="home"/>
- <t:commandLink id="excludedLink1" forceId="true"
- value="Excluded link (goes to the home page withouth warning)" action="home"/>
- <t:commandLink id="excludedLink2" immediate="true"
- value="Another excluded link (goes to the home page withouth warning)" action="home"/>
+ <t:commandLink value="Submit Form (goes to the home page)" action="home"/>
+ <t:commandButton id="link3"
+ value="Excluded button (goes to the home page without warning)" action="home"/>
</h:panelGrid>