myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bara...@apache.org
Subject svn commit: r227272 - in /myfaces: share/trunk/src/java/org/apache/myfaces/renderkit/html/ tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/ tomahawk/trunk/src/java/org/apache/myfaces/custom/date/
Date Wed, 03 Aug 2005 22:53:20 GMT
Author: baranda
Date: Wed Aug  3 15:53:01 2005
New Revision: 227272

URL: http://svn.apache.org/viewcvs?rev=227272&view=rev
Log:
I've rewritten how the button that popups the popcalendar is rendered for the date and the
calendar renderers. Now the style of the date/calendar is applied also to the button and it
is easier now to add more attributes to the button... Also fixes MYFACES-282.

Modified:
    myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HTML.java
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java

Modified: myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HTML.java
URL: http://svn.apache.org/viewcvs/myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HTML.java?rev=227272&r1=227271&r2=227272&view=diff
==============================================================================
--- myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HTML.java (original)
+++ myfaces/share/trunk/src/java/org/apache/myfaces/renderkit/html/HTML.java Wed Aug  3 15:53:01
2005
@@ -284,6 +284,7 @@
     public static final String INPUT_TYPE_PASSWORD = "password";
     public static final String INPUT_TYPE_TEXT = "text";
     public static final String INPUT_TYPE_RADIO = "radio";
+    public static final String INPUT_TYPE_BUTTON = "button";
 
     // <button>
     public static final String[] BUTTON_ATTRIBUTES =

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java?rev=227272&r1=227271&r2=227272&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
(original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
Wed Aug  3 15:53:01 2005
@@ -155,8 +155,10 @@
 	            writer.write("<!--\n");
 	            writer.writeText(getLocalizedLanguageScript(symbols, months,
 	                    timeKeeper.getFirstDayOfWeek(),inputCalendar),null);
-	            writer.writeText(getScriptBtnText(inputCalendar.getClientId(facesContext),
-	                    dateFormat,inputCalendar.getPopupButtonString()),null);
+	            //writer.writeText(getScriptBtnText(inputCalendar.getClientId(facesContext),
+	            //        dateFormat,inputCalendar.getPopupButtonString()),null);
+                writeScriptBtnText(facesContext, inputCalendar,
+                        dateFormat,inputCalendar.getPopupButtonString());
 	            writer.write("\n-->");
 	            writer.endElement(HTML.SCRIPT_ELEM);
 	
@@ -329,25 +331,30 @@
         script.append(");");
     }
 
-    private String getScriptBtnText(String clientId, String dateFormat, String popupButtonString)
+    private void writeScriptBtnText(FacesContext facesContext, UIComponent uiComponent, String
dateFormat, String popupButtonString)
+        throws IOException
     {
-
-        StringBuffer script = new StringBuffer();
-        script.append("if (!document.layers) {\n");
-        script.append("document.write(");
-        script.append("\"<input type='button' onclick='jscalendarPopUpCalendar(this,this.form.elements[\\\"");
-        script.append(clientId);
-        script.append("\\\"],\\\"");
-        script.append(dateFormat);
-        script.append("\\\")' value='");
+        String clientId = uiComponent.getClientId(facesContext);
+        
+        ResponseWriter writer = facesContext.getResponseWriter();
+        
+        writer.write("if (!document.layers) {\n");
+        writer.write("document.write('");
+        
+        // render the button
+        writer.startElement(HTML.INPUT_ELEM, null);
+        writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_BUTTON, null);
+        
+        String jsCalendarFunctionCall = "jscalendarPopUpCalendar(this,this.form.elements[\\'"+clientId+"\\'],\\'"+dateFormat+"\\')";
+        writer.writeAttribute(HTML.ONCLICK_ATTR, jsCalendarFunctionCall, null);
         if(popupButtonString==null)
             popupButtonString="...";
-        script.append(popupButtonString);
-        script.append("'/>\"");
-        script.append(");");
-        script.append("\n}");
-
-        return script.toString();
+        writer.writeAttribute(HTML.VALUE_ATTR, popupButtonString, null);
+        HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.UNIVERSAL_ATTRIBUTES);
+        writer.endElement(HTML.INPUT_ELEM);
+        
+        writer.write("');");
+        writer.write("\n}");
     }
 
     private void writeMonthYearHeader(FacesContext facesContext, ResponseWriter writer, UIInput
inputComponent, Calendar timeKeeper,

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java?rev=227272&r1=227271&r2=227272&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/date/HtmlDateRenderer.java Wed
Aug  3 15:53:01 2005
@@ -87,7 +87,7 @@
 	        encodeInputYear(inputDate, writer, clientId, userData, disabled, readonly);
 	        
 	        if( inputDate.isPopupCalendar() && ! disabled && ! readonly )
-	            encodePopupCalendarButton(facesContext, writer, clientId, currentLocale);
+	            encodePopupCalendarButton(facesContext, uiComponent, writer, clientId, currentLocale);
         }
         if( type.equals("both") ){
             writer.write(" ");
@@ -189,7 +189,7 @@
         encodeInputField(uiComponent, writer, clientId + ID_SECONDS_POSTFIX, userData.getSeconds(),
2, disabled, readonly);
     }
     
-    protected void encodePopupCalendarButton(FacesContext facesContext, ResponseWriter writer,
String clientId, Locale currentLocale) throws IOException{
+    protected void encodePopupCalendarButton(FacesContext facesContext, UIComponent uiComponent,
ResponseWriter writer, String clientId, Locale currentLocale) throws IOException{
         HtmlCalendarRenderer.addScriptAndCSSResources(facesContext);
         
         DateFormatSymbols symbols = new DateFormatSymbols(currentLocale);
@@ -210,7 +210,17 @@
         writer.endElement(HTML.SCRIPT_ELEM);
         
         String dateFormat = CalendarDateTimeConverter.createJSPopupFormat(facesContext, null);
-        writer.write("<input type='button' onclick='jscalendarPopUpCalendarForInputDate(\""+clientId+"\",\""+dateFormat+"\")'
value='...'/>");
+        
+        // render the button
+        writer.startElement(HTML.INPUT_ELEM, null);
+        writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_BUTTON, null);
+        
+        String jsCalendarFunctionCall = "jscalendarPopUpCalendarForInputDate('"+clientId+"','"+dateFormat+"')";
+        writer.writeAttribute(HTML.ONCLICK_ATTR, jsCalendarFunctionCall, null);
+        writer.writeAttribute(HTML.VALUE_ATTR, "...", null);
+        HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.UNIVERSAL_ATTRIBUTES);
+        
+        writer.endElement(HTML.INPUT_ELEM);
     }
 
     public void decode(FacesContext facesContext, UIComponent uiComponent) {



Mime
View raw message