myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svieu...@apache.org
Subject svn commit: r169590 - /myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlDateRenderer.java /myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlInputDate.java /myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlInputDateTag.java
Date Wed, 11 May 2005 05:28:00 GMT
Author: svieujot
Date: Tue May 10 22:27:59 2005
New Revision: 169590

URL: http://svn.apache.org/viewcvs?rev=169590&view=rev
Log:
inputDate : partial fix for MYFACES-234

Modified:
    myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlDateRenderer.java
    myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlInputDate.java
    myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlInputDateTag.java

Modified: myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlDateRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlDateRenderer.java?rev=169590&r1=169589&r2=169590&view=diff
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlDateRenderer.java (original)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlDateRenderer.java Tue
May 10 22:27:59 2005
@@ -39,50 +39,6 @@
 import org.apache.myfaces.util.MessageUtils;
 
 /**
- * $Log$
- * Revision 1.14  2004/12/27 04:11:11  mmarinschek
- * Data Table stores the state of facets of children; script tag is rendered with type attribute
instead of language attribute, popup works better as a column in a data table
- *
- * Revision 1.13  2004/12/24 13:21:51  matzew
- * organized imports
- *
- * Revision 1.12  2004/12/10 02:15:19  svieujot
- * New popupCalendar attribute, and implements UserRoleAware.
- *
- * Revision 1.11  2004/12/09 12:54:26  svieujot
- * Changes to check for submitted-value first
- *
- * Revision 1.10  2004/12/09 05:13:02  svieujot
- * Mark potential bugs where we use the backing bean's value, and do not check for submitted
value
- *
- * Revision 1.9  2004/10/13 11:50:57  matze
- * renamed packages to org.apache
- *
- * Revision 1.8  2004/10/04 17:47:55  svieujot
- * Bugfix for bug 1039797 (Missing setter in HtmlInputDateTag), and add User Role support
to InputDate.
- *
- * Revision 1.7  2004/07/30 13:09:04  svieujot
- * Render numbers as 2 digits
- *
- * Revision 1.6  2004/07/30 02:59:00  svieujot
- * Enable disabled attribute
- *
- * Revision 1.5  2004/07/26 02:00:05  svieujot
- * Change structure to keep the data entered by the user even if they can't be converted
- *
- * Revision 1.4  2004/07/21 20:34:13  svieujot
- * Add error handling
- *
- * Revision 1.3  2004/07/18 03:08:23  svieujot
- * inputDate : add a type="date|time|both" similar as f:convertDateTime
- *
- * Revision 1.2  2004/07/17 21:03:05  svieujot
- * Clean code
- *
- * Revision 1.1  2004/07/17 20:52:53  svieujot
- * First version of an x:inputDate component
- *
- * 
  * @author Sylvain Vieujot (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
@@ -100,11 +56,11 @@
     private static final String ID_MINUTES_POSTFIX = ".minutes";
     private static final String ID_SECONDS_POSTFIX = ".seconds";
     
-    protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent) {
-        if( !UserRoleUtils.isEnabledOnUserRole(uiComponent) )
+    protected boolean isDisabled(FacesContext facesContext, HtmlInputDate inputDate) {
+        if( !UserRoleUtils.isEnabledOnUserRole(inputDate) )
             return false;
 
-        return ((HtmlInputDate)uiComponent).isDisabled();
+        return inputDate.isDisabled();
     }
     
     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException
{
@@ -118,33 +74,35 @@
         String type = inputDate.getType();
         String clientId = uiComponent.getClientId(facesContext);
 
-        boolean disabled = isDisabled(facesContext, uiComponent);
+        boolean disabled = isDisabled(facesContext, inputDate);
+		boolean readonly = inputDate.isReadonly();
 
         ResponseWriter writer = facesContext.getResponseWriter();
 
         HtmlRendererUtils.writePrettyLineSeparator(facesContext);
 
         if( ! type.equals("time")){
-	        encodeInputDay(uiComponent, writer, clientId, userData, disabled);
-	        encodeInputMonth(uiComponent, writer, clientId, userData, currentLocale, disabled);
-	        encodeInputYear(uiComponent, writer, clientId, userData, disabled);
+	        encodeInputDay(inputDate, writer, clientId, userData, disabled, readonly);
+	        encodeInputMonth(inputDate, writer, clientId, userData, currentLocale, disabled,
readonly);
+	        encodeInputYear(inputDate, writer, clientId, userData, disabled, readonly);
 	        
-	        if( inputDate.isPopupCalendar() && ! disabled )
+	        if( inputDate.isPopupCalendar() && ! disabled && ! readonly )
 	            encodePopupCalendarButton(facesContext, writer, clientId, currentLocale);
         }
         if( type.equals("both") ){
             writer.write(" ");
         }
         if( ! type.equals("date")){
-	        encodeInputHours(uiComponent, writer, clientId, userData, disabled);
+	        encodeInputHours(uiComponent, writer, clientId, userData, disabled, readonly);
 	        writer.write(":");
-	        encodeInputMinutes(uiComponent, writer, clientId, userData, disabled);
+	        encodeInputMinutes(uiComponent, writer, clientId, userData, disabled, readonly);
 	        writer.write(":");
-	        encodeInputSeconds(uiComponent, writer, clientId, userData, disabled);
+	        encodeInputSeconds(uiComponent, writer, clientId, userData, disabled, readonly);
         }
     }
     
-    private static void encodeInputField(UIComponent uiComponent, ResponseWriter writer,
String id, String value, int size, boolean disabled)  throws IOException {
+    private static void encodeInputField(UIComponent uiComponent, ResponseWriter writer,
String id,
+			String value, int size, boolean disabled, boolean readonly)  throws IOException {
         writer.startElement(HTML.INPUT_ELEM, uiComponent);
         HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.UNIVERSAL_ATTRIBUTES);
         HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.EVENT_HANDLER_ATTRIBUTES);
@@ -153,6 +111,9 @@
 		if (disabled) {
 		    writer.writeAttribute(HTML.DISABLED_ATTR, Boolean.TRUE, null);
 		}
+		if( readonly ) {
+			writer.writeAttribute(HTML.READONLY_ATTR, Boolean.TRUE, null);
+		}
 
 		writer.writeAttribute(HTML.ID_ATTR, id, null);
 		writer.writeAttribute(HTML.NAME_ATTR, id, null);
@@ -164,13 +125,13 @@
 		writer.endElement(HTML.INPUT_ELEM);
     }
     
-    private static void encodeInputDay(UIComponent uiComponent, ResponseWriter writer, String
clientId, UserData userData, boolean disabled)
-            throws IOException {
-        encodeInputField(uiComponent, writer, clientId + ID_DAY_POSTFIX, userData.getDay(),
2, disabled);
+    private static void encodeInputDay(UIComponent uiComponent, ResponseWriter writer, String
clientId,
+			UserData userData, boolean disabled, boolean readonly) throws IOException {
+        encodeInputField(uiComponent, writer, clientId + ID_DAY_POSTFIX, userData.getDay(),
2, disabled, readonly);
     }
 
     private static void encodeInputMonth(UIComponent uiComponent, ResponseWriter writer,
String clientId, UserData userData, Locale currentLocale,
-            boolean disabled) throws IOException {
+            boolean disabled, boolean readonly) throws IOException {
         writer.startElement(HTML.SELECT_ELEM, uiComponent);
         writer.writeAttribute(HTML.ID_ATTR, clientId + ID_MONTH_POSTFIX, null);
         writer.writeAttribute(HTML.NAME_ATTR, clientId + ID_MONTH_POSTFIX, null);
@@ -206,20 +167,24 @@
         writer.endElement(HTML.SELECT_ELEM);
     }
 
-    private static void encodeInputYear(UIComponent uiComponent, ResponseWriter writer, String
clientId, UserData userData, boolean disabled) throws IOException {
-        encodeInputField(uiComponent, writer, clientId + ID_YEAR_POSTFIX, userData.getYear(),
4, disabled);
+    private static void encodeInputYear(UIComponent uiComponent, ResponseWriter writer, String
clientId,
+			UserData userData, boolean disabled, boolean readonly) throws IOException {
+        encodeInputField(uiComponent, writer, clientId + ID_YEAR_POSTFIX, userData.getYear(),
4, disabled, readonly);
     }
     
-    private static void encodeInputHours(UIComponent uiComponent, ResponseWriter writer,
String clientId, UserData userData, boolean disabled) throws IOException {
-        encodeInputField(uiComponent, writer, clientId + ID_HOURS_POSTFIX, userData.getHours(),
2, disabled);
+    private static void encodeInputHours(UIComponent uiComponent, ResponseWriter writer,
String clientId,
+			UserData userData, boolean disabled, boolean readonly) throws IOException {
+        encodeInputField(uiComponent, writer, clientId + ID_HOURS_POSTFIX, userData.getHours(),
2, disabled, readonly);
     }
     
-    private static void encodeInputMinutes(UIComponent uiComponent, ResponseWriter writer,
String clientId, UserData userData, boolean disabled) throws IOException {
-        encodeInputField(uiComponent, writer, clientId + ID_MINUTES_POSTFIX, userData.getMinutes(),
2, disabled);
+    private static void encodeInputMinutes(UIComponent uiComponent, ResponseWriter writer,
String clientId,
+			UserData userData, boolean disabled, boolean readonly) throws IOException {
+        encodeInputField(uiComponent, writer, clientId + ID_MINUTES_POSTFIX, userData.getMinutes(),
2, disabled, readonly);
     }
     
-    private static void encodeInputSeconds(UIComponent uiComponent, ResponseWriter writer,
String clientId, UserData userData, boolean disabled) throws IOException {
-        encodeInputField(uiComponent, writer, clientId + ID_SECONDS_POSTFIX, userData.getSeconds(),
2, disabled);
+    private static void encodeInputSeconds(UIComponent uiComponent, ResponseWriter writer,
String clientId,
+			UserData userData, boolean disabled, boolean readonly) throws IOException {
+        encodeInputField(uiComponent, writer, clientId + ID_SECONDS_POSTFIX, userData.getSeconds(),
2, disabled, readonly);
     }
     
     private void encodePopupCalendarButton(FacesContext facesContext, ResponseWriter writer,
String clientId, Locale currentLocale) throws IOException{
@@ -249,10 +214,11 @@
     public void decode(FacesContext facesContext, UIComponent uiComponent) {
         RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlInputDate.class);
         
-        if( isDisabled(facesContext, uiComponent) ) // For safety, do not set the submited
value if the component is disabled.
+        HtmlInputDate inputDate = (HtmlInputDate) uiComponent;
+		
+        if( isDisabled(facesContext, inputDate) ) // For safety, do not set the submited
value if the component is disabled.
             return;
 
-        HtmlInputDate inputDate = (HtmlInputDate) uiComponent;
         Locale currentLocale = facesContext.getViewRoot().getLocale();
         UserData userData = (UserData) inputDate.getSubmittedValue();
         if( userData == null )

Modified: myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlInputDate.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlInputDate.java?rev=169590&r1=169589&r2=169590&view=diff
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlInputDate.java (original)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlInputDate.java Tue May
10 22:27:59 2005
@@ -39,6 +39,7 @@
     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;
     
@@ -88,7 +89,17 @@
     public void setPopupCalendar(boolean popupCalendar){
         this._popupCalendar = Boolean.valueOf(popupCalendar);
     }
-	
+
+    public boolean isReadonly(){
+        if (_readonly != null) return _readonly.booleanValue();
+        ValueBinding vb = getValueBinding("readonly");
+        Boolean v = vb != null ? (Boolean)vb.getValue(getFacesContext()) : null;
+        return v != null ? v.booleanValue() : false;
+    }
+    public void setReadonly(boolean readonly){
+        _readonly = Boolean.valueOf(readonly);
+    }
+
     public void setEnabledOnUserRole(String enabledOnUserRole){
         _enabledOnUserRole = enabledOnUserRole;
     }
@@ -123,14 +134,15 @@
     }
 	
     public Object saveState(FacesContext context) {
-        Object values[] = new Object[7];
+        Object values[] = new Object[8];
         values[0] = super.saveState(context);
         values[1] = _type;
         values[2] = _popupCalendar;
         values[3] = _userData;
         values[4] = _disabled;
-        values[5] = _enabledOnUserRole;
-        values[6] = _visibleOnUserRole;
+		values[5] = _readonly;
+        values[6] = _enabledOnUserRole;
+        values[7] = _visibleOnUserRole;
         return values;
     }
 
@@ -141,8 +153,9 @@
         _popupCalendar = (Boolean)values[2];
         _userData = (UserData)values[3];
         _disabled = (Boolean)values[4];
-        _enabledOnUserRole = (String)values[5];
-        _visibleOnUserRole = (String)values[6];
+		_readonly = (Boolean)values[5];
+        _enabledOnUserRole = (String)values[6];
+        _visibleOnUserRole = (String)values[7];
     }
     
     public static class UserData implements Serializable {

Modified: myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlInputDateTag.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlInputDateTag.java?rev=169590&r1=169589&r2=169590&view=diff
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlInputDateTag.java (original)
+++ myfaces/trunk/src/components/org/apache/myfaces/custom/date/HtmlInputDateTag.java Tue
May 10 22:27:59 2005
@@ -22,9 +22,7 @@
 
 /**
  * @author Sylvain Vieujot (latest modification by $Author$)
- * @version $Revision$ $Date$ $Log:
- *          HtmlInputCalendarTag.java,v $
- *  
+ * @version $Revision$ $Date$
  */
 public class HtmlInputDateTag extends HtmlInputTextTagBase {
     public String getComponentType() {



Mime
View raw message