You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by ma...@apache.org on 2006/10/31 22:58:27 UTC

svn commit: r469694 - in /incubator/adffaces/trunk/trinidad: trinidad-api/src/main/java/org/apache/myfaces/trinidad/validator/ trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/ trinidad-api/src/test/java/org/apache/myfaces/trinidad/valid...

Author: matzew
Date: Tue Oct 31 14:58:26 2006
New Revision: 469694

URL: http://svn.apache.org/viewvc?view=rev&rev=469694
Log:
added server side version of "dateRestrictionValidator" (see ADFFACES-258). doc and client-version is coming up next!

Added:
    incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidator.java
    incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidatorTest.java
    incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/validator/TestDateListProvider.java
    incubator/adffaces/trunk/trinidad/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/validators/trinidad/DateRestriction.xml
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/DateRestrictionValidatorBean.java
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/GermanHolidayDateListProvider.java
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/dateRestrictionValidate.jspx
Modified:
    incubator/adffaces/trunk/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/index.jspx

Added: incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidator.java?view=auto&rev=469694
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidator.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidator.java Tue Oct 31 14:58:26 2006
@@ -0,0 +1,534 @@
+/*
+ * Copyright  2004-2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.myfaces.trinidad.validator;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TimeZone;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.component.ValueHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.DateTimeConverter;
+import javax.faces.el.ValueBinding;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+import org.apache.myfaces.trinidad.bean.FacesBean;
+import org.apache.myfaces.trinidad.bean.PropertyKey;
+import org.apache.myfaces.trinidad.context.RequestContext;
+import org.apache.myfaces.trinidad.model.DateListProvider;
+import org.apache.myfaces.trinidad.util.ComponentUtils;
+import org.apache.myfaces.trinidad.util.MessageFactory;
+
+
+public class DateRestrictionValidator implements Validator, StateHolder {
+
+
+  public static final String VALIDATOR_ID = "org.apache.myfaces.trinidad.DateRestriction";
+  
+  /**
+   * <p>The message identifier of the {@link javax.faces.application.FacesMessage}
+   * to be created if the valid days  value check fails.  The message format
+   * string for this message may optionally include <code>{0}</code>,
+   * <code>{1}</code> and <code>{3}</code> placeholders,
+   * which will be replaced by user input, component label and configured
+   * days value.</p>
+   */
+  public static final String DAY_MESSAGE_ID =
+      "org.apache.myfaces.trinidad.validator.DateRestrictionValidator.DAY";
+
+  /**
+   * <p>The message identifier of the {@link javax.faces.application.FacesMessage}
+   * to be created if the valid month value check fails.  The message format
+   * string for this message may optionally include <code>{0}</code>,
+   * <code>{1}</code> and <code>{3}</code> placeholders,
+   * which will be replaced by user input, component label and configured
+   * month value.</p>
+   */
+  public static final String MONTH_MESSAGE_ID =
+      "org.apache.myfaces.trinidad.validator.DateRestrictionValidator.MONTH";
+
+  /**
+   * <p>The message identifier of the {@link javax.faces.application.FacesMessage}
+   * to be created if the valid weekdays value check fails.  The message format
+   * string for this message may optionally include <code>{0}</code>,
+   * <code>{1}</code> and <code>{3}</code> placeholders,
+   * which will be replaced by user input, component label and configured
+   * weekdays value.</p>
+   */
+  public static final String WEEKDAY_MESSAGE_ID =
+      "org.apache.myfaces.trinidad.validator.DateRestrictionValidator.WEEKDAY";
+
+  /**
+   * Construct a {@link Validator} with no preconfigured limits.
+   */
+  public DateRestrictionValidator()
+  {
+    super();
+    _initMaps();
+  }
+
+  public final String[] getInvalidMonths()
+  {
+    return (String[]) _facesBean.getProperty(_INVALID_MONTHS);
+  }
+
+  public final void setInvalidMonths(String[] invalidMonths)
+  {
+    _facesBean.setProperty(_INVALID_MONTHS, invalidMonths);
+  }
+  
+  public final String[] getInvalidDaysOfWeek()
+  {
+    return (String[]) _facesBean.getProperty(_INVALID_DAYS_OF_WEEK);  }
+
+  public final void setInvalidDaysOfWeek(String[] invalidDaysOfWeek)
+  {
+    _facesBean.setProperty(_INVALID_DAYS_OF_WEEK, invalidDaysOfWeek);
+  }
+  
+  public final DateListProvider getInvalidDays()
+  {
+    return (DateListProvider)_facesBean.getProperty(_INVALID_DAYS);
+  }
+
+  public final void setInvalidDays(DateListProvider invalidDays)
+  {
+    _facesBean.setProperty(_INVALID_DAYS, invalidDays);
+  }
+  
+  public final String getMessageDetailInvalidMonths()
+  {
+    Object messageDetailInvalidMonths = _facesBean.getProperty(_INVALID_MONTHS_MESSAGE_DETAIL_KEY);
+    return ComponentUtils.resolveString(messageDetailInvalidMonths);
+  }
+
+  public final void setMessageDetailInvalidMonths(String invalidMonths)
+  {
+    _facesBean.setProperty(_INVALID_MONTHS_MESSAGE_DETAIL_KEY, invalidMonths);
+  }
+  
+  public final String getMessageDetailInvalidDaysOfWeek()
+  {
+    Object messageDetailInvalidDaysOfWeek = _facesBean.getProperty(_INVALID_DAYS_OF_WEEK_MESSAGE_DETAIL_KEY);
+    return ComponentUtils.resolveString(messageDetailInvalidDaysOfWeek);
+  }
+
+  public final void setMessageDetailInvalidDaysOfWeek(String invalidDaysOfWeek)
+  {
+    _facesBean.setProperty(_INVALID_DAYS_OF_WEEK_MESSAGE_DETAIL_KEY, invalidDaysOfWeek);
+  }
+  
+  public final String getMessageDetailInvalidDays()
+  {
+    Object messageDetailInvalidDays = _facesBean.getProperty(_INVALID_DAYS_MESSAGE_DETAIL_KEY);
+    return ComponentUtils.resolveString(messageDetailInvalidDays);
+  }
+
+  public final void setMessageDetailInvalidDays(String invalidDays)
+  {
+    _facesBean.setProperty(_INVALID_DAYS_MESSAGE_DETAIL_KEY, invalidDays);
+  }
+
+  /**
+   * @exception NullPointerException {@inheritDoc}
+   * @exception ValidatorException {@inheritDoc}
+   * @exception IllegalArgumentException if <code>value</code> is not of type
+   * {@link java.util.Date}
+   */
+  public void validate(
+    FacesContext context,
+    UIComponent  component,
+    Object       value) throws ValidatorException
+  {
+    if ((context == null) || (component == null))
+    {
+      throw new NullPointerException("FacesContext or Component is null");
+    }
+
+    if (value != null)
+    {
+      TimeZone tz = null;
+      RequestContext rctx = RequestContext.getCurrentInstance();
+      if (rctx != null)
+      {
+        tz = rctx.getTimeZone();
+      }
+      else
+      {
+        tz = TimeZone.getDefault();
+      }
+      Calendar calendar = Calendar.getInstance(tz);
+      calendar.setTime(_getDateValue(value));
+      Date convertedDate = calendar.getTime();
+      
+      String weekday = _dayMap.get(calendar.get(Calendar.DAY_OF_WEEK));
+      if (_getInvalidDaysOfWeek().contains(weekday))
+      {
+        throw new ValidatorException(
+            _getWrongWeekDayMessage(context, component, value, weekday));
+      }
+      
+      String month = _monthMap.get(calendar.get(Calendar.MONTH));
+      if ( _getInvalidMonths().contains(month))
+      {
+        throw new ValidatorException(
+            _getWrongMonthMessage(context, component, value, month));
+      }
+      
+      DateListProvider dlp = getInvalidDays();
+      List<Date> dates = null;
+      if (dlp != null)
+      {
+        dates = dlp.getDateList(context, calendar, calendar.getTime(), calendar.getTime());
+      }
+      
+      if(dates!=null)
+      {
+        for (Date date : dates)
+        {
+          //range is only one submitted day...
+          if(!date.before(convertedDate) && !date.after(convertedDate))
+          {
+            throw new ValidatorException(
+                _getWrongDayMessage(context, component, value, date));
+          }
+        }
+      }
+    }
+  }
+
+  //  StateHolder Methods
+  public Object saveState(FacesContext context)
+  {
+    return _facesBean.saveState(context);
+  }
+
+
+  public void restoreState(FacesContext context, Object state)
+  {
+    _facesBean.restoreState(context, state);
+  }
+
+  public boolean isTransient()
+  {
+    return (_transientValue);
+  }
+
+
+  public void setTransient(boolean transientValue)
+  {
+    _transientValue = transientValue;
+  }
+  //  End of StateHolder Methods
+
+  /**
+   * <p>Set the {@link ValueBinding} used to calculate the value for the
+   * specified attribute if any.</p>
+   *
+   * @param name Name of the attribute for which to set a {@link ValueBinding}
+   * @param binding The {@link ValueBinding} to set, or <code>null</code>
+   *  to remove any currently set {@link ValueBinding}
+   *
+   * @exception NullPointerException if <code>name</code>
+   *  is <code>null</code>
+   * @exception IllegalArgumentException if <code>name</code> is not a valid
+   *            attribute of this validator
+   */
+  public void setValueBinding(String name, ValueBinding binding)
+  {
+    ValidatorUtils.setValueBinding(_facesBean, name, binding) ;
+  }
+
+  /**
+   * <p>Return the {@link ValueBinding} used to calculate the value for the
+   * specified attribute name, if any.</p>
+   *
+   * @param name Name of the attribute or property for which to retrieve a
+   *  {@link ValueBinding}
+   *
+   * @exception NullPointerException if <code>name</code>
+   *  is <code>null</code>
+   * @exception IllegalArgumentException if <code>name</code> is not a valid
+   * attribute of this validator
+   */
+  public ValueBinding getValueBinding(String name)
+  {
+    return ValidatorUtils.getValueBinding(_facesBean, name);
+  }
+
+  @Override
+  public boolean equals(Object o)
+  {
+    if ( o instanceof DateRestrictionValidator)
+    {
+      DateRestrictionValidator that = (DateRestrictionValidator)o;
+
+      if ( _transientValue == that._transientValue &&
+           (ValidatorUtils.equals(getInvalidDays(), that.getInvalidDays())) &&
+           (ValidatorUtils.equals(getInvalidDaysOfWeek(), that.getInvalidDaysOfWeek())) &&
+           (ValidatorUtils.equals(getInvalidMonths(), that.getInvalidMonths())) &&
+           (ValidatorUtils.equals(getMessageDetailInvalidDays(),
+                                   that.getMessageDetailInvalidDays())) &&
+           (ValidatorUtils.equals(getMessageDetailInvalidDaysOfWeek(),
+                                   that.getMessageDetailInvalidDaysOfWeek())) &&
+           (ValidatorUtils.equals(getMessageDetailInvalidMonths(),
+                                   that.getMessageDetailInvalidMonths()))
+          )
+      {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  @Override
+  public int hashCode()
+  {
+    int result = 17;
+    Object days = getInvalidDays();
+    Object daysOfWeek = getInvalidDaysOfWeek();
+    Object month = getInvalidMonths();
+    Object msgDetDays = getMessageDetailInvalidDays();
+    Object msgDetDaysOfWeek = getMessageDetailInvalidDaysOfWeek();
+    Object msgDetMonth = getMessageDetailInvalidMonths();
+
+    result = 37 * result + ( days == null ? 0 : days.hashCode());
+    result = 37 * result + ( daysOfWeek == null ? 0 : daysOfWeek.hashCode());
+    result = 37 * result + ( month == null ? 0 : month.hashCode());
+    result = 37 * result + ( _transientValue ? 0 : 1);
+    result = 37 * result + ( msgDetDays == null ? 0: msgDetDays.hashCode());
+    result = 37 * result + ( msgDetDaysOfWeek == null ? 0: msgDetDaysOfWeek.hashCode());
+    result = 37 * result + ( msgDetMonth == null ? 0: msgDetMonth.hashCode());
+    return result;
+  }
+
+
+  private Converter _getConverter(
+    FacesContext context,
+    UIComponent component)
+  {
+    Converter converter = null;
+    if (component instanceof ValueHolder)
+    {
+      converter = ((ValueHolder) component).getConverter();
+    }
+
+    if (converter == null)
+    {
+      // Use the DateTimeConverter's CONVERTER_ID, not Date.class,
+      // because there is in fact not usually a converter registered
+      // at Date.class
+      converter = context.getApplication().createConverter(
+                      DateTimeConverter.CONVERTER_ID);
+    }
+
+    assert(converter != null);
+
+    return converter;
+  }
+
+  /**
+   * Parses the already converted value to a <code>java.util.Date</code>.
+   * @param value converted value
+   * @return fulltyped <code>java.util.Date</code>
+   * @throws IllegalArgumentException
+   */
+  private static Date _getDateValue(
+      Object value) throws IllegalArgumentException
+    {
+      if (value instanceof Date)
+      {
+        return ( (Date)value );
+      }
+
+      throw new IllegalArgumentException("'value' is not of type java.util.Date");
+    }
+
+  private FacesMessage _getWrongWeekDayMessage(
+      FacesContext context,
+      UIComponent component,
+      Object value,
+      Object weekday)
+  { 
+      Converter converter = _getConverter(context, component);
+
+      Object cValue = _getConvertedValue(context, component, converter, value);
+      Object cWeekday   = _getConvertedValue(context, component, converter, weekday);
+
+      Object msg   = _getRawInvalidDaysOfWeekMessageDetail();
+      Object label = ValidatorUtils.getComponentLabel(component);
+
+      Object[] params = {label, cValue, cWeekday};
+
+      return MessageFactory.getMessage(context, WEEKDAY_MESSAGE_ID,
+                                        msg, params, component);
+  }
+  private Object _getRawInvalidDaysOfWeekMessageDetail()
+  {
+    return _facesBean.getRawProperty(_INVALID_DAYS_OF_WEEK_MESSAGE_DETAIL_KEY);
+  }
+
+  private FacesMessage _getWrongMonthMessage(
+      FacesContext context,
+      UIComponent component,
+      Object value,
+      Object weekday)
+  { 
+      Converter converter = _getConverter(context, component);
+
+      Object cValue = _getConvertedValue(context, component, converter, value);
+      Object cWeekday   = _getConvertedValue(context, component, converter, weekday);
+
+      Object msg   = _getRawInvalidMonthMessageDetail();
+      Object label = ValidatorUtils.getComponentLabel(component);
+
+      Object[] params = {label, cValue, cWeekday};
+
+      return MessageFactory.getMessage(context, MONTH_MESSAGE_ID,
+                                        msg, params, component);
+  }
+  private Object _getRawInvalidMonthMessageDetail()
+  {
+    return _facesBean.getRawProperty(_INVALID_MONTHS_MESSAGE_DETAIL_KEY);
+  }
+
+  private FacesMessage _getWrongDayMessage(
+      FacesContext context,
+      UIComponent component,
+      Object value,
+      Object weekday)
+  { 
+      Converter converter = _getConverter(context, component);
+
+      Object cValue = _getConvertedValue(context, component, converter, value);
+      Object cWeekday   = _getConvertedValue(context, component, converter, weekday);
+
+      Object msg   = _getRawInvalidDaysMessageDetail();
+      Object label = ValidatorUtils.getComponentLabel(component);
+
+      Object[] params = {label, cValue, cWeekday};
+
+      return MessageFactory.getMessage(context, DAY_MESSAGE_ID,
+                                        msg, params, component);
+  }
+  private Object _getRawInvalidDaysMessageDetail()
+  {
+    return _facesBean.getRawProperty(_INVALID_DAYS_MESSAGE_DETAIL_KEY);
+  }
+
+  private Object _getConvertedValue(
+    FacesContext context,
+    UIComponent  component,
+    Converter    converter,
+    Object       value)
+  {
+    return converter.getAsString(context, component, value);
+  }
+
+  private final Set<String> _getInvalidMonths()
+  {
+    Set<String> monthSet = new HashSet<String>();
+    String[] month = getInvalidMonths();
+    if(month != null){
+      
+      for (int i = 0; i < month.length; i++)
+      {
+        monthSet.add(month[i].toLowerCase());
+      }
+    }
+      
+    return monthSet;
+  }
+
+  private final Set<String> _getInvalidDaysOfWeek()
+  {
+    Set<String> daysOfWeekSet = new HashSet<String>();
+    String[] daysOfWeek = getInvalidDaysOfWeek();
+    if(daysOfWeek != null){
+      
+      for (int i = 0; i < daysOfWeek.length; i++)
+      {
+        daysOfWeekSet.add(daysOfWeek[i].toLowerCase());
+      }
+    }
+      
+    return daysOfWeekSet;
+  }
+
+  private void _initMaps()
+  {
+    _dayMap = new HashMap<Integer, String>();
+    _dayMap.put(Calendar.SUNDAY, "sun");
+    _dayMap.put(Calendar.MONDAY, "mon");
+    _dayMap.put(Calendar.TUESDAY, "tue");
+    _dayMap.put(Calendar.WEDNESDAY, "wed");
+    _dayMap.put(Calendar.THURSDAY, "thu");
+    _dayMap.put(Calendar.FRIDAY, "fri");
+    _dayMap.put(Calendar.SATURDAY, "sat");
+    
+    _monthMap = new HashMap<Integer, String>();
+    _monthMap.put(Calendar.JANUARY, "jan");
+    _monthMap.put(Calendar.FEBRUARY, "feb");
+    _monthMap.put(Calendar.MARCH, "mar");
+    _monthMap.put(Calendar.APRIL, "apr");
+    _monthMap.put(Calendar.MAY, "may");
+    _monthMap.put(Calendar.JUNE, "jun");
+    _monthMap.put(Calendar.JULY, "jul");
+    _monthMap.put(Calendar.AUGUST, "aug");
+    _monthMap.put(Calendar.SEPTEMBER, "sep");
+    _monthMap.put(Calendar.OCTOBER, "oct");
+    _monthMap.put(Calendar.NOVEMBER, "nov");
+    _monthMap.put(Calendar.DECEMBER, "dec");
+  }
+  
+  private static final FacesBean.Type _TYPE = new FacesBean.Type();
+
+  private static final PropertyKey _INVALID_MONTHS =
+    _TYPE.registerKey("invalidMonths", String[].class);
+
+  private static final PropertyKey _INVALID_DAYS_OF_WEEK =
+    _TYPE.registerKey("invalidDaysOfWeek", String[].class);
+
+  private static final PropertyKey _INVALID_DAYS =
+    _TYPE.registerKey("invalidDays", DateListProvider.class);
+
+  private static final PropertyKey _INVALID_MONTHS_MESSAGE_DETAIL_KEY =
+    _TYPE.registerKey("messageDetailInvalidMonths", String.class);
+
+  private static final PropertyKey _INVALID_DAYS_OF_WEEK_MESSAGE_DETAIL_KEY =
+    _TYPE.registerKey("messageDetailInvalidDaysOfWeek", String.class);
+
+  private static final PropertyKey _INVALID_DAYS_MESSAGE_DETAIL_KEY =
+    _TYPE.registerKey("messageDetailInvalidDays", String.class);
+
+  private FacesBean _facesBean = ValidatorUtils.getFacesBean(_TYPE);
+
+  private boolean _transientValue = false;
+  
+  private Map<Integer, String> _dayMap = null;
+  private Map<Integer, String> _monthMap = null;
+}
\ No newline at end of file

Modified: incubator/adffaces/trunk/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts?view=diff&rev=469694&r1=469693&r2=469694
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts Tue Oct 31 14:58:26 2006
@@ -112,6 +112,13 @@
   <resource key="org.apache.myfaces.trinidad.DateTimeRange">Wrong date.</resource>
   <resource key="org.apache.myfaces.trinidad.DateTimeRange_detail">Value "{1}" fit's not into the desired date range.</resource>
 
+  <!-- {0} the label that identifies the component  -->
+  <!-- {1} value entered by the user                -->
+  <!-- NOTE: The format of this message must match the format of the    -->
+  <!-- general javascript messages (see  VALIDATION_ALERT_FORMAT below) -->
+  <resource key="org.apache.myfaces.trinidad.DateRestriction">Wrong date.</resource>
+  <resource key="org.apache.myfaces.trinidad.DateRestriction_detail">Value "{1}" is not a valid date. Check the given restrictions.</resource>
+
   <!-- E.g. for input value "test" and maximum value set to "3" -->
   <!--      the message would be:                               -->
   <!-- The length of the value entered, "test", exceeds the     -->
@@ -152,6 +159,34 @@
   <resource key="org.apache.myfaces.trinidad.validator.DateTimeRangeValidator.NOT_IN_RANGE">Date is not within valid range.</resource>
 
   <resource key="org.apache.myfaces.trinidad.validator.DateTimeRangeValidator.NOT_IN_RANGE_detail">The date entered, "{1}", is not within the range of valid dates {2} and {3}.</resource>
+
+  <!-- Date exceeds date range error               -->
+  <!-- {0} the label that identifies the component -->
+  <!-- {1} value entered by the user               -->
+  <!-- {2} represents the maximum allowed date     -->
+  <resource
+    key="org.apache.myfaces.trinidad.validator.DateRestrictionValidator.DAY">Date is not allowed.</resource>
+
+  <resource
+    key="org.apache.myfaces.trinidad.validator.DateRestrictionValidator.DAY_detail">The date entered, "{1}" is not allowed.</resource>
+
+  <!-- Date preceeds date range error                -->
+  <!-- {0} the label that identifies the component   -->
+  <!-- {1} represent Date which the user has set     -->
+  <!-- {2} represents the minimum allowed date       -->
+  <resource
+     key="org.apache.myfaces.trinidad.validator.DateRestrictionValidator.MONTH">Date is not in a valid month.</resource>
+  <resource
+    key="org.apache.myfaces.trinidad.validator.DateRestrictionValidator.MONTH_detail">The date entered, "{1}", is inside the month {2}.</resource>
+
+  <!-- Date outside date range error               -->
+  <!-- {0} the label that identifies the component -->
+  <!-- {1} value entered by the user               -->
+  <!-- {2} represents the minimum allowed date     -->
+  <!-- {3} represents the maximum allowed date     -->
+  <resource key="org.apache.myfaces.trinidad.validator.DateRestrictionValidator.WEEKDAY">Date is not within a valid weekday.</resource>
+
+  <resource key="org.apache.myfaces.trinidad.validator.DateRestrictionValidator.WEEKDAY_detail">The date entered, "{1}", is a {2} and therefor not valid.</resource>
 
   <!-- Number exceeds number range error               -->
   <!-- {0} the label that identifies the component -->

Added: incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidatorTest.java?view=auto&rev=469694
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidatorTest.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidatorTest.java Tue Oct 31 14:58:26 2006
@@ -0,0 +1,308 @@
+/*
+ * Copyright 2004,2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.trinidad.validator;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.convert.DateTimeConverter;
+import javax.faces.validator.ValidatorException;
+import javax.faces.component.UIComponent;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.myfaces.trinidadbuild.test.MockUIComponentWrapper;
+import org.apache.shale.test.mock.MockApplication;
+import org.jmock.Mock;
+
+/**
+ * Unit tests for DateRestrictionValidator.
+ *
+ * @author Matthias Wessendorf
+ */
+public class DateRestrictionValidatorTest extends ValidatorTestCase
+{
+  /**
+   * Creates a new DateTimeRangeValidatorTest.
+   *
+   * @param testName  the unit test name
+   */
+  public DateRestrictionValidatorTest(
+    String testName)
+  {
+    super(testName);
+  }
+  
+  @Override
+  protected void setUp() throws Exception
+  {
+    super.setUp();
+  }
+  
+  @Override
+  protected void tearDown() throws Exception
+  {
+    super.tearDown();
+  }
+  
+  public static Test suite()
+  {
+    return new TestSuite(DateRestrictionValidatorTest.class);
+  }
+
+  /**
+   * Tests that null returns immediately.
+   *
+   * @throws ValidatorException  when test fails
+   */
+  public void testNull() throws ValidatorException
+  {
+    DateRestrictionValidator validator = new DateRestrictionValidator();
+
+    Mock mock = buildMockUIComponent();
+    UIComponent component = (UIComponent) mock.proxy();
+    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
+    doTestNull(facesContext, wrapper, validator);
+  }
+
+   /**
+   * Test when context is set to null
+   */
+  public void testNullContext()
+  {
+    Mock mock = buildMockUIComponent();
+    UIComponent component = (UIComponent) mock.proxy();
+    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
+    DateRestrictionValidator validator = new DateRestrictionValidator();
+
+    doTestNullContext(wrapper, validator);
+  }
+
+  /**
+   * Test null value for component.
+   */
+  public void testNullComponent()
+  {
+    DateRestrictionValidator validator = new DateRestrictionValidator();
+
+    doTestNullComponent(facesContext, validator);
+  }
+
+  /**
+   * Tests that non Date objects throw a ValidationException.
+   */
+  public void testNonDate()
+  {
+    DateRestrictionValidator validator = new DateRestrictionValidator();
+
+    Mock mock = buildMockUIComponent();
+    UIComponent component = (UIComponent) mock.proxy();
+    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
+
+    mock.stubs().method("getId").will(returnValue("test"));
+    try
+    {
+      setFacesContext(facesContext);
+      validator.validate(facesContext, component, "not-a-date");
+      fail("ValidatorException not thrown");
+    }
+    catch (IllegalArgumentException iae)
+    {
+      // pass
+    }
+    finally
+    {
+      setFacesContext(null);
+    }
+    mock.verify();
+  }
+
+  protected void setMockCreateConverter(MockApplication app)
+  {
+    DateTimeConverter dtc = new DateTimeConverter();
+    app.addConverter(DateTimeConverter.CONVERTER_ID, dtc.getClass().getName());
+  }
+  
+  /**
+   * Tests that invalid day, like Fri or Sun cause a ValidationException.
+   */
+  public void testInvalidDaysOfWeek()
+  {
+    DateRestrictionValidator validator = new DateRestrictionValidator();
+    validator.setInvalidDaysOfWeek(new String[] {"mon", "Sun"});
+
+    Mock mock = buildMockUIComponent();
+    UIComponent component = (UIComponent) mock.proxy();
+    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
+    setMockLabelForComponent(wrapper);
+    
+    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
+    Date dateToValidate = null;
+    
+    try
+    {
+      dateToValidate = sdf.parse("30.10.2006");
+    }
+    catch (ParseException e1)
+    {
+    }
+
+    setMockCreateConverter(application);
+    try
+    {
+      setFacesContext(facesContext);
+      validator.validate(facesContext, component, dateToValidate);
+      fail("ValidatorException not thrown");
+    }
+    catch (ValidatorException e)
+    {
+      // pass
+//      String msg = e.getFacesMessage().getDetail();
+//      assertEquals(msg, "max set");
+      
+      FacesMessage msg = e.getFacesMessage();
+      assertNotNull(msg);
+      
+    }
+    finally
+    {
+      setFacesContext(null);
+    }
+  }
+
+  /**
+   * Tests that invalid day, like Fri or Sun cause a ValidationException.
+   */
+  public void testInvalidMonth()
+  {
+    
+    DateRestrictionValidator validator = new DateRestrictionValidator();
+    validator.setInvalidMonths(new String[] {"Jan", "Oct"});
+
+    Mock mock = buildMockUIComponent();
+    UIComponent component = (UIComponent) mock.proxy();
+    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
+    setMockLabelForComponent(wrapper);
+    
+    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
+    Date dateToValidate = null;
+    
+    try
+    {
+      dateToValidate = sdf.parse("30.10.2006");
+    }
+    catch (ParseException e1)
+    {
+    }
+
+    setMockCreateConverter(application);
+    try
+    {
+      setFacesContext(facesContext);
+      validator.validate(facesContext, component, dateToValidate);
+      fail("ValidatorException not thrown");
+    }
+    catch (ValidatorException e)
+    {
+      // pass
+//      String msg = e.getFacesMessage().getDetail();
+//      assertEquals(msg, "max set");
+      
+      FacesMessage msg = e.getFacesMessage();
+      assertNotNull(msg);
+      
+    }
+    finally
+    {
+      setFacesContext(null);
+    }
+  }
+
+  /**
+   * Tests that invalid day, like Fri or Sun cause a ValidationException.
+   */
+  public void testInvalidDays()
+  {
+    
+    DateRestrictionValidator validator = new DateRestrictionValidator();
+    TestDateListProvider tdlp = new TestDateListProvider();
+    validator.setInvalidDays(tdlp);
+
+    Mock mock = buildMockUIComponent();
+    UIComponent component = (UIComponent) mock.proxy();
+    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
+    setMockLabelForComponent(wrapper);
+    
+    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
+    Date dateToValidate = null;
+    
+    try
+    {
+      dateToValidate = sdf.parse("15.05.2007");
+    }
+    catch (ParseException e1)
+    {
+    }
+
+    setMockCreateConverter(application);
+    try
+    {
+      setFacesContext(facesContext);
+      validator.validate(facesContext, component, dateToValidate);
+      fail("ValidatorException not thrown");
+    }
+    catch (ValidatorException e)
+    {
+      // pass
+//      String msg = e.getFacesMessage().getDetail();
+//      assertEquals(msg, "max set");
+      
+      FacesMessage msg = e.getFacesMessage();
+      assertNotNull(msg);
+      
+    }
+    finally
+    {
+      setFacesContext(null);
+    }
+  }
+
+  public void testStateHolderSaveRestore()
+  {
+    long millis = System.currentTimeMillis();
+    DateRestrictionValidator originalValidator = new DateRestrictionValidator();
+    
+    originalValidator.setInvalidDaysOfWeek(new String[]{"MO", "DI"});
+    originalValidator.setInvalidMonths(new String[]{"MO", "DI"});
+
+    originalValidator.setMessageDetailInvalidDays("min");
+    originalValidator.setMessageDetailInvalidDaysOfWeek("max");
+    originalValidator.setMessageDetailInvalidMonths("not in range");
+
+    Mock mock = buildMockUIComponent();
+    UIComponent component = (UIComponent) mock.proxy();
+    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
+
+    DateRestrictionValidator restoredValidator = new DateRestrictionValidator();
+
+    doTestStateHolderSaveRestore(originalValidator, restoredValidator,
+                                 facesContext, wrapper);
+  }
+
+}
\ No newline at end of file

Added: incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/validator/TestDateListProvider.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/validator/TestDateListProvider.java?view=auto&rev=469694
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/validator/TestDateListProvider.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-api/src/test/java/org/apache/myfaces/trinidad/validator/TestDateListProvider.java Tue Oct 31 14:58:26 2006
@@ -0,0 +1,60 @@
+package org.apache.myfaces.trinidad.validator;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.trinidad.model.DateListProvider;
+
+public class TestDateListProvider implements DateListProvider
+{
+  
+  List<Date> germanHolidays = null;
+  
+  public TestDateListProvider()
+  {
+    germanHolidays = new ArrayList<Date>();
+    germanHolidays.add(newDate("01.01.2007"));
+    germanHolidays.add(newDate("01.05.2007"));
+    germanHolidays.add(newDate("15.05.2007"));
+  }
+  
+
+  private Date newDate(String string)
+  {
+    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
+    Date ret = null;
+    try
+    {
+      ret = sdf.parse(string);
+    } catch (ParseException e)
+    {
+      e.printStackTrace();
+    }
+    return ret;
+  }
+
+
+  public List<Date> getDateList(FacesContext context, Calendar base,
+      Date rangeStart, Date rangeEnd)
+  {
+    
+    List<Date> returnDates = new ArrayList<Date>();
+    
+    for (Date it : germanHolidays)
+    {
+      if(!it.before(rangeStart) && !it.after(rangeEnd)){
+        base.setTime(it);
+        returnDates.add(base.getTime());
+      }
+    }
+    
+    return returnDates;
+  }
+
+}

Added: incubator/adffaces/trunk/trinidad/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/validators/trinidad/DateRestriction.xml
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/validators/trinidad/DateRestriction.xml?view=auto&rev=469694
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/validators/trinidad/DateRestriction.xml (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/validators/trinidad/DateRestriction.xml Tue Oct 31 14:58:26 2006
@@ -0,0 +1,96 @@
+<?xml version="1.0" ?>
+<!--
+  Copyright 2006 The Apache Software Foundation.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
+              xmlns:tr="http://myfaces.apache.org/trinidad"
+              xmlns:mfp="http://myfaces.apache.org/maven-faces-plugin">
+  <validator>
+    <description><![CDATA[Validate that the date entered is within a given range.]]></description>
+    <display-name>validateDateRestriction</display-name>
+    <validator-id>org.apache.myfaces.trinidad.DateRestriction</validator-id>
+    <validator-class>org.apache.myfaces.trinidadinternal.validator.DateRestrictionValidator</validator-class>
+    <property>
+      <description><![CDATA[the .]]>
+      </description>
+      <property-name>invalidMonths</property-name>
+      <property-class>java.lang.String[]</property-class>
+      <property-extension/>
+    </property>
+    
+    <property>
+      <description><![CDATA[the .]]>
+      </description>
+      <property-name>invalidDaysOfWeek</property-name>
+      <property-class>java.lang.String[]</property-class>
+      <property-extension/>
+    </property>
+    
+    <property>
+      <description><![CDATA[the .]]>
+      </description>
+      <property-name>invalidDays</property-name>
+      <property-class>org.apache.myfaces.trinidad.model.DateListProvider</property-class>
+      <property-extension/>
+    </property>
+    
+    <property>
+      <description><![CDATA[<p>
+           The detail error message to be used for constructing faces messages,
+          </p>]]>
+      </description>
+      <property-name>messageDetailInvalidMonths</property-name>
+      <property-class>java.lang.String</property-class>
+      <property-extension>
+        <mfp:property-metadata>
+          <mfp:preferred>true</mfp:preferred>
+        </mfp:property-metadata>
+      </property-extension>
+    </property>
+    <property>
+      <description><![CDATA[<p>
+           The detail error message to be used for constructing faces messages,
+          </p>]]>
+      </description>
+      <property-name>messageDetailInvalidDaysOfWeek</property-name>
+      <property-class>java.lang.String</property-class>
+      <property-extension>
+        <mfp:property-metadata>
+          <mfp:preferred>true</mfp:preferred>
+        </mfp:property-metadata>
+      </property-extension>
+    </property>
+    <property>
+      <description><![CDATA[<p>
+           The detail error message to be used for constructing faces messages,
+          </p>]]>
+      </description>
+      <property-name>messageDetailInvalidDays</property-name>
+      <property-class>java.lang.String</property-class>
+      <property-extension>
+        <mfp:property-metadata>
+          <mfp:preferred>true</mfp:preferred>
+        </mfp:property-metadata>
+      </property-extension>
+    </property>
+    
+    <validator-extension>
+      <mfp:tag-name>tr:validateDateRestriction</mfp:tag-name>
+      <mfp:tag-class>org.apache.myfaces.trinidadinternal.taglib.validator.ValidateDateRestrictionTag</mfp:tag-class>
+      <mfp:author>Matthias Wessendorf</mfp:author>
+      <mfp:uix2-local-name>validateDateTimeRange</mfp:uix2-local-name>
+    </validator-extension>
+  </validator>
+</faces-config>

Added: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/DateRestrictionValidatorBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/DateRestrictionValidatorBean.java?view=auto&rev=469694
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/DateRestrictionValidatorBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/DateRestrictionValidatorBean.java Tue Oct 31 14:58:26 2006
@@ -0,0 +1,72 @@
+/*
+* Copyright 2006 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.myfaces.trinidaddemo;
+
+import java.util.Date;
+
+import org.apache.myfaces.trinidad.model.DateListProvider;
+
+public class DateRestrictionValidatorBean
+{
+
+  public String getCountry()
+  {
+    return _country;
+  }
+  public void setCountry(String country)
+  {
+    this._country = country;
+  }
+  public DateListProvider getNationalHolidays()
+  {
+    return _nationalHolidays;
+  }
+  public void setNationalHolidays(DateListProvider nationalHolidays)
+  {
+    this._nationalHolidays = nationalHolidays;
+  }
+  public Date getTestInvalidDays()
+  {
+    return _testInvalidDays;
+  }
+  public void setTestInvalidDays(Date testInvalidDays)
+  {
+    this._testInvalidDays = testInvalidDays;
+  }
+  public Date getTestInvalidDaysOfWeek()
+  {
+    return _testInvalidDaysOfWeek;
+  }
+  public void setTestInvalidDaysOfWeek(Date testInvalidDaysOfWeek)
+  {
+    this._testInvalidDaysOfWeek = testInvalidDaysOfWeek;
+  }
+  public Date getTestInvalidMonth()
+  {
+    return _testInvalidMonth;
+  }
+  public void setTestInvalidMonth(Date testInvalidMonth)
+  {
+    this._testInvalidMonth = testInvalidMonth;
+  }
+  
+  private DateListProvider _nationalHolidays = null;
+  private String _country = null;
+  private Date _testInvalidDays = null;
+  private Date _testInvalidDaysOfWeek = null;
+  private Date _testInvalidMonth = null;
+  
+}
\ No newline at end of file

Added: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/GermanHolidayDateListProvider.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/GermanHolidayDateListProvider.java?view=auto&rev=469694
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/GermanHolidayDateListProvider.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/GermanHolidayDateListProvider.java Tue Oct 31 14:58:26 2006
@@ -0,0 +1,80 @@
+/*
+* Copyright 2006 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.myfaces.trinidaddemo;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.trinidad.model.DateListProvider;
+
+public class GermanHolidayDateListProvider implements DateListProvider
+{
+  
+  public GermanHolidayDateListProvider()
+  {
+    _germanHolidays = new ArrayList<Date>();
+    _germanHolidays.add(_newDate("01.01.2007"));
+    _germanHolidays.add(_newDate("06.04.2007"));
+    _germanHolidays.add(_newDate("09.04.2007"));
+    _germanHolidays.add(_newDate("01.05.2007"));
+    _germanHolidays.add(_newDate("17.05.2007"));
+    _germanHolidays.add(_newDate("07.06.2007"));
+    _germanHolidays.add(_newDate("03.10.2007"));
+    _germanHolidays.add(_newDate("01.11.2007"));
+    _germanHolidays.add(_newDate("25.12.2007"));
+    _germanHolidays.add(_newDate("26.12.2007"));
+  }
+
+  public List<Date> getDateList(FacesContext context, Calendar base,
+      Date rangeStart, Date rangeEnd)
+  {
+    
+    List<Date> returnDates = new ArrayList<Date>();
+    
+    for (Date it : _germanHolidays)
+    {
+      if(!it.before(rangeStart) && !it.after(rangeEnd)){
+        base.setTime(it);
+        returnDates.add(base.getTime());
+      }
+    }
+    
+    return returnDates;
+  }
+
+  private Date _newDate(String string)
+  {
+    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
+    Date ret = null;
+    try
+    {
+      ret = sdf.parse(string);
+    } catch (ParseException e)
+    {
+      e.printStackTrace();
+    }
+    return ret;
+  }
+
+
+  private List<Date> _germanHolidays = null;
+}
\ No newline at end of file

Modified: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml?view=diff&rev=469694&r1=469693&r2=469694
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml Tue Oct 31 14:58:26 2006
@@ -97,6 +97,33 @@
     </managed-bean-scope>
   </managed-bean>
 
+  <managed-bean>
+    <managed-bean-name>germanHolidays</managed-bean-name>
+    <managed-bean-class>
+       org.apache.myfaces.trinidaddemo.GermanHolidayDateListProvider
+    </managed-bean-class>
+    <managed-bean-scope>
+       application
+    </managed-bean-scope>
+  </managed-bean>
+  
+  <managed-bean>
+    <managed-bean-name>dateRestrictionValidator</managed-bean-name>
+    <managed-bean-class>
+       org.apache.myfaces.trinidaddemo.DateRestrictionValidatorBean
+    </managed-bean-class>
+    <managed-bean-scope>
+       request
+    </managed-bean-scope>
+    <managed-property>
+      <property-name>nationalHolidays</property-name>
+      <value>#{germanHolidays}</value>
+    </managed-property>
+    <managed-property>
+      <property-name>country</property-name>
+      <value>German</value>
+    </managed-property>
+  </managed-bean>
 
   <managed-bean>
     <managed-bean-name>action</managed-bean-name>
@@ -1815,6 +1842,12 @@
     <navigation-case>
       <from-outcome>clientConvert</from-outcome>
       <to-view-id>/convertValidate/clientConvert.jspx</to-view-id>
+      <redirect/>
+    </navigation-case>
+
+    <navigation-case>
+      <from-outcome>dateRestrictionValidate</from-outcome>
+      <to-view-id>/convertValidate/dateRestrictionValidate.jspx</to-view-id>
       <redirect/>
     </navigation-case>
 

Added: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/dateRestrictionValidate.jspx
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/dateRestrictionValidate.jspx?view=auto&rev=469694
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/dateRestrictionValidate.jspx (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/dateRestrictionValidate.jspx Tue Oct 31 14:58:26 2006
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="iso-8859-1"  standalone="yes" ?>
+<!--
+  Copyright 2006 The Apache Software Foundation.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<jsp:root version="1.2" xmlns:tr="http://myfaces.apache.org/trinidad"
+          xmlns:f="http://java.sun.com/jsf/core"
+          xmlns:jsp="http://java.sun.com/JSP/Page">
+  <jsp:directive.page contentType="text/html;charset=utf-8"/>
+  <f:view>
+    <tr:document title="Trinidad DateRestrictionValidator">
+        <tr:form>
+          <tr:panelPage>
+            <tr:messages/>
+            <f:facet name="navigationGlobal">
+              <tr:navigationPane hint="buttons">
+                <tr:commandNavigationItem text="Validators and Converters"
+                                    action="convertValidateDemos"
+                                    immediate="true"/>
+              </tr:navigationPane>
+            </f:facet>
+          <tr:panelHeader text="Date Restriction Validator">
+            <tr:panelFormLayout>
+              <tr:inputDate id="days" value="#{dateRestrictionValidator.testInvalidDays}"
+                                  label="Select a date!">
+                <f:facet name="help">
+                  <tr:outputText value="Ensures, that  #{dateRestrictionValidator.country} holidays are not selectable"/>
+                </f:facet>
+                <tr:convertDateTime pattern="yyyy-MM-dd"/>
+                <tr:validateDateRestriction  invalidDays="#{dateRestrictionValidator.nationalHolidays}" />
+              </tr:inputDate>
+              
+              <tr:inputDate id="month" value="#{dateRestrictionValidator.testInvalidMonth}"
+                                  label="Select a date!">
+                <f:facet name="help">
+                  <tr:outputText value="November/December dates are not allowed here!"/>
+                </f:facet>
+                <tr:convertDateTime pattern="yyyy-MM-dd"/>
+                <tr:validateDateRestriction  invalidMonths="Nov Dec" />
+              </tr:inputDate>
+              
+              <tr:inputDate id="daysOfWeek" value="#{dateRestrictionValidator.testInvalidDaysOfWeek}"
+                                  label="Select a date!">
+                <f:facet name="help">
+                  <tr:outputText value="Please no Mondays...!"/>
+                </f:facet>
+                <tr:convertDateTime pattern="yyyy-MM-dd"/>
+                <tr:validateDateRestriction  invalidDaysOfWeek="Mon"/>
+              </tr:inputDate>
+            </tr:panelFormLayout>
+           </tr:panelHeader>
+           <tr:commandButton text="Submit"/>
+          </tr:panelPage>
+        </tr:form>
+    </tr:document>
+  </f:view>
+</jsp:root>
\ No newline at end of file

Modified: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/index.jspx
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/index.jspx?view=diff&rev=469694&r1=469693&r2=469694
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/index.jspx (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/index.jspx Tue Oct 31 14:58:26 2006
@@ -33,6 +33,7 @@
               <tr:panelGroupLayout layout="vertical">
                 <tr:commandLink text="client converters and validators" action="clientConvert"/>
                 <tr:commandLink text="converters and validators" action="convertValidate"/>
+                <tr:commandLink text="Date Restriction Validator" action="dateRestrictionValidate" />
                 <tr:commandLink text="message customization on validators and converters" action="messageCustomization"/>
               </tr:panelGroupLayout>
             </tr:panelHeader>