You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2007/09/21 21:14:21 UTC

svn commit: r578234 - in /myfaces/tomahawk/trunk/sandbox/core/src: main/java/org/apache/myfaces/custom/subform/ main/tld/ site/xdoc/

Author: imario
Date: Fri Sep 21 12:14:21 2007
New Revision: 578234

URL: http://svn.apache.org/viewvc?rev=578234&view=rev
Log:
added "preserveSubmittedValues" attribute to allow to reflect any model update in the subform if another one has been submitted.
Default is true for backward compatibility

Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubForm.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormTag.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
    myfaces/tomahawk/trunk/sandbox/core/src/site/xdoc/subForm.xml

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubForm.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubForm.java?rev=578234&r1=578233&r2=578234&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubForm.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubForm.java Fri Sep 21 12:14:21 2007
@@ -20,12 +20,14 @@
 
 import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
 
+import javax.faces.component.EditableValueHolder;
 import javax.faces.component.NamingContainer;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIComponentBase;
 import javax.faces.context.FacesContext;
-import javax.faces.event.FacesEvent;
+import javax.faces.el.ValueBinding;
 import javax.faces.event.ActionEvent;
+import javax.faces.event.FacesEvent;
 import javax.faces.event.PhaseId;
 import java.util.Iterator;
 import java.util.List;
@@ -61,8 +63,9 @@
     private static final String PARTIAL_ENABLED = "org.apache.myfaces.IsPartialPhaseExecutionEnabled";
     private boolean _submitted;
 
+	private Boolean preserveSubmittedValues;
 
-    public SubForm()
+	public SubForm()
     {
         super.setRendererType(DEFAULT_RENDERER_TYPE);
     }
@@ -82,25 +85,75 @@
         _submitted = submitted;
     }
 
-    public void processValidators(FacesContext context)
-    {
-        if (context == null) throw new NullPointerException("context");
-        if (!isRendered()) return;
-
-        boolean partialEnabled = isPartialEnabled(context, PhaseId.PROCESS_VALIDATIONS);
-
-        if(partialEnabled || (_submitted && isEmptyList(context)))
-        {
-            for (Iterator it = getFacetsAndChildren(); it.hasNext(); )
-            {
-                UIComponent childOrFacet = (UIComponent)it.next();
-                childOrFacet.processValidators(context);
-            }
-        }
-        else
-        {
-            processSubFormValidators(this,context);
-        }
+	public Boolean getPreserveSubmittedValues()
+	{
+		if (preserveSubmittedValues != null)
+		{
+			return preserveSubmittedValues;
+		}
+
+		ValueBinding vb = getValueBinding("preserveSubmittedValues");
+
+		return (Boolean) ((vb != null) ? vb.getValue(getFacesContext()) : null);
+	}
+
+	public void setPreserveSubmittedValues(Boolean preserveSubmittedValues)
+	{
+		this.preserveSubmittedValues = preserveSubmittedValues;
+	}
+
+	public Object saveState(FacesContext context)
+	{
+		return new Object[]
+		{
+			super.saveState(context),
+			preserveSubmittedValues
+		};
+	}
+
+	public void restoreState(FacesContext context, Object state)
+	{
+		Object[] states = (Object[]) state;
+
+		super.restoreState(context, states[0]);
+		preserveSubmittedValues=(Boolean)states[1];
+	}
+
+
+	public void processDecodes(FacesContext context)
+	{
+		super.processDecodes(context);
+		if (!isRendered()) return;
+
+		if (!_submitted && Boolean.FALSE.equals(getPreserveSubmittedValues()))
+		{
+			// didn't find any better way as we do not know if we are submitted before the
+			// decode phase, but then all the other components have the submitted value
+			// set already.
+			// so lets reset them again ... boring hack.
+			resetSubmittedValues(this, context);
+		}
+	}
+
+	public void processValidators(FacesContext context)
+    {
+		if (context == null) throw new NullPointerException("context");
+		if (!isRendered()) return;
+
+		boolean partialEnabled = isPartialEnabled(context, PhaseId.PROCESS_VALIDATIONS);
+
+		if(partialEnabled || (_submitted && isEmptyList(context)))
+		{
+			for (Iterator it = getFacetsAndChildren(); it.hasNext(); )
+			{
+				UIComponent childOrFacet = (UIComponent)it.next();
+				childOrFacet.processValidators(context);
+			}
+		}
+		else
+		{
+			processSubFormValidators(this,context);
+		}
     }
 
     public void processUpdates(FacesContext context)
@@ -124,7 +177,27 @@
         }
     }
 
