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/02/25 18:51:07 UTC
svn commit: r380961 - in
/myfaces/commons/trunk/src/main/java/org/apache/myfaces:
component/BindingAware.java util/RestoreStateUtils.java
Author: mmarinschek
Date: Sat Feb 25 09:51:06 2006
New Revision: 380961
URL: http://svn.apache.org/viewcvs?rev=380961&view=rev
Log:
fix for myfaces-334. Thanks to Mario Ivankovits for finding this solution. Spec bug will need to be fixed, then we'll be able to get rid of BindingAware interface
Added:
myfaces/commons/trunk/src/main/java/org/apache/myfaces/component/BindingAware.java
myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/RestoreStateUtils.java
Added: myfaces/commons/trunk/src/main/java/org/apache/myfaces/component/BindingAware.java
URL: http://svn.apache.org/viewcvs/myfaces/commons/trunk/src/main/java/org/apache/myfaces/component/BindingAware.java?rev=380961&view=auto
==============================================================================
--- myfaces/commons/trunk/src/main/java/org/apache/myfaces/component/BindingAware.java (added)
+++ myfaces/commons/trunk/src/main/java/org/apache/myfaces/component/BindingAware.java Sat Feb 25 09:51:06 2006
@@ -0,0 +1,6 @@
+package org.apache.myfaces.component;
+
+public interface BindingAware
+{
+ public void handleBindings();
+}
Added: myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/RestoreStateUtils.java
URL: http://svn.apache.org/viewcvs/myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/RestoreStateUtils.java?rev=380961&view=auto
==============================================================================
--- myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/RestoreStateUtils.java (added)
+++ myfaces/commons/trunk/src/main/java/org/apache/myfaces/util/RestoreStateUtils.java Sat Feb 25 09:51:06 2006
@@ -0,0 +1,65 @@
+package org.apache.myfaces.util;
+
+import org.apache.myfaces.component.BindingAware;
+
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+import javax.faces.el.ValueBinding;
+import java.util.Iterator;
+
+/**
+ * @author Martin Marinschek (latest modification by $Author: grantsmith $)
+ * @version $Revision: 169655 $ $Date: 2005-05-11 18:45:06 +0200 (Mi, 11 Mai 2005) $
+ */
+public class RestoreStateUtils
+{
+ /**
+ * Walk the component tree, executing any component-bindings to reattach
+ * components to their backing beans. Also, any UIInput component is
+ * marked as Valid.
+ * <p>
+ * Note that this method effectively breaks encapsulation; instead of
+ * asking each component to update itself and its children, this
+ * method just reaches into each component. That makes it impossible
+ * for any component to customise its behaviour at this point.
+ * <p>
+ * This has been filed as an issue against the spec. Until this
+ * issue is resolved, we'll add a new marker-interface for components
+ * to allow them to define their interest in handling children bindings themselves.
+ */
+ public static void recursivelyHandleComponentReferencesAndSetValid(FacesContext facesContext,
+ UIComponent parent)
+ {
+ recursivelyHandleComponentReferencesAndSetValid(facesContext, parent, false);
+ }
+
+ public static void recursivelyHandleComponentReferencesAndSetValid(FacesContext facesContext,
+ UIComponent parent, boolean forceHandle)
+ {
+ if(parent instanceof BindingAware && !forceHandle)
+ {
+ ((BindingAware) parent).handleBindings();
+ }
+ else
+ {
+ for (Iterator it = parent.getFacetsAndChildren(); it.hasNext(); )
+ {
+ UIComponent component = (UIComponent)it.next();
+
+ ValueBinding binding = component.getValueBinding("binding"); //TODO: constant
+ if (binding != null && !binding.isReadOnly(facesContext))
+ {
+ binding.setValue(facesContext, component);
+ }
+
+ if (component instanceof UIInput)
+ {
+ ((UIInput)component).setValid(true);
+ }
+
+ recursivelyHandleComponentReferencesAndSetValid(facesContext, component);
+ }
+ }
+ }
+}