myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yee-Wah Lee (JIRA)" <...@myfaces.apache.org>
Subject [jira] Commented: (TRINIDAD-985) Maximum date on <tr:validateDateTimeRange> is maximum date minus 1
Date Tue, 11 Mar 2008 17:12:46 GMT

    [ https://issues.apache.org/jira/browse/TRINIDAD-985?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12577519#action_12577519
] 

Yee-Wah Lee commented on TRINIDAD-985:
--------------------------------------

Great, thanks for the confirmation. I can explain what you are seeing. It is to support a
scenario very similar to yours, i.e.
- InputDate with value bound to a backing bean's Date object
- Child convertDateTime with the format pattern "mm/dd/yyyy" (or any pattern, just as long
as time doesn't appear).

Suppose the original date value is "3/11/2008  12:00". 
- It gets displayed as "3/11/2008" because of the converter pattern. 
- When the user posts back the form, "3/11/2008" is sent back. 
- The underlying implementation of the converter is to use a SimpleDateFormat with the pattern
set to parse the String. By default, SimpleDateFormat defaults the hours/mins/seconds to 0.
So, it constructs the Date for "3/11/2008 00:00" and saves that.
Now the user didn't touch the InputDate but the underlying value has changed. This seemed
like data loss to users, so the code attempts to preserve the time portions by copying over
the components that aren't displayed (hours/mins/seconds/milliseconds) from the previous value.


In your situation, this is happening:
- The validator creates a GregorianCalendar with March 30 2008 value. Constructor defaults
the time values to 0, so the Date is created for "3/30/2008 00:00". 
- The backing bean creates a Value using new Date(), which is the current date/time, e.g.
3/11/2008 HH:MM where HH:MM are the current hour/min values, usually non-zero.
- The user enters "3/30/08" and the string is posted back
- The converter creates "3/30/08 00:00" and copies the time values to get "3/30/2008 HH:MM"

- That value "3/30/2008 HH:MM" is then compared against the Validator's max of "3/30/2008
00:00" and found to be more than the maximum. Therefore, maximizing the time components will
work.

> Maximum date on <tr:validateDateTimeRange> is maximum date minus 1
> ------------------------------------------------------------------
>
>                 Key: TRINIDAD-985
>                 URL: https://issues.apache.org/jira/browse/TRINIDAD-985
>             Project: MyFaces Trinidad
>          Issue Type: Bug
>          Components: Components
>         Environment: windows xp professional; IE 6.0; Myfaces 1.1.5;Trinidad 1.1.4
>            Reporter: Veena K. Pandit
>
> When I set a maximum date in <tr:inputDate> associated with a <tr:validateDateTimeRange>
date component, the date component reflects the maximum date to be maximum date minus 1
> date.jspx looks like this
> <?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2"
>           xmlns:f="http://java.sun.com/jsf/core"
>           xmlns:tr="http://myfaces.apache.org/trinidad"
>           xmlns:trh="http://myfaces.apache.org/trinidad/html">
>   <jsp:directive.page contentType="text/html;charset=utf-8"/>
>   <f:view>
>     <tr:messages/>
>     <tr:document title="Date Component">
>       <tr:form>
>       <tr:panelHorizontalLayout>
>         <tr:inputDate id="date" autoSubmit="true"
>                       value="#{myDateBacking.dateValue}"
>                       label="Effective Date:">
>           <tr:convertDateTime pattern="yyyy-MM-dd"/>
>           <tr:validateDateTimeRange minimum="#{myDateBacking.minDate}"
>                                     maximum="#{myDateBacking.maxDate}"
>                                     messageDetailNotInRange="Date {0} in {1} does not
fall within {2} : {3}"/>
>         </tr:inputDate>
>       </tr:panelHorizontalLayout>
>       </tr:form>
>     </tr:document>
>   </f:view>
> </jsp:root>
> MyDateBacking.java looks like this:
> package mil.osd.dmdc.deers.demo.backing;
> import java.util.Calendar;
> import java.util.Date;
> import java.util.GregorianCalendar;
> public class MyDateBacking {
>   
>   
>   private Date _dateValue;
>   private Date _minDate;
>   private Date _maxDate;
>   
>   
>   public MyDateBacking(){
>       _dateValue = new Date();
>       Calendar xmas = new GregorianCalendar(1998, Calendar.DECEMBER, 25);
>        _minDate = xmas.getTime();
>       Calendar future = new GregorianCalendar(2008,Calendar.MARCH,30);
>       _maxDate = future.getTime();
>     
>   }
>   public void setDateValue(Date dateValue) {
>     this._dateValue = dateValue;
>   }
>   public Date getDateValue() {
>     return _dateValue;
>   }
>   public void setMinDate(Date minDate) {
>     this._minDate = minDate;
>   }
>   public Date getMinDate() {
>     return _minDate;
>   }
>   public void setMaxDate(Date maxDate) {
>     this._maxDate = maxDate;
>   }
>   public Date getMaxDate() {
>     return _maxDate;
>   }
> }
> The example shows the maximum date is set to March 30,2008, but the calendar reflects
> the maximum date to be March 29, 2008

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message