-    private static void processSubFormUpdates(UIComponent comp, FacesContext context)
+	private static void resetSubmittedValues(UIComponent comp, FacesContext context)
+	{
+		for (Iterator it = comp.getFacetsAndChildren(); it.hasNext(); )
+		{
+			UIComponent childOrFacet = (UIComponent)it.next();
+			if (childOrFacet instanceof SubForm)
+			{
+				// we are not responsible for this subForm, are we?
+				continue;
+			}
+
+			if (childOrFacet instanceof EditableValueHolder)
+			{
+				((EditableValueHolder) childOrFacet).setSubmittedValue(null);
+			}
+
+			resetSubmittedValues(childOrFacet, context);
+		}
+	}
+
+	private static void processSubFormUpdates(UIComponent comp, FacesContext context)
     {
         for (Iterator it = comp.getFacetsAndChildren(); it.hasNext(); )
         {

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java?rev=578234&r1=578233&r2=578234&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormRenderer.java Fri Sep 21 12:14:21 2007
@@ -18,16 +18,10 @@
  */
 package org.apache.myfaces.custom.subform;
 
-import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import java.io.IOException;
 import java.util.Map;
 
 /**

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormTag.java?rev=578234&r1=578233&r2=578234&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormTag.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/subform/SubFormTag.java Fri Sep 21 12:14:21 2007
@@ -18,16 +18,20 @@
  */
 package org.apache.myfaces.custom.subform;
 
-import javax.faces.webapp.UIComponentTag;
+import org.apache.myfaces.shared_tomahawk.taglib.UIComponentTagBase;
+
+import javax.faces.component.UIComponent;
 
 /**
  * @author Gerald Muellan
  *         Date: 19.01.2006
  *         Time: 14:01:07
  */
-public class SubFormTag extends UIComponentTag
+public class SubFormTag extends UIComponentTagBase
 {
-    public String getComponentType()
+	private String preserveSubmittedValues;
+
+	public String getComponentType()
     {
         return SubForm.COMPONENT_TYPE;
     }
@@ -36,4 +40,31 @@
     {
         return SubForm.DEFAULT_RENDERER_TYPE;
     }
+
+	public void release()
+	{
+		super.release();
+
+		preserveSubmittedValues = null;
+	}
+
+	protected void setProperties(UIComponent component)
+	{
+		super.setProperties(component);
+
+		if (preserveSubmittedValues != null)
+		{
+			setBooleanProperty(component, "preserveSubmittedValues", preserveSubmittedValues);
+		}
+	}
+
+	public String getPreserveSubmittedValues()
+	{
+		return preserveSubmittedValues;
+	}
+
+	public void setPreserveSubmittedValues(String preserveSubmittedValues)
+	{
+		this.preserveSubmittedValues = preserveSubmittedValues;
+	}
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld?rev=578234&r1=578233&r2=578234&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld Fri Sep 21 12:14:21 2007
@@ -692,7 +692,7 @@
 			<rtexprvalue>false</rtexprvalue>
 			<type>java.lang.String</type>
 			<description>
-				A value binding which will be called to get the instance of an org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer. 
+				A value binding which will be called to get the instance of an org.apache.myfaces.custom.graphicimagedynamic.ImageRenderer.
 			</description>
 		</attribute>
 
@@ -1061,6 +1061,15 @@
 			of this subform.
 		</description>
 		&ui_form_attributes;
+		<attribute>
+			<name>preserveSubmittedValues</name>
+			<required>false</required>
+			<rtexprvalue>false</rtexprvalue>
+			<description>
+				true|false - set to false if you submit other subforms and would like to have your subform
+				reflecting any model update. Default: true
+			</description>
+		</attribute>
 	</tag>
 
 	<!-- selectOneRow -->
@@ -1668,7 +1677,7 @@
         </description>
         &ui_component_attributes;
      </tag>
-     
+
     <tag>
         <name>limitRendered</name>
         <tag-class>org.apache.myfaces.custom.limitrendered.UILimitRenderedTag</tag-class>
@@ -1677,7 +1686,7 @@
         &ui_component_attributes;
         &ui_limitRendered_attributes;
     </tag>
-    
+
     <tag>
         <name>roundedDiv</name>
         <tag-class>org.apache.myfaces.custom.roundeddiv.HtmlRoundedDivTag</tag-class>
@@ -1690,98 +1699,98 @@
         &user_role_attributes;
         &html_roundeddiv_attributes;
     </tag>
-    
+
     <tag>
     <name>passwordStrength</name>
     <tag-class>org.apache.myfaces.custom.passwordStrength.PasswordStrengthTag</tag-class>
 	&standard_input_text_attributes;
-      <attribute> 
-         <name>preferredPasswordLength</name>    
-	     <required>true</required>          
+      <attribute>
+         <name>preferredPasswordLength</name>
+	     <required>true</required>
          <rtexprvalue>true</rtexprvalue>
 	     <type>java.lang.String</type>
-	     <description>The prefered length of the password</description>         
+	     <description>The prefered length of the password</description>
       </attribute>
-      <attribute> 
-         <name>textStrengthDescriptions</name>    
-	     <required>false</required>          
+      <attribute>
+         <name>textStrengthDescriptions</name>
+	     <required>false</required>
          <rtexprvalue>true</rtexprvalue>
 	     <type>java.lang.String</type>
-	     <description>The text strength descriptions</description>         
-      </attribute>      
-      <attribute> 
-         <name>prefixText</name>    
-	  	 <required>false</required>          
+	     <description>The text strength descriptions</description>
+      </attribute>
+      <attribute>
+         <name>prefixText</name>
+	  	 <required>false</required>
          <rtexprvalue>true</rtexprvalue>
 	     <type>java.lang.String</type>
-	     <description>The prefix of the component message</description>         
+	     <description>The prefix of the component message</description>
       </attribute>
-      <attribute> 
-         <name>showDetails</name>    
-	  	 <required>false</required>          
+      <attribute>
+         <name>showDetails</name>
+	  	 <required>false</required>
          <rtexprvalue>true</rtexprvalue>
 	     <type>java.lang.String</type>
-	      <description>This flag {true | false} determines whether to show the details (left characters). default is true</description>         
-      </attribute>  
-      <attribute> 
-         <name>strengthIndicatorType</name>    
-	  	 <required>false</required>          
+	      <description>This flag {true | false} determines whether to show the details (left characters). default is true</description>
+      </attribute>
+      <attribute>
+         <name>strengthIndicatorType</name>
+	  	 <required>false</required>
          <rtexprvalue>true</rtexprvalue>
 	     <type>java.lang.String</type>
-	      <description>This flag determines the indicator type. It can be {text or bar}. Default is text</description>         
-      </attribute>          
+	      <description>This flag determines the indicator type. It can be {text or bar}. Default is text</description>
+      </attribute>
 
 
-      <attribute> 
-         <name>useCustomSecurity</name>    
-	  	 <required>false</required>          
+      <attribute>
+         <name>useCustomSecurity</name>
+	  	 <required>false</required>
          <rtexprvalue>true</rtexprvalue>
-	     <type>java.lang.String</type>     
+	     <type>java.lang.String</type>
 	      <description>
-	      	This flag determines whether to user custom security rules instead 
+	      	This flag determines whether to user custom security rules instead
 	      	of just depending on the password length. The default is false.
-	      </description>	         
+	      </description>
       </attribute>
-      
-      <attribute> 
-         <name>customSecurityExpression</name>    
-	  	 <required>false</required>          
+
+      <attribute>
+         <name>customSecurityExpression</name>
+	  	 <required>false</required>
          <rtexprvalue>true</rtexprvalue>
 	     <type>java.lang.String</type>
 	      <description>
 	      		This string determines the expression of the custom security rule of the password
 				Note that the expression has the following format :
-				******************************************************* 
+				*******************************************************
 				S (Number)  N (Number) A (Number)
 				Where S stands for Symbols
 				Where N stands for Numbers
 				Where A stands for Alphabets
-				******************************************************* 
+				*******************************************************
 				For example) A4N2S3A2
 				Means that the password will be as following :
 				4 or more Alphabets followed by
 				2 or more Numbers followed by
 				3 or more Symbols followed by
 				2 or more Alphabets
-				******************************************************* 
-				Note also that the useCustomSecurity should be set to true.  		
-	      </description>         
-      </attribute>       
-      
-      
-      <attribute> 
-         <name>penaltyRatio</name>    
-	  	 <required>false</required>          
+				*******************************************************
+				Note also that the useCustomSecurity should be set to true.
+	      </description>
+      </attribute>
+
+
+      <attribute>
+         <name>penaltyRatio</name>
+	  	 <required>false</required>
          <rtexprvalue>true</rtexprvalue>
-	     <type>java.lang.String</type>     
+	     <type>java.lang.String</type>
 	      <description>
-	      	This attribute determines the penalty ratio that will decrease the password 
+	      	This attribute determines the penalty ratio that will decrease the password
 	      	Strength if the custom security expression is not met.
 			Note also that the useCustomSecurity should be set to true to apply this flag.
 			Possible values from 0 to 100.
 			Default value is 50.
-	      </description>	         
-      </attribute>        
-                           
+	      </description>
+      </attribute>
+
   </tag>
 </taglib>

Modified: myfaces/tomahawk/trunk/sandbox/core/src/site/xdoc/subForm.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/site/xdoc/subForm.xml?rev=578234&r1=578233&r2=578234&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/site/xdoc/subForm.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/site/xdoc/subForm.xml Fri Sep 21 12:14:21 2007
@@ -69,11 +69,17 @@
    </s:subForm>
    <t:commandButton value="Submit subForm" actionFor="subFormId"/>
 </h:form>]]></source>Submit from inside the subForm:<source
-    xml:space="preserve"><![CDATA[<h:form> 
-   <s:subForm id="subFormId"> 
+    xml:space="preserve"><![CDATA[<h:form>
+   <s:subForm id="subFormId">
        <h:inputText value="#{bean.value}" />
-       <t:commandButton value="Submit subForm"/> 
-   </s:subForm> 
+       <t:commandButton value="Submit subForm"/>
+   </s:subForm>
+</h:form>]]></source>Do not keep any entered value if submitted another subform<source
+    xml:space="preserve"><![CDATA[<h:form>
+   <s:subForm id="subFormId" preserveSubmittedValues="false">
+       <h:inputText value="#{bean.value}" />
+       <t:commandButton value="Submit subForm"/>
+   </s:subForm>
 </h:form>]]></source></section>
 
     <!-- Syntax -->