seade       2003/09/28 22:12:01

  Modified:    src/java/org/apache/turbine/services/intake/validator Tag:
                        TURBINE_2_3_BRANCH DateStringValidator.java
               xdocs    Tag: TURBINE_2_3_BRANCH changes.xml
               src/java/org/apache/turbine/services/intake/model Tag:
                        TURBINE_2_3_BRANCH Field.java
  Log:
  Intake now provides $group.foo.StringValue which DateStrng uses to provide the 
formatted date Strng value.
  DateString will use the "formatn" (where n >= 1) rules to parse the input and then 
the "format" rule to format it.
  Thanks to Colin Chalmers for contributing to this patch.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.7.2.3   +22 -5     
jakarta-turbine-2/src/java/org/apache/turbine/services/intake/validator/DateStringValidator.java
  
  Index: DateStringValidator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/validator/DateStringValidator.java,v
  retrieving revision 1.7.2.2
  retrieving revision 1.7.2.3
  diff -u -r1.7.2.2 -r1.7.2.3
  --- DateStringValidator.java  12 Sep 2003 00:21:37 -0000      1.7.2.2
  +++ DateStringValidator.java  29 Sep 2003 05:12:00 -0000      1.7.2.3
  @@ -77,7 +77,7 @@
    * <td>&nbsp;</td></tr>
    * <tr><td>formatx</td><td>see SimpleDateFormat javadoc</td>
    * <td>&nbsp;</td></tr>
  - * <tr><td colspan=3>where x is &gt;= 0 to specify multiple date
  + * <tr><td colspan=3>where x is &gt;= 1 to specify multiple date
    *         formats.  Only one format rule should have a message</td></tr>
    * <tr><td>flexible</td><td>true, as long as DateFormat can parse the date,
    *                            allow it, and false</td>
  @@ -88,6 +88,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Quinton McCombs</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Colin Chalmers</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">J&uuml;rgen Hoffmann</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Scott Eade</a>
    * @version $Id$
    */
   public class DateStringValidator
  @@ -209,8 +210,11 @@
       }
   
       /**
  -     * Parses the String s according to the rules/formats for this
  -     * validator.
  +     * Parses the String s according to the rules/formats for this validator.  
  +     * The formats provided by the "formatx" rules (where x is &gt;= 1) are 
  +     * used <strong>before</strong> the "format" rules to allow for a display 
  +     * format that includes a 4 digit year, but that will parse the date using
  +     * a format that accepts 2 digit years.
        *
        * @throws ParseException indicates that the string could not be
        * parsed into a date.
  @@ -225,7 +229,7 @@
               throw new ParseException("Input string was null", -1);
           }
   
  -        for (int i = 0; i < dateFormats.size() && date == null; i++)
  +        for (int i = 1; i < dateFormats.size() && date == null; i++)
           {
               sdf.applyPattern((String) dateFormats.get(i));
   
  @@ -237,7 +241,20 @@
               {
                   // ignore
               }
  +        }
  +
  +        if (date == null)
  +        {
  +            sdf.applyPattern((String) dateFormats.get(0));
   
  +            try
  +            {
  +                date = sdf.parse(s);
  +            }
  +            catch (ParseException e)
  +            {
  +                // ignore
  +            }
           }
   
           if (date == null && df != null)
  
  
  
  No                   revision
  No                   revision
  1.60.2.4  +9 -0      jakarta-turbine-2/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/xdocs/changes.xml,v
  retrieving revision 1.60.2.3
  retrieving revision 1.60.2.4
  diff -u -r1.60.2.3 -r1.60.2.4
  --- changes.xml       26 Sep 2003 00:39:18 -0000      1.60.2.3
  +++ changes.xml       29 Sep 2003 05:12:01 -0000      1.60.2.4
  @@ -81,6 +81,15 @@
          can later be enabled with field.setRequired(true) (i.e. you should 
          do this rather than using the deprecated required-message element).
       </li>
  +    <li>
  +       Intake was fixed so that DateString will use the "formatn" (where n 
  +       &gt;= 1) rules to parse the input and then the "format" rule to format 
  +       it (the "format" rule is also used to parse the date if there are no
  +       "formatn" rules or they are not able to parse it).  In order to 
  +       retrieve the correctly formatted DateString value you need to use
  +       <em>$group.foo.StringValue</em> rather than <em>$group.foo.Value</em> 
  +       (you can do this for all values, not just DateString).
  +    </li>
     </ul>
   </p>
   </subsection>
  
  
  
  No                   revision
  No                   revision
  1.15.2.2  +16 -1     
jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/Field.java
  
  Index: Field.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/model/Field.java,v
  retrieving revision 1.15.2.1
  retrieving revision 1.15.2.2
  diff -u -r1.15.2.1 -r1.15.2.2
  --- Field.java        26 Sep 2003 00:35:38 -0000      1.15.2.1
  +++ Field.java        29 Sep 2003 05:12:01 -0000      1.15.2.2
  @@ -996,4 +996,19 @@
           return (StringUtils.isEmpty(maxSize) ? "" : maxSize);
       }
   
  +    /**
  +     * Gets the String representation of the Value. This is basically a wrapper
  +     * method for the toString method which doesn't seem to show anything on
  +     * screen if accessed from Template. Name is also more in line with getValue
  +     * method which returns the actual Object.
  +     * This is useful for displaying correctly formatted data such as dates,
  +     * such as 18/11/1968 instead of the toString dump of a Date Object.
  +     *
  +     * @return the String Value
  +     */
  +    public String getStringValue()
  +    {
  +        return this.toString();   
  +    }
  +    
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to