You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2004/08/02 00:15:38 UTC

cvs commit: jakarta-tapestry/junit/src/org/apache/tapestry/junit/valid TestValidationDelegate.java

hlship      2004/08/01 15:15:38

  Modified:    framework/src/org/apache/tapestry/valid Tag: branch-3-0
                        ValidationDelegate.java IValidationDelegate.java
               .        Tag: branch-3-0 status.xml
               junit/src/org/apache/tapestry/junit/valid Tag: branch-3-0
                        TestValidationDelegate.java
  Log:
  Added a new method, clearErrors(), to IValidationDelegate.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.7.2.2   +24 -5     jakarta-tapestry/framework/src/org/apache/tapestry/valid/ValidationDelegate.java
  
  Index: ValidationDelegate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/valid/ValidationDelegate.java,v
  retrieving revision 1.7.2.1
  retrieving revision 1.7.2.2
  diff -u -r1.7.2.1 -r1.7.2.2
  --- ValidationDelegate.java	30 Jun 2004 15:35:19 -0000	1.7.2.1
  +++ ValidationDelegate.java	1 Aug 2004 22:15:38 -0000	1.7.2.2
  @@ -34,14 +34,16 @@
    *  details.
    *
    *  @author Howard Lewis Ship
  - *  @version $Id$
    *  @since 1.0.5
  - * 
  - **/
  + */
   
   public class ValidationDelegate implements IValidationDelegate
   {
       private IFormComponent _currentComponent;
  +
  +    /**
  +     * List of {@link FieldTracking}.
  +     */
       private List _trackings;
   
       /**
  @@ -49,7 +51,11 @@
        *  the trackings for one form, keyed on component name.  Care must
        *  be taken, because the inner Map is not always present.
        * 
  -     **/
  +     * <p>
  +     * Each ultimate {@link FieldTracking} object is also in the _trackings
  +     * list.
  +     * 
  +     */
   
       private Map _trackingMap;
   
  @@ -60,6 +66,19 @@
           _trackingMap = null;
       }
   
  +    public void clearErrors()
  +    {
  +        if (_trackings == null)
  +            return;
  +
  +        Iterator i = (Iterator) _trackings.iterator();
  +        while (i.hasNext())
  +        {
  +            FieldTracking ft = (FieldTracking) i.next();
  +			ft.setErrorRenderer(null);
  +        }
  +    }
  +
       /**
        *  If the form component is in error, places a &lt;font color="red"&lt; around it.
        *  Note: this will only work on the render phase after a rewind, and will be
  @@ -397,7 +416,7 @@
           // so assume it cannot have errors.
           if (form == null)
               return false;
  -        
  +
           String formName = form.getName();
           Map formMap = (Map) _trackingMap.get(formName);
   
  
  
  
  1.7.2.1   +16 -3     jakarta-tapestry/framework/src/org/apache/tapestry/valid/IValidationDelegate.java
  
  Index: IValidationDelegate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/valid/IValidationDelegate.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- IValidationDelegate.java	19 Feb 2004 17:38:03 -0000	1.7
  +++ IValidationDelegate.java	1 Aug 2004 22:15:38 -0000	1.7.2.1
  @@ -82,9 +82,7 @@
    *
    *
    *  @author Howard Lewis Ship
  - *  @version $Id$
  - *
  - **/
  + */
   
   public interface IValidationDelegate
   {
  @@ -153,6 +151,21 @@
        **/
   
       public void clear();
  +    
  +    /**
  +     * Clears all errors, but maintains user input. This is useful when a form
  +     * has been submitted for a semantic other than "process this data". A common example
  +     * of this is a dependent drop down list; selecting an option in one drop down list
  +     * forces a submit to repopulate the options in a second, dependent drop down list.
  +     * 
  +     * <p>
  +     * In these cases, the user input provided in the request is maintained, but any
  +     * errors should be cleared out (to prevent unwanted error messages and decorations).
  +     * 
  +     * @since 3.0.1
  +     */
  +    
  +    public void clearErrors();
   
       /**
        *  Records the user's input for the current form component.  Input should
  
  
  
  No                   revision
  No                   revision
  1.47.2.7  +3 -0      jakarta-tapestry/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/status.xml,v
  retrieving revision 1.47.2.6
  retrieving revision 1.47.2.7
  diff -u -r1.47.2.6 -r1.47.2.7
  --- status.xml	29 Jul 2004 15:14:41 -0000	1.47.2.6
  +++ status.xml	1 Aug 2004 22:15:38 -0000	1.47.2.7
  @@ -278,6 +278,9 @@
         Shell component should allow informal parameters
       </action>
       
  +    <action type="update" dev="HLS">
  +      Added a clearErrors() method to IValidationDelegate.
  +    </action>
     </release>	
      
    	<release version="3.0" date="Apr 18 2004">
  
  
  
  No                   revision
  No                   revision
  1.4.2.2   +48 -27    jakarta-tapestry/junit/src/org/apache/tapestry/junit/valid/TestValidationDelegate.java
  
  Index: TestValidationDelegate.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/junit/src/org/apache/tapestry/junit/valid/TestValidationDelegate.java,v
  retrieving revision 1.4.2.1
  retrieving revision 1.4.2.2
  diff -u -r1.4.2.1 -r1.4.2.2
  --- TestValidationDelegate.java	30 Jun 2004 15:35:19 -0000	1.4.2.1
  +++ TestValidationDelegate.java	1 Aug 2004 22:15:38 -0000	1.4.2.2
  @@ -155,42 +155,42 @@
           checkRender("Overload!", t1);
   
           checkRender("Overload!", d.getFirstError());
  -        
  +
           List trackings = d.getUnassociatedTrackings();
           assertEquals(1, trackings.size());
           assertEquals(t1, trackings.get(0));
  -        
  +
           trackings = d.getAssociatedTrackings();
           assertEquals(1, trackings.size());
           assertEquals(t0, trackings.get(0));
       }
  -    
  -	/**
  -	 * In rare cases, you may add errors even though the page hasn't rendered and that's
  -	 * was causing a NPE.
  -	 */
  +
  +    /**
  +     * In rare cases, you may add errors even though the page hasn't rendered and that's
  +     * was causing a NPE.
  +     */
       public void testComponentNotRecorded()
       {
  -    	// This mock field neaver rendered, so it does not have a Form-assigned name.
  -    	
  -		IFormComponent f = new MockField(null);
  -		
  -		d.setFormComponent(f);
  -		d.record("Never rendered.", ValidationConstraint.CONSISTENCY);
  -		
  -		assertEquals(true, d.getHasErrors());
  -		
  -		List fieldTracking = d.getFieldTracking();
  -		assertEquals(1, fieldTracking.size());
  -		
  -		List trackings = d.getUnassociatedTrackings();
  -		assertEquals(1, trackings.size());
  -		
  -		IFieldTracking t = (IFieldTracking)trackings.get(0);
  -		
  -		assertEquals(null, t.getComponent());
  -		assertEquals(true, t.isInError());
  -		checkRender("Never rendered.", t);
  +        // This mock field neaver rendered, so it does not have a Form-assigned name.
  +
  +        IFormComponent f = new MockField(null);
  +
  +        d.setFormComponent(f);
  +        d.record("Never rendered.", ValidationConstraint.CONSISTENCY);
  +
  +        assertEquals(true, d.getHasErrors());
  +
  +        List fieldTracking = d.getFieldTracking();
  +        assertEquals(1, fieldTracking.size());
  +
  +        List trackings = d.getUnassociatedTrackings();
  +        assertEquals(1, trackings.size());
  +
  +        IFieldTracking t = (IFieldTracking) trackings.get(0);
  +
  +        assertEquals(null, t.getComponent());
  +        assertEquals(true, t.isInError());
  +        checkRender("Never rendered.", t);
       }
   
       private void checkRender(String errorMessage, IFieldTracking tracking)
  @@ -286,5 +286,26 @@
   
           assertEquals(false, d.getHasErrors());
           assertNull(d.getFirstError());
  +    }
  +
  +    public void testClearErrors()
  +    {
  +        IFormComponent f = new MockField("input");
  +
  +        d.setFormComponent(f);
  +        d.recordFieldInputValue("hello");
  +        d.record("An error in the input field.", null);
  +
  +        assertEquals(true, d.getHasErrors());
  +
  +        assertNotNull(d.getFirstError());
  +
  +        d.clearErrors();
  +
  +        assertEquals(false, d.getHasErrors());
  +
  +        d.setFormComponent(f);
  +
  +        assertEquals("hello", d.getFieldInputValue());
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org