You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/08/28 21:11:32 UTC
svn commit: r990410 -
/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
Author: lu4242
Date: Sat Aug 28 19:11:31 2010
New Revision: 990410
URL: http://svn.apache.org/viewvc?rev=990410&view=rev
Log:
TOMAHAWK-1472 Add Support for new Resource API in tomahawk 2.0 module (addResource calls should happen on rendering to work correctly NonBufferingAddResource)
Modified:
myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
Modified: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java?rev=990410&r1=990409&r2=990410&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java (original)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java Sat Aug 28 19:11:31 2010
@@ -119,6 +119,7 @@ public class HtmlCalendarRenderer
private final Log log = LogFactory.getLog(HtmlCalendarRenderer.class);
private static final String JAVASCRIPT_ENCODED = "org.apache.myfaces.calendar.JAVASCRIPT_ENCODED";
+ private static final String JAVASCRIPT_ENCODED_JSF2 = "org.apache.myfaces.calendar.JAVASCRIPT_ENCODED_JSF2";
// TODO: move this to HtmlRendererUtils in shared
private static final String RESOURCE_NONE = "none";
@@ -129,7 +130,7 @@ public class HtmlCalendarRenderer
if (inputCalendar.isRenderAsPopup() && inputCalendar.isAddResources())
{
- addScriptAndCSSResources(FacesContext.getCurrentInstance(), inputCalendar);
+ addScriptAndCSSResourcesWithJSF2ResourceAPI(FacesContext.getCurrentInstance(), inputCalendar);
}
}
@@ -270,8 +271,8 @@ public class HtmlCalendarRenderer
Calendar timeKeeper,
DateFormatSymbols symbols) throws IOException
{
- //if(inputCalendar.isAddResources())
- // addScriptAndCSSResources(facesContext, inputCalendar);
+ if(inputCalendar.isAddResources())
+ addScriptAndCSSResources(facesContext, inputCalendar);
// Check for an enclosed converter:
UIInput uiInput = (UIInput) inputCalendar;
@@ -497,7 +498,8 @@ public class HtmlCalendarRenderer
// different styleLocation or scriptLocation settings then all but the first one get ignored.
// Having different settings for calendars on the same page would be unusual, so ignore this
// for now..
- if (facesContext.getExternalContext().getRequestMap().containsKey(JAVASCRIPT_ENCODED))
+ if (facesContext.getAttributes().containsKey(JAVASCRIPT_ENCODED) ||
+ facesContext.getAttributes().containsKey(JAVASCRIPT_ENCODED_JSF2))
{
return;
}
@@ -509,6 +511,7 @@ public class HtmlCalendarRenderer
if(styleLocation==null)
{
+ /*
String styleLibrary = (String) component.getAttributes().get(LibraryLocationAware.STYLE_LIBRARY_ATTR);
if (styleLibrary == null)
{
@@ -520,7 +523,7 @@ public class HtmlCalendarRenderer
else
{
TomahawkResourceUtils.addOutputStylesheetResource(facesContext, styleLocation, "theme.css");
- }
+ }*/
}
else if (!RESOURCE_NONE.equals(styleLocation))
{
@@ -535,6 +538,7 @@ public class HtmlCalendarRenderer
if(javascriptLocation==null)
{
+ /*
String javascriptLibrary = (String) component.getAttributes().get(LibraryLocationAware.JAVASCRIPT_LIBRARY_ATTR);
if (javascriptLibrary == null)
{
@@ -551,7 +555,7 @@ public class HtmlCalendarRenderer
TomahawkResourceUtils.addOutputScriptResource(facesContext, javascriptLibrary, "date.js");
TomahawkResourceUtils.addOutputScriptResource(facesContext, javascriptLibrary, "popcalendar.js");
- }
+ }*/
}
else if (!RESOURCE_NONE.equals(javascriptLocation))
{
@@ -564,10 +568,66 @@ public class HtmlCalendarRenderer
// output nothing; presumably the page directly references the necessary javascript
}
- facesContext.getExternalContext().getRequestMap().put(JAVASCRIPT_ENCODED, Boolean.TRUE);
+ facesContext.getAttributes().put(JAVASCRIPT_ENCODED, Boolean.TRUE);
}
-
+ static public void addScriptAndCSSResourcesWithJSF2ResourceAPI(FacesContext facesContext, UIComponent component){
+ // Check to see if javascript has already been written (which could happen if more than one calendar
+ // on the same page). Note that this means that if two calendar controls in the same page have
+ // different styleLocation or scriptLocation settings then all but the first one get ignored.
+ // Having different settings for calendars on the same page would be unusual, so ignore this
+ // for now..
+ if (facesContext.getAttributes().containsKey(JAVASCRIPT_ENCODED_JSF2))
+ {
+ return;
+ }
+
+ // Add the javascript and CSS pages
+
+ String styleLocation = HtmlRendererUtils.getStyleLocation(component);
+
+ if(styleLocation==null)
+ {
+ String styleLibrary = (String) component.getAttributes().get(LibraryLocationAware.STYLE_LIBRARY_ATTR);
+ if (styleLibrary == null)
+ {
+ //addresource.addStyleSheet(facesContext, AddResource.HEADER_BEGIN, HtmlCalendarRenderer.class, "WH/theme.css");
+ TomahawkResourceUtils.addOutputStylesheetResource(facesContext, "oam.custom.calendar.WH", "theme.css");
+ //addresource.addStyleSheet(facesContext, AddResource.HEADER_BEGIN, HtmlCalendarRenderer.class, "DB/theme.css");
+ TomahawkResourceUtils.addOutputStylesheetResource(facesContext, "oam.custom.calendar.DB", "theme.css");
+ }
+ else
+ {
+ TomahawkResourceUtils.addOutputStylesheetResource(facesContext, styleLocation, "theme.css");
+ }
+ }
+
+ String javascriptLocation = HtmlRendererUtils.getJavascriptLocation(component);
+
+ if(javascriptLocation==null)
+ {
+ String javascriptLibrary = (String) component.getAttributes().get(LibraryLocationAware.JAVASCRIPT_LIBRARY_ATTR);
+ if (javascriptLibrary == null)
+ {
+ //addresource.addJavaScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, PrototypeResourceLoader.class, "prototype.js");
+ TomahawkResourceUtils.addOutputScriptResource(facesContext, "oam.custom.prototype", "prototype.js");
+ //addresource.addJavaScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, HtmlCalendarRenderer.class, "date.js");
+ TomahawkResourceUtils.addOutputScriptResource(facesContext, "oam.custom.calendar", "date.js");
+ //addresource.addJavaScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, HtmlCalendarRenderer.class, "popcalendar.js");
+ TomahawkResourceUtils.addOutputScriptResource(facesContext, "oam.custom.calendar", "popcalendar.js");
+ }
+ else
+ {
+ TomahawkResourceUtils.addOutputScriptResource(facesContext, javascriptLibrary, "prototype.js");
+ TomahawkResourceUtils.addOutputScriptResource(facesContext, javascriptLibrary, "date.js");
+ TomahawkResourceUtils.addOutputScriptResource(facesContext, javascriptLibrary, "popcalendar.js");
+
+ }
+ }
+
+ facesContext.getAttributes().put(JAVASCRIPT_ENCODED_JSF2, Boolean.TRUE);
+ }
+
/**
* Creates and returns a String which contains the initialisation data for
* the popup calendar control as a sequence of javascript commands that