You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2006/03/03 00:13:03 UTC
svn commit: r382551 -
/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/ExtensionsPhaseListener.java
Author: imario
Date: Thu Mar 2 15:12:59 2006
New Revision: 382551
URL: http://svn.apache.org/viewcvs?rev=382551&view=rev
Log:
get access to the myfaces body-end script. We have to move it elsewhere later.
Modified:
myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/ExtensionsPhaseListener.java
Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/ExtensionsPhaseListener.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/ExtensionsPhaseListener.java?rev=382551&r1=382550&r2=382551&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/ExtensionsPhaseListener.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/ExtensionsPhaseListener.java Thu Mar 2 15:12:59 2006
@@ -72,7 +72,7 @@
* Renders stuff such as the dummy form and the autoscroll javascript, which goes before the closing </body>
* @throws IOException
*/
- public static void renderCodeBeforeBodyEnd(FacesContext facesContext) throws IOException
+ public void renderCodeBeforeBodyEnd(FacesContext facesContext) throws IOException
{
Object myFacesJavascript = facesContext.getExternalContext().getRequestMap().get(ORG_APACHE_MYFACES_MY_FACES_JAVASCRIPT);
@@ -81,14 +81,33 @@
return;
}
+ facesContext.getExternalContext().getRequestMap().put(ORG_APACHE_MYFACES_MY_FACES_JAVASCRIPT, getCodeBeforeBodyEnd(facesContext));
+ }
+
+ public static String getCodeBeforeBodyEnd(FacesContext facesContext) throws IOException
+ {
ResponseWriter responseWriter = facesContext.getResponseWriter();
HtmlBufferResponseWriterWrapper writerWrapper = HtmlBufferResponseWriterWrapper
.getInstance(responseWriter);
facesContext.setResponseWriter(writerWrapper);
- if (DummyFormUtils.isWriteDummyForm(facesContext))
+ writeCodeBeforeBodyEnd(facesContext);
+
+ //todo: this is just a quick-fix - Sun RI screams if the old responsewriter is null
+ //but how to reset the old response-writer then?
+ if(responseWriter!=null)
+ facesContext.setResponseWriter(responseWriter);
+
+ return "<!-- MYFACES JAVASCRIPT -->\n"+writerWrapper.toString()+"\n";
+ }
+
+ public static void writeCodeBeforeBodyEnd(FacesContext facesContext) throws IOException
+ {
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ if (DummyFormUtils.isWriteDummyForm(facesContext))
{
- DummyFormUtils.writeDummyForm(writerWrapper, DummyFormUtils.getDummyFormParameters(facesContext));
+ DummyFormUtils.writeDummyForm(writer, DummyFormUtils.getDummyFormParameters(facesContext));
}
MyfacesConfig myfacesConfig = MyfacesConfig.getCurrentInstance(facesContext.getExternalContext());
@@ -97,28 +116,19 @@
if (! JavascriptUtils.isJavascriptDetected(facesContext.getExternalContext()))
{
- writerWrapper.startElement("script",null);
- writerWrapper.writeAttribute("attr", HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT,null);
+ writer.startElement("script",null);
+ writer.writeAttribute("attr", HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT,null);
StringBuffer script = new StringBuffer();
script.append("document.location.replace('").
append(facesContext.getApplication().getViewHandler().getResourceURL(facesContext, "/_javascriptDetector_")).append("?goto=").append(facesContext.getApplication().getViewHandler().getActionURL(facesContext, facesContext.getViewRoot().getViewId())).append("');");
- writerWrapper.writeText(script.toString(),null);
- writerWrapper.endElement(HTML.SCRIPT_ELEM);
+ writer.writeText(script.toString(),null);
+ writer.endElement(HTML.SCRIPT_ELEM);
}
}
if (myfacesConfig.isAutoScroll())
{
- JavascriptUtils.renderAutoScrollFunction(facesContext, writerWrapper);
+ JavascriptUtils.renderAutoScrollFunction(facesContext, writer);
}
-
- //todo: this is just a quick-fix - Sun RI screams if the old responsewriter is null
- //but how to reset the old response-writer then?
- if(responseWriter!=null)
- facesContext.setResponseWriter(responseWriter);
-
- facesContext.getExternalContext().getRequestMap().put(ORG_APACHE_MYFACES_MY_FACES_JAVASCRIPT, "<!-- MYFACES JAVASCRIPT -->\n"+writerWrapper.toString()+"\n");
- }
-
-
+ }
}