You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mb...@apache.org on 2005/09/02 20:05:42 UTC

svn commit: r267237 - in /myfaces/tomahawk/trunk: src/java/org/apache/myfaces/custom/date/HtmlInputDate.java src/java/org/apache/myfaces/custom/date/HtmlInputDate.xml src/java/org/apache/myfaces/custom/date/HtmlInputDateTag.java tld/tomahawk.tld

Author: mbr
Date: Fri Sep  2 11:05:32 2005
New Revision: 267237

URL: http://svn.apache.org/viewcvs?rev=267237&view=rev
Log:
patch for MYFACES-478 from Kai Heinecke

Modified:
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDate.java
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDate.xml
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDateTag.java
    myfaces/tomahawk/trunk/tld/tomahawk.tld

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDate.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDate.java?rev=267237&r1=267236&r2=267237&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDate.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDate.java Fri Sep  2 11:05:32 2005
@@ -1,12 +1,12 @@
 /*
  * Copyright 2004 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.
@@ -21,6 +21,7 @@
 import java.util.Calendar;
 import java.util.Date;
 import java.util.Locale;
+import java.util.TimeZone;
 
 import javax.faces.component.UIInput;
 import javax.faces.context.FacesContext;
@@ -38,39 +39,40 @@
     public static final String COMPONENT_FAMILY = "javax.faces.Input";
     private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Date";
     private static final boolean DEFAULT_DISABLED = false;
-    
+
 	private Boolean _readonly = null;
     private String _enabledOnUserRole = null;
     private String _visibleOnUserRole = null;
-    
+
     /**
-     * Same as for f:convertDateTime 
+     * Same as for f:convertDateTime
      * Specifies what contents the string value will be formatted to include, or parsed expecting.
      * Valid values are "date", "time", and "both". Default value is "date".
      */
     private String _type = null;
     private Boolean _popupCalendar = null;
-    
-    
+    private String _timeZone = null;
+
+
     private Boolean _disabled = null;
-    
+
     // Values to hold the data entered by the user
     private UserData _userData = null;
-    
+
     public HtmlInputDate() {
         setRendererType(DEFAULT_RENDERER_TYPE);
     }
-    
+
     public void setUserData(UserData userData){
         this._userData = userData;
     }
 
     public UserData getUserData(Locale currentLocale){
         if( _userData == null )
-            _userData = new UserData((Date) getValue(), currentLocale);
+            _userData = new UserData((Date) getValue(), currentLocale, getTimeZone());
         return _userData;
     }
-    
+
 	public String getType() {
 		if (_type != null) return _type;
 		ValueBinding vb = getValueBinding("type");
@@ -79,7 +81,7 @@
 	public void setType(String string) {
 		_type = string;
 	}
-	
+
     public boolean isPopupCalendar(){
    		if (_popupCalendar != null)
    		    return _popupCalendar.booleanValue();
@@ -90,6 +92,16 @@
         this._popupCalendar = Boolean.valueOf(popupCalendar);
     }
 
+    public String getTimeZone(){
+        if(_timeZone != null) return _timeZone;
+        ValueBinding vb = getValueBinding("timeZone");
+        return vb != null ? (String)vb.getValue(getFacesContext()) : null;
+    }
+    
+    public void setTimeZone(String timeZone){
+        _timeZone = timeZone;
+    }
+
     public boolean isReadonly(){
         if (_readonly != null) return _readonly.booleanValue();
         ValueBinding vb = getValueBinding("readonly");
@@ -122,7 +134,7 @@
         if (!UserRoleUtils.isVisibleOnUserRole(this)) return false;
         return super.isRendered();
     }
-	
+
     public boolean isDisabled(){
         if (_disabled != null) return _disabled.booleanValue();
         ValueBinding vb = getValueBinding("disabled");
@@ -132,9 +144,9 @@
     public void setDisabled(boolean disabled) {
         _disabled = Boolean.valueOf(disabled);
     }
-	
+
     public Object saveState(FacesContext context) {
-        Object values[] = new Object[8];
+        Object values[] = new Object[9];
         values[0] = super.saveState(context);
         values[1] = _type;
         values[2] = _popupCalendar;
@@ -143,6 +155,7 @@
 		values[5] = _readonly;
         values[6] = _enabledOnUserRole;
         values[7] = _visibleOnUserRole;
+        values[8] = _timeZone;
         return values;
     }
 
@@ -156,8 +169,9 @@
 		_readonly = (Boolean)values[5];
         _enabledOnUserRole = (String)values[6];
         _visibleOnUserRole = (String)values[7];
+        _timeZone = (String)values[8];
     }
-    
+
     public static class UserData implements Serializable {
         private static final long serialVersionUID = -6507279524833267707L;
         private String day;
@@ -166,12 +180,17 @@
         private String hours;
         private String minutes;
         private String seconds;
-        
-        public UserData(Date date, Locale currentLocale){
+        private TimeZone timeZone = null;
+
+        public UserData(Date date, Locale currentLocale, String _timeZone){
             if( date == null )
                 date = new Date();
-            
+
             Calendar calendar = Calendar.getInstance(currentLocale);
+            if (_timeZone != null) {
+				timeZone = TimeZone.getTimeZone(_timeZone);
+                calendar.setTimeZone(timeZone);
+			}
             calendar.setTime( date );
             day = Integer.toString(calendar.get(Calendar.DAY_OF_MONTH));
             month = Integer.toString(calendar.get(Calendar.MONTH)+1);
@@ -180,16 +199,18 @@
             minutes = Integer.toString(calendar.get(Calendar.MINUTE));
             seconds = Integer.toString(calendar.get(Calendar.SECOND));
         }
-        
+
         public Date parse() throws ParseException{
             SimpleDateFormat fullFormat = new SimpleDateFormat( "dd MM yyyy HH mm ss" );
+            if (timeZone != null)
+                fullFormat.setTimeZone(timeZone);
             return fullFormat.parse(day+" "+month+" "+year+" "+hours+" "+minutes+" "+seconds);
         }
-        
+
         private String formatedInt(String toFormat){
             if( toFormat == null )
                 return null;
-            
+
             int i = -1;
             try{
                 i = Integer.parseInt( toFormat );
@@ -200,8 +221,8 @@
                 return "0"+i;
             return Integer.toString(i);
         }
-        
-        
+
+
         public String getDay() {
             return formatedInt( day );
         }
@@ -215,14 +236,14 @@
         public void setMonth(String month) {
             this.month = month;
         }
-        
+
         public String getYear() {
             return year;
         }
         public void setYear(String year) {
             this.year = year;
         }
-        
+
         public String getHours() {
             return formatedInt( hours );
         }

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDate.xml
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDate.xml?rev=267237&r1=267236&r2=267237&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDate.xml (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDate.xml Fri Sep  2 11:05:32 2005
@@ -13,6 +13,10 @@
         <type>java.lang.String</type>
     </field>
 	<field>
+        <name>timeZone</name>
+        <type>java.lang.String</type>
+    </field>
+	<field>
         <name>disabled</name>
         <type>java.lang.String</type>
     </field>

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDateTag.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDateTag.java?rev=267237&r1=267236&r2=267237&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDateTag.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlInputDateTag.java Fri Sep  2 11:05:32 2005
@@ -1,12 +1,12 @@
 /*
  * Copyright 2004 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.
@@ -32,10 +32,12 @@
     public String getRendererType() {
         return "org.apache.myfaces.Date";
     }
-    
+
     // HtmlInputDate attributes
     private String type;
     private String popupCalendar;
+    private String timeZone;
+
 
     // UIComponent attributes --> already implemented in UIComponentTagBase
     // HTML universal attributes --> already implemented in HtmlComponentTagBase
@@ -50,13 +52,14 @@
     // User Role support
     private String enabledOnUserRole;
     private String visibleOnUserRole;
-    
+
     public void release() {
         super.release();
         enabledOnUserRole=null;
         visibleOnUserRole=null;
         type=null;
         popupCalendar=null;
+        timeZone = null;
     }
 
     protected void setProperties(UIComponent component) {
@@ -64,24 +67,30 @@
 
         setStringProperty(component, "type", type);
         setBooleanProperty(component, "popupCalendar", popupCalendar);
-        
+        setStringProperty(component, "timeZone", timeZone);
+
         setStringProperty(component, UserRoleAware.ENABLED_ON_USER_ROLE_ATTR, enabledOnUserRole);
         setStringProperty(component, UserRoleAware.VISIBLE_ON_USER_ROLE_ATTR, visibleOnUserRole);
     }
-    
+
     public void setType(String type){
         this.type = type;
     }
-    
+
     public void setPopupCalendar(String popupCalendar){
         this.popupCalendar = popupCalendar;
     }
-    
+
     public void setEnabledOnUserRole(String enabledOnUserRole){
         this.enabledOnUserRole = enabledOnUserRole;
     }
 
     public void setVisibleOnUserRole(String visibleOnUserRole){
         this.visibleOnUserRole = visibleOnUserRole;
+    }
+
+    public void setTimeZone(String timeZone)
+    {
+        this.timeZone = timeZone;
     }
 }

Modified: myfaces/tomahawk/trunk/tld/tomahawk.tld
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/tld/tomahawk.tld?rev=267237&r1=267236&r2=267237&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/tld/tomahawk.tld (original)
+++ myfaces/tomahawk/trunk/tld/tomahawk.tld Fri Sep  2 11:05:32 2005
@@ -1229,6 +1229,11 @@
             <required>false</required>
             <rtexprvalue>false</rtexprvalue>
         </attribute>
+        <attribute>
+            <name>timeZone</name>
+            <required>false</required>
+            <rtexprvalue>false</rtexprvalue>
+        </attribute>
     </tag>
 
     <!-- inputFileUpload -->