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 2006/04/02 22:03:35 UTC
svn commit: r390892 - in
/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier:
StateChangedNotifier.java StateChangedNotifierRenderer.java
StateChangedNotifierTag.java
Author: werpu
Date: Sun Apr 2 13:03:33 2006
New Revision: 390892
URL: http://svn.apache.org/viewcvs?rev=390892&view=rev
Log:
added a deferred triggering, so that the rendering is not stopped at more complicated forms, added a patch submitted last week
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifier.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifierRenderer.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifierTag.java
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifier.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifier.java?rev=390892&r1=390891&r2=390892&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifier.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifier.java Sun Apr 2 13:03:33 2006
@@ -21,84 +21,65 @@
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
+
/**
* Shows a confirmation window if some of the input fields of the form have changed its value
* @author Bruno Aranda (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class StateChangedNotifier extends HtmlInputHidden
-{
- public static final String COMPONENT_TYPE = "org.apache.myfaces.StateChangedNotifier";
+public class StateChangedNotifier extends HtmlInputHidden {
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.StateChangedNotifier";
public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.StateChangedNotifierRenderer";
private static final String DEFAULT_MESSAGE = "Are you sure?";
- private String confirmationMessage = DEFAULT_MESSAGE;
+ private String confirmationMessage = DEFAULT_MESSAGE;
private Boolean disabled;
- private String excludedIds = null;
+ private String excludedIds = null;
- public StateChangedNotifier()
- {
+ public StateChangedNotifier() {
super();
setRendererType(DEFAULT_RENDERER_TYPE);
}
- public Object saveState(FacesContext context)
- {
- Object[] values = new Object[4];
- values[0] = super.saveState(context);
- values[1] = confirmationMessage;
- values[2] = disabled;
- values[3] = excludedIds;
-
- return values;
+ /**
+ * enable the state changed notification for this cycle
+ *
+ */
+ public void enableStateChanged() {
+ super.setValue("true");
}
- public void restoreState(FacesContext context, Object state)
- {
- Object values[] = (Object[])state;
- super.restoreState(context, values[0]);
- this.confirmationMessage = (String) values[1];
- this.disabled = (Boolean) values[2];
- this.excludedIds = (String) values[3];
- }
+ public String getConfirmationMessage() {
+
+ if (confirmationMessage != null)
+ return confirmationMessage;
- public String getConfirmationMessage()
- {
- if (confirmationMessage != null) return confirmationMessage;
ValueBinding vb = getValueBinding("confirmationMessage");
- return vb != null ? _ComponentUtils.getStringValue(getFacesContext(), vb) : null;
- }
- public void setConfirmationMessage(String confirmationMessage)
- {
- this.confirmationMessage = confirmationMessage;
+ return (vb != null) ? _ComponentUtils.getStringValue(getFacesContext(), vb) : null;
}
- public Boolean getDisabled()
- {
- if (disabled != null) return disabled;
+ public Boolean getDisabled() {
+
+ if (disabled != null)
+ return disabled;
+
ValueBinding vb = getValueBinding("disabled");
- return vb != null ? (Boolean)vb.getValue(getFacesContext()) : null;
- }
- public void setDisabled(Boolean disabled)
- {
- this.disabled = disabled;
+ return (vb != null) ? (Boolean) vb.getValue(getFacesContext()) : null;
}
- public String getExcludedIds()
- {
- if (excludedIds != null) return excludedIds;
+ public String getExcludedIds() {
+
+ if (excludedIds != null)
+ return excludedIds;
+
ValueBinding vb = getValueBinding("excludedIds");
- return vb != null ? _ComponentUtils.getStringValue(getFacesContext(), vb) : null;
- }
- public void setExcludedIds(String excludedIds)
- {
- this.excludedIds = excludedIds;
+ return (vb != null) ? _ComponentUtils.getStringValue(getFacesContext(), vb) : null;
}
-
+
/**
* a helper reset to reset the notifier
* to a non state changed state
@@ -106,13 +87,35 @@
public void reset() {
super.setValue("false");
}
- /**
- * enable the state changed notification for this cycle
- *
- */
- public void enableStateChanged() {
- super.setValue("true");
+
+ public void restoreState(FacesContext context, Object state) {
+ Object[] values = (Object[]) state;
+ super.restoreState(context, values[0]);
+ this.confirmationMessage = (String) values[1];
+ this.disabled = (Boolean) values[2];
+ this.excludedIds = (String) values[3];
}
-
-}
+ public Object saveState(FacesContext context) {
+ Object[] values = new Object[4];
+ values[0] = super.saveState(context);
+ values[1] = confirmationMessage;
+ values[2] = disabled;
+ values[3] = excludedIds;
+
+ return values;
+ }
+
+ public void setConfirmationMessage(String confirmationMessage) {
+ this.confirmationMessage = confirmationMessage;
+ }
+
+ public void setDisabled(Boolean disabled) {
+ this.disabled = disabled;
+ }
+
+ public void setExcludedIds(String excludedIds) {
+ this.excludedIds = excludedIds;
+ }
+
+}
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=390892&r1=390891&r2=390892&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 Apr 2 13:03:33 2006
@@ -15,14 +15,8 @@
*/
package org.apache.myfaces.custom.statechangednotifier;
-import java.io.IOException;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIForm;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
import org.apache.commons.lang.StringUtils;
+
import org.apache.myfaces.custom.dojo.DojoConfig;
import org.apache.myfaces.custom.dojo.DojoUtils;
import org.apache.myfaces.renderkit.html.HtmlHiddenRenderer;
@@ -32,24 +26,31 @@
import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+
/**
* @author Bruno Aranda (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class StateChangedNotifierRenderer extends HtmlHiddenRenderer
-{
+public class StateChangedNotifierRenderer extends HtmlHiddenRenderer {
- public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException
- {
+ public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
RendererUtils.checkParamValidity(facesContext, uiComponent, StateChangedNotifier.class);
StateChangedNotifier notifier = (StateChangedNotifier) uiComponent;
- if (notifier.getDisabled() != null)
- {
+ if (notifier.getDisabled() != null) {
+
if (notifier.getDisabled().booleanValue())
return;
}
+
String javascriptLocation = (String) notifier.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
DojoUtils.addMainInclude(facesContext, uiComponent, javascriptLocation, new DojoConfig());
DojoUtils.addRequire(facesContext, uiComponent, "dojo.widget.Dialog");
@@ -60,20 +61,17 @@
writeDialog(facesContext, uiComponent);
AddResource addResource = AddResourceFactory.getInstance(facesContext);
- if(!DojoUtils.isInlineScriptSet(facesContext, "stateChangedNotifier.js"))
- addResource.addJavaScriptHere(facesContext, StateChangedNotifierRenderer.class, "stateChangedNotifier.js");
+
+ if (!DojoUtils.isInlineScriptSet(facesContext, "stateChangedNotifier.js"))
+ addResource.addJavaScriptHere(facesContext, StateChangedNotifierRenderer.class, "stateChangedNotifier.js");
String styleLocation = (String) uiComponent.getAttributes().get(JSFAttr.STYLE_LOCATION);
//we need a style def for the dialog system
- if (StringUtils.isNotBlank(styleLocation))
- {
+ if (StringUtils.isNotBlank(styleLocation)) {
addResource.addStyleSheet(facesContext, AddResource.HEADER_BEGIN, styleLocation + "/default.css");
- }
- else
- {
- addResource.addStyleSheet(facesContext, AddResource.HEADER_BEGIN, StateChangedNotifierRenderer.class,
- "css/default.css");
+ } else {
+ addResource.addStyleSheet(facesContext, AddResource.HEADER_BEGIN, StateChangedNotifierRenderer.class, "css/default.css");
}
encodeJavascript(facesContext, notifier);
@@ -81,6 +79,56 @@
super.encodeEnd(facesContext, uiComponent);
}
+ private void encodeJavascript(FacesContext facesContext, StateChangedNotifier notifier) {
+ String notifierClientId = notifier.getClientId(facesContext);
+
+ String replacedClientId = notifierClientId.replaceAll(":", "_");
+ String initFunctionName = "init_" + replacedClientId;
+
+ UIForm form = getParentForm(notifier);
+ String formId = form.getClientId(facesContext);
+
+ String notifierVar = replacedClientId + "Notifier";
+
+ StringBuffer sb = new StringBuffer();
+ sb.append("dojo.addOnLoad(window, '" + initFunctionName + "');\n");
+ sb.append("function " + initFunctionName + "() {\n");
+ sb.append(notifierVar + " = new org_apache_myfaces_StateChangedNotifier('" + notifierVar + "','" + formId + "','" + notifierClientId + "','" + notifier.getConfirmationMessage() + "',");
+
+ String excludedCommandIds = notifier.getExcludedIds();
+
+ if (excludedCommandIds != null) {
+ sb.append("'" + excludedCommandIds + "');\n");
+ } else {
+ sb.append("'');\n");
+ }
+
+ sb.append("setTimeout('"+replacedClientId +"Notifier.prepareNotifier()',2000);\n");
+
+ sb.append("}\n");
+
+ AddResource addResource = AddResourceFactory.getInstance(facesContext);
+ addResource.addInlineScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, sb.toString());
+ }
+
+ /**
+ * Get the parent UIForm. If no parent is a UIForm then returns null.
+ *
+ * @param component
+ * @return UIForm
+ */
+ private UIForm getParentForm(UIComponent component) {
+
+ // See if we are in a form
+ UIComponent parent = component.getParent();
+
+ while ((parent != null) && !(parent instanceof UIForm)) {
+ parent = parent.getParent();
+ }
+
+ return (UIForm) parent;
+ }
+
/**
* dialog definition
* this one is needed for the dojoized dialog
@@ -89,8 +137,7 @@
* @param uiComponent
* @throws IOException
*/
- private void writeDialog(FacesContext facesContext, UIComponent uiComponent) throws IOException
- {
+ private void writeDialog(FacesContext facesContext, UIComponent uiComponent) throws IOException {
/*
* <div id="form1__idJsp1Notifier_Dialog" style="position:absolute; visibility: hidden;">
<div id="form1__idJsp1Notifier_Dialog_Content">
@@ -105,13 +152,12 @@
String notifierClientId = uiComponent.getClientId(facesContext);
String replacedClientId = notifierClientId.replaceAll(":", "_");
- String dialogVar = replacedClientId + "Notifier_Dialog";
-
- String yesText = (String) uiComponent.getAttributes().get("yesText");
- String noText = (String) uiComponent.getAttributes().get("noText");
+ String dialogVar = replacedClientId + "Notifier_Dialog";
+ String yesText = (String) uiComponent.getAttributes().get("yesText");
+ String noText = (String) uiComponent.getAttributes().get("noText");
yesText = (yesText == null) ? "Yes" : yesText;
- noText = (noText == null) ? "No" : noText;
+ noText = (noText == null) ? "No" : noText;
ResponseWriter writer = facesContext.getResponseWriter();
writer.startElement(HTML.DIV_ELEM, uiComponent);
@@ -122,70 +168,17 @@
writer.endElement(HTML.DIV_ELEM);
writer.write(" ");
writer.startElement(HTML.INPUT_ELEM, uiComponent);
- writer.writeAttribute(HTML.TYPE_ATTR,"button",null);
+ writer.writeAttribute(HTML.TYPE_ATTR, "button", null);
writer.writeAttribute(HTML.ID_ATTR, dialogVar + "_Yes", null);
writer.writeAttribute(HTML.VALUE_ATTR, yesText, null);
writer.endElement(HTML.INPUT_ELEM);
writer.write(" ");
writer.startElement(HTML.INPUT_ELEM, uiComponent);
- writer.writeAttribute(HTML.TYPE_ATTR,"button",null);
+ writer.writeAttribute(HTML.TYPE_ATTR, "button", null);
writer.writeAttribute(HTML.ID_ATTR, dialogVar + "_No", null);
writer.writeAttribute(HTML.VALUE_ATTR, noText, null);
writer.endElement(HTML.INPUT_ELEM);
writer.endElement(HTML.DIV_ELEM);
writer.write(" ");
- }
-
- private void encodeJavascript(FacesContext facesContext, StateChangedNotifier notifier)
- {
- String notifierClientId = notifier.getClientId(facesContext);
-
- String replacedClientId = notifierClientId.replaceAll(":", "_");
- String initFunctionName = "init_" + replacedClientId;
-
- UIForm form = getParentForm(notifier);
- String formId = form.getClientId(facesContext);
-
- String notifierVar = replacedClientId + "Notifier";
-
- StringBuffer sb = new StringBuffer();
- sb.append("dojo.addOnLoad(window, '" + initFunctionName + "');\n");
- sb.append("function " + initFunctionName + "() {\n");
- sb.append(notifierVar + " = new org_apache_myfaces_StateChangedNotifier('" + notifierVar + "','" + formId
- + "','" + notifierClientId + "','" + notifier.getConfirmationMessage() + "',");
-
- String excludedCommandIds = notifier.getExcludedIds();
- if (excludedCommandIds != null)
- {
- sb.append("'" + excludedCommandIds + "');\n");
- }
- else
- {
- sb.append("'');\n");
- }
-
- sb.append(replacedClientId + "Notifier.prepareNotifier();\n");
-
- sb.append("}\n");
-
- AddResource addResource = AddResourceFactory.getInstance(facesContext);
- addResource.addInlineScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, sb.toString());
- }
-
- /**
- * Get the parent UIForm. If no parent is a UIForm then returns null.
- *
- * @param component
- * @return UIForm
- */
- private UIForm getParentForm(UIComponent component)
- {
- // See if we are in a form
- UIComponent parent = component.getParent();
- while (parent != null && !(parent instanceof UIForm))
- {
- parent = parent.getParent();
- }
- return (UIForm) parent;
}
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifierTag.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifierTag.java?rev=390892&r1=390891&r2=390892&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifierTag.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/statechangednotifier/StateChangedNotifierTag.java Sun Apr 2 13:03:33 2006
@@ -19,57 +19,50 @@
import javax.faces.component.UIComponent;
+
/**
* @author Bruno Aranda (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class StateChangedNotifierTag extends HtmlInputHiddenTag
-{
+public class StateChangedNotifierTag extends HtmlInputHiddenTag {
private String confirmationMessage;
private String disabled;
private String excludedIds;
- public String getComponentType()
- {
+ public String getComponentType() {
return StateChangedNotifier.COMPONENT_TYPE;
}
- public String getRendererType()
- {
+ public String getRendererType() {
return StateChangedNotifier.DEFAULT_RENDERER_TYPE;
}
- public void release()
- {
+ public void release() {
super.release();
confirmationMessage = null;
- disabled = null;
- excludedIds = null;
- }
-
- protected void setProperties(UIComponent component)
- {
-
- super.setProperties(component);
-
- setStringProperty(component,"confirmationMessage",confirmationMessage);
- setBooleanProperty(component, "disabled", disabled);
- setStringProperty(component, "excludedIds", excludedIds);
-
+ disabled = null;
+ excludedIds = null;
}
- public void setConfirmationMessage(String confirmationMessage)
- {
+ public void setConfirmationMessage(String confirmationMessage) {
this.confirmationMessage = confirmationMessage;
}
- public void setDisabled(String disabled)
- {
+ public void setDisabled(String disabled) {
this.disabled = disabled;
}
- public void setExcludedIds(String excludedIds)
- {
+ public void setExcludedIds(String excludedIds) {
this.excludedIds = excludedIds;
+ }
+
+ protected void setProperties(UIComponent component) {
+
+ super.setProperties(component);
+
+ setStringProperty(component, "confirmationMessage", confirmationMessage);
+ setBooleanProperty(component, "disabled", disabled);
+ setStringProperty(component, "excludedIds", excludedIds);
+
}
}