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/05/15 00:05:39 UTC

svn commit: r944499 - in /myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces: custom/autoscroll/ tomahawk/application/ tomahawk/util/

Author: lu4242
Date: Fri May 14 22:05:39 2010
New Revision: 944499

URL: http://svn.apache.org/viewvc?rev=944499&view=rev
Log:
TOMAHAWK-1504 Update autoscroll feature to JSF 2

Added:
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBehavior.java
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBehaviorTagHandler.java
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBodyScript.java
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBodyScriptRenderer.java
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollHiddenField.java
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollHiddenFieldRenderer.java
Modified:
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/tomahawk/application/ResourceViewHandlerWrapper.java
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/tomahawk/util/TomahawkResourceUtils.java

Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBehavior.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBehavior.java?rev=944499&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBehavior.java (added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBehavior.java Fri May 14 22:05:39 2010
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.autoscroll;
+
+import javax.faces.component.behavior.ClientBehaviorBase;
+import javax.faces.component.behavior.ClientBehaviorContext;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFBehavior;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
+/**
+ * Adds to a command link or button a javascript that enable automatic scrolling 
+ * behavior after the event is invoked.
+ * 
+ * @since 1.1.10
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+@JSFBehavior(name="t:autoscroll",bodyContent="empty")
+public class AutoscrollBehavior extends ClientBehaviorBase
+{
+
+    public static final String BEHAVIOR_ID = "org.apache.myfaces.custom.autoscroll.AutoscrollBehavior";
+    
+    @Override
+    public String getScript(ClientBehaviorContext behaviorContext)
+    {
+        FormInfo nestedFormInfo = RendererUtils.findNestingForm(behaviorContext.getComponent(), behaviorContext.getFacesContext());
+        StringBuffer script = new StringBuffer();
+        HtmlRendererUtils.appendAutoScrollAssignment(script, nestedFormInfo.getFormName());
+        return script.toString();
+    }
+    
+    /**
+     * The event that this client behavior should be attached.
+     * 
+     * @return
+     */
+    @JSFProperty
+    private String getEvent()
+    {
+        return null;
+    }
+}

Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBehaviorTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBehaviorTagHandler.java?rev=944499&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBehaviorTagHandler.java (added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBehaviorTagHandler.java Fri May 14 22:05:39 2010
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.autoscroll;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.view.facelets.BehaviorConfig;
+import javax.faces.view.facelets.BehaviorHandler;
+import javax.faces.view.facelets.FaceletContext;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
+
+/**
+ * @since 1.1.10
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+@JSFFaceletTag(name="t:autoscroll", behaviorClass="org.apache.myfaces.custom.autoscroll.AutoscrollBehavior")
+public class AutoscrollBehaviorTagHandler extends BehaviorHandler
+{
+
+    public static final String AUTOSCROLL_TAG_ON_PAGE = "oam.autoscroll.AUTOSCROLL_TAG_ON_PAGE";
+    
+    public AutoscrollBehaviorTagHandler(BehaviorConfig config)
+    {
+        super(config);
+    }
+
+    @Override
+    public void apply(FaceletContext ctx, UIComponent parent)
+            throws IOException
+    {
+        super.apply(ctx, parent);
+        
+        UIViewRoot root = getViewRoot(ctx, parent);
+        
+        if (!root.getAttributes().containsKey(AUTOSCROLL_TAG_ON_PAGE))
+        {
+            root.getAttributes().put(AUTOSCROLL_TAG_ON_PAGE, Boolean.TRUE);
+        }
+    }
+    
+    private UIViewRoot getViewRoot(FaceletContext ctx, UIComponent parent)
+    {
+        UIComponent c = parent;
+        do
+        {
+            if (c instanceof UIViewRoot)
+            {
+                return (UIViewRoot) c;
+            }
+            else
+            {
+                c = c.getParent();
+            }
+        } while (c != null);
+
+        return ctx.getFacesContext().getViewRoot();
+    }
+}

Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBodyScript.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBodyScript.java?rev=944499&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBodyScript.java (added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBodyScript.java Fri May 14 22:05:39 2010
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.autoscroll;
+
+import javax.faces.component.UIOutput;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
+import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
+import org.apache.myfaces.tomahawk.util.TomahawkResourceUtils;
+
+/**
+ * This component is used internally to render the script that comes before
+ * render </body>  
+ * 
+ * @since 1.1.10
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+@JSFComponent
+public class AutoscrollBodyScript extends UIOutput
+{
+    public static final String COMPONENT_TYPE = "org.apache.myfaces.custom.autoscroll.AutoscrollBodyScript";
+    public static final String COMPONENT_FAMILY = "org.apache.myfaces.custom.autoscroll.AutoscrollBodyScript";
+    public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.custom.autoscroll.AutoscrollBodyScript";
+
+    public AutoscrollBodyScript()
+    {
+        this.getAttributes().put(JSFAttr.TARGET_ATTR, TomahawkResourceUtils.BODY_LOCATION);
+    }
+    
+    @Override
+    public String getFamily()
+    {
+        return COMPONENT_FAMILY;
+    }
+
+}

Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBodyScriptRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBodyScriptRenderer.java?rev=944499&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBodyScriptRenderer.java (added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollBodyScriptRenderer.java Fri May 14 22:05:39 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.autoscroll;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
+import org.apache.myfaces.renderkit.html.util.AddResource;
+import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
+import org.apache.myfaces.shared_tomahawk.config.MyfacesConfig;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+
+/**
+ * 
+ * @since 1.1.10
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+@JSFRenderer(renderKitId = "HTML_BASIC",
+        family = "org.apache.myfaces.custom.autoscroll.AutoscrollBodyScript",
+        type = "org.apache.myfaces.custom.autoscroll.AutoscrollBodyScript")
+public class AutoscrollBodyScriptRenderer extends HtmlRenderer
+{    
+    @Override
+    public void encodeEnd(FacesContext context, UIComponent component)
+            throws IOException
+    {
+        //Check npe
+        super.encodeEnd(context, component);
+        
+        //AddResource addResource = AddResourceFactory.getInstance(context);
+        
+        //Only render it if we are not buffering the request by addResource
+        //if (MyfacesConfig.getCurrentInstance(context.getExternalContext()).isAutoScroll())
+        //{
+            ResponseWriter writer = context.getResponseWriter();
+            HtmlRendererUtils.renderAutoScrollFunction(context, writer);
+            
+            HtmlRendererUtils.renderFormSubmitScript(context);
+        //}
+    }
+}

Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollHiddenField.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollHiddenField.java?rev=944499&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollHiddenField.java (added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollHiddenField.java Fri May 14 22:05:39 2010
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.autoscroll;
+
+import javax.faces.component.UIOutput;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
+import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
+import org.apache.myfaces.tomahawk.util.TomahawkResourceUtils;
+
+/**
+ * This component is used internally to render an autoscroll hidden field at the end
+ * of the form.
+ * 
+ * @since 1.1.10
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+@JSFComponent
+public class AutoscrollHiddenField extends UIOutput
+{
+    public static final String COMPONENT_TYPE = "org.apache.myfaces.custom.autoscroll.AutoscrollHiddenField";
+    public static final String COMPONENT_FAMILY = "org.apache.myfaces.custom.autoscroll.AutoscrollHiddenField";
+    public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.custom.autoscroll.AutoscrollHiddenField";
+    
+    public AutoscrollHiddenField()
+    {
+        this.getAttributes().put(JSFAttr.TARGET_ATTR, TomahawkResourceUtils.FORM_LOCATION);
+    }
+    
+    @Override
+    public String getFamily()
+    {
+        return COMPONENT_FAMILY;
+    }
+}

Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollHiddenFieldRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollHiddenFieldRenderer.java?rev=944499&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollHiddenFieldRenderer.java (added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/autoscroll/AutoscrollHiddenFieldRenderer.java Fri May 14 22:05:39 2010
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.autoscroll;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIForm;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
+import org.apache.myfaces.shared_tomahawk.config.MyfacesConfig;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlFormRendererBase;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+
+/**
+ * 
+ * @since 1.1.10
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+@JSFRenderer(renderKitId = "HTML_BASIC",
+    family = "org.apache.myfaces.custom.autoscroll.AutoscrollHiddenField",
+    type = "org.apache.myfaces.custom.autoscroll.AutoscrollHiddenField")
+public class AutoscrollHiddenFieldRenderer extends HtmlRenderer
+{
+    private static final String SCROLL_HIDDEN_INPUT = "org.apache.myfaces.SCROLL_HIDDEN_INPUT";
+    
+    @Override
+    public void encodeEnd(FacesContext context, UIComponent component)
+            throws IOException
+    {
+        //Check npe
+        super.encodeEnd(context, component);
+        
+        //It is necessary a small to obtain the renderer parent of this field.
+        //In theory the current component is called from a form renderer,
+        //because this component is only added by
+        //facesContext.getViewRoot().addComponentResource()
+        //with target="form".
+        component.popComponentFromEL(context);
+        try
+        {
+            UIComponent form = UIComponent.getCurrentComponent(context);
+
+            if (form instanceof UIForm)
+            {
+                ResponseWriter writer = context.getResponseWriter();
+                if (MyfacesConfig.getCurrentInstance(context.getExternalContext()).isAutoScroll())
+                {
+                    //Render as original, to prevent duplicate hidden input rendering
+                    HtmlFormRendererBase.renderScrollHiddenInputIfNecessary(form, context, writer);
+                }
+                else
+                {
+                    // No automatic scroll, but use of t:autoscroll, so force the rendering of the hidden field.
+                    // It is not necessary to check if the hidden input has been rendered, because there is no
+                    // other component that renders it.
+                    HtmlRendererUtils.renderAutoScrollHiddenInput(context, writer);
+                    context.getExternalContext().getRequestMap().put(getScrollHiddenInputName(context, form), Boolean.TRUE);
+                }
+            }
+        }
+        finally
+        {
+            //Restore the stack
+            component.pushComponentToEL(context, component);
+        }
+    }
+    
+    private static String getScrollHiddenInputName(FacesContext facesContext, UIComponent form) {
+        StringBuffer buf = new StringBuffer();
+        buf.append(SCROLL_HIDDEN_INPUT);
+        buf.append("_");
+        buf.append(form.getClientId(facesContext));
+        return buf.toString();
+    }
+}

Modified: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/tomahawk/application/ResourceViewHandlerWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/tomahawk/application/ResourceViewHandlerWrapper.java?rev=944499&r1=944498&r2=944499&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/tomahawk/application/ResourceViewHandlerWrapper.java (original)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/tomahawk/application/ResourceViewHandlerWrapper.java Fri May 14 22:05:39 2010
@@ -28,6 +28,15 @@ import javax.faces.component.UIComponent
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 
+import org.apache.myfaces.custom.autoscroll.AutoscrollBehaviorTagHandler;
+import org.apache.myfaces.custom.autoscroll.AutoscrollBodyScript;
+import org.apache.myfaces.custom.autoscroll.AutoscrollHiddenField;
+import org.apache.myfaces.renderkit.html.util.AddResource;
+import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
+import org.apache.myfaces.shared_tomahawk.config.MyfacesConfig;
+import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
+import org.apache.myfaces.tomahawk.util.TomahawkResourceUtils;
+
 public class ResourceViewHandlerWrapper extends ViewHandlerWrapper
 {
     private ViewHandler _delegate;
@@ -48,6 +57,35 @@ public class ResourceViewHandlerWrapper 
     public void renderView(FacesContext context, UIViewRoot viewToRender)
             throws IOException, FacesException
     {
+        if (MyfacesConfig.getCurrentInstance(context.getExternalContext()).isAutoScroll() ||
+            viewToRender.getAttributes().containsKey(AutoscrollBehaviorTagHandler.AUTOSCROLL_TAG_ON_PAGE))
+        {
+            AddResource addResource = AddResourceFactory.getInstance(context);
+
+            if (!addResource.requiresBuffer())
+            {
+                //If the response is buffered, addResource instance takes
+                //the responsability of render this script.
+                AutoscrollBodyScript autoscrollBodyScript = (AutoscrollBodyScript) 
+                    context.getApplication().createComponent(context, 
+                        AutoscrollBodyScript.COMPONENT_TYPE,
+                        AutoscrollBodyScript.DEFAULT_RENDERER_TYPE);
+                autoscrollBodyScript.setTransient(true);
+                autoscrollBodyScript.getAttributes().put(
+                        JSFAttr.TARGET_ATTR, 
+                        TomahawkResourceUtils.BODY_LOCATION);
+                viewToRender.addComponentResource(context, autoscrollBodyScript);
+            }
+            
+            AutoscrollHiddenField autoscrollHiddenField = (AutoscrollHiddenField) context.getApplication().
+                createComponent(context, 
+                        AutoscrollHiddenField.COMPONENT_TYPE,
+                        AutoscrollHiddenField.DEFAULT_RENDERER_TYPE);
+            autoscrollHiddenField.setTransient(true);
+            autoscrollHiddenField.getAttributes().put(JSFAttr.TARGET_ATTR, TomahawkResourceUtils.FORM_LOCATION);
+            viewToRender.addComponentResource(context, autoscrollHiddenField);
+        }
+        
         _publishPreRenderViewAddResourceEvent(context, viewToRender);
         super.renderView(context, viewToRender);
     }

Modified: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/tomahawk/util/TomahawkResourceUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/tomahawk/util/TomahawkResourceUtils.java?rev=944499&r1=944498&r2=944499&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/tomahawk/util/TomahawkResourceUtils.java (original)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/tomahawk/util/TomahawkResourceUtils.java Fri May 14 22:05:39 2010
@@ -23,18 +23,22 @@ import javax.faces.application.ResourceH
 import javax.faces.component.UIOutput;
 import javax.faces.context.FacesContext;
 
+import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.util.ResourceUtils;
+
 public class TomahawkResourceUtils
 {
-    public static final String DEFAULT_SCRIPT_RENDERER_TYPE = "javax.faces.resource.Script";
-    public static final String DEFAULT_STYLESHEET_RENDERER_TYPE = "javax.faces.resource.Stylesheet";
-    public static final String HEAD_LOCATION = "head"; 
+    public static final String HEAD_LOCATION = "head";
+    public static final String BODY_LOCATION = HTML.BODY_ELEM;
+    public static final String FORM_LOCATION = HTML.FORM_ELEM;
     
     public static void addOutputScriptResource(final FacesContext facesContext, final String libraryName, final String resourceName)
     {
         UIOutput outputScript = (UIOutput) facesContext.getApplication().
-            createComponent(facesContext, "javax.faces.Output", DEFAULT_SCRIPT_RENDERER_TYPE);
-        outputScript.getAttributes().put("library", libraryName);
-        outputScript.getAttributes().put("name", resourceName);
+            createComponent(facesContext, ResourceUtils.JAVAX_FACES_OUTPUT_COMPONENT_TYPE, ResourceUtils.DEFAULT_SCRIPT_RENDERER_TYPE);
+        outputScript.getAttributes().put(JSFAttr.LIBRARY_ATTR, libraryName);
+        outputScript.getAttributes().put(JSFAttr.NAME_ATTR, resourceName);
         outputScript.setTransient(true);
         outputScript.setId(facesContext.getViewRoot().createUniqueId());
         facesContext.getViewRoot().addComponentResource(facesContext, outputScript);
@@ -43,9 +47,9 @@ public class TomahawkResourceUtils
     public static void addOutputStylesheetResource(final FacesContext facesContext, final String libraryName, final String resourceName)
     {
         UIOutput outputStylesheet = (UIOutput) facesContext.getApplication().
-            createComponent(facesContext, "javax.faces.Output", DEFAULT_STYLESHEET_RENDERER_TYPE);
-        outputStylesheet.getAttributes().put("library", libraryName);
-        outputStylesheet.getAttributes().put("name", resourceName);
+            createComponent(facesContext, ResourceUtils.JAVAX_FACES_OUTPUT_COMPONENT_TYPE, ResourceUtils.DEFAULT_STYLESHEET_RENDERER_TYPE);
+        outputStylesheet.getAttributes().put(JSFAttr.LIBRARY_ATTR, libraryName);
+        outputStylesheet.getAttributes().put(JSFAttr.NAME_ATTR, resourceName);
         outputStylesheet.setTransient(true);
         outputStylesheet.setId(facesContext.getViewRoot().createUniqueId());
         facesContext.getViewRoot().addComponentResource(facesContext, outputStylesheet);
@@ -54,9 +58,9 @@ public class TomahawkResourceUtils
     public static void addInlineOutputStylesheetResource(final FacesContext facesContext, Object value)
     {
         UIOutput stylesheet = (UIOutput) facesContext.getApplication().createComponent(facesContext, 
-                "javax.faces.Output", "javax.faces.Text");
+                ResourceUtils.JAVAX_FACES_OUTPUT_COMPONENT_TYPE, ResourceUtils.JAVAX_FACES_TEXT_RENDERER_TYPE);
         UIOutput outputStylesheet = (UIOutput) facesContext.getApplication().
-            createComponent(facesContext, "javax.faces.Output", DEFAULT_STYLESHEET_RENDERER_TYPE);
+            createComponent(facesContext, ResourceUtils.JAVAX_FACES_OUTPUT_COMPONENT_TYPE, ResourceUtils.DEFAULT_STYLESHEET_RENDERER_TYPE);
         stylesheet.setValue( value);
         stylesheet.setTransient(true);
         stylesheet.setId(facesContext.getViewRoot().createUniqueId());
@@ -69,12 +73,12 @@ public class TomahawkResourceUtils
     public static void addInlineOutputScriptResource(final FacesContext facesContext, String target, Object value)
     {
         UIOutput script = (UIOutput) facesContext.getApplication().createComponent(facesContext, 
-                "javax.faces.Output", "javax.faces.Text");
+                ResourceUtils.JAVAX_FACES_OUTPUT_COMPONENT_TYPE, ResourceUtils.JAVAX_FACES_TEXT_RENDERER_TYPE);
         UIOutput outputScript = (UIOutput) facesContext.getApplication().
-            createComponent(facesContext, "javax.faces.Output", DEFAULT_SCRIPT_RENDERER_TYPE);
+            createComponent(facesContext, ResourceUtils.JAVAX_FACES_OUTPUT_COMPONENT_TYPE, ResourceUtils.DEFAULT_SCRIPT_RENDERER_TYPE);
         if (target != null)
         {
-            script.getAttributes().put("target", target);
+            script.getAttributes().put(JSFAttr.TARGET_ATTR, target);
         }
         script.setValue( value);
         script.setTransient(true);