You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/07/04 00:03:31 UTC

svn commit: r673836 [7/8] - in /myfaces/tomahawk/trunk: core/src/main/java/org/apache/myfaces/custom/buffer/ core/src/main/java/org/apache/myfaces/custom/calendar/ core/src/main/java/org/apache/myfaces/custom/captcha/ core/src/main/java/org/apache/myfa...

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSupport.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSupport.java?rev=673836&r1=673835&r2=673836&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSupport.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSupport.java Thu Jul  3 15:03:29 2008
@@ -1,444 +1,444 @@
-/*
- * 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.ppr;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.lang.StringUtils;
-import org.apache.myfaces.custom.dojo.DojoConfig;
-import org.apache.myfaces.custom.dojo.DojoUtils;
-import org.apache.myfaces.custom.subform.SubForm;
-import org.apache.myfaces.renderkit.html.util.AddResource;
-import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
-import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
-import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
-
-import javax.faces.FacesException;
-import javax.faces.component.UIComponent;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.ArrayList;
-
-/**
- * @author Ernst Fastl
- * @author Thomas Spiegl
- */
-public class PPRSupport
-{
-    private static Log log = LogFactory.getLog(PPRSupport.class);
-
-    private static final String PPR_INITIALIZED = "org.apache.myfaces.ppr.INITIALIZED";
-
-    private static final String PPR_JS_FILE = "ppr.js";
-
-    private static final String ADD_PARTIAL_TRIGGER_FUNCTION = "addPartialTrigger";
-
-    private static final String ADD_PERIODICAL_TRIGGER_FUNCTION = "addPeriodicalTrigger";
-
-    private static final String ADD_PARTIAL_TRIGGER_PATTERN_FUNCTION = "addPartialTriggerPattern";
-
-    private static final String SET_SUBFORM_ID_FUNCTION = "setSubFormId";
-
-    private static final String SET_COMPONENT_UPDATE_FUNCTION = "setComponentUpdateFunction";
-
-    private static final String ADD_INLINE_LOADING_MESSAGE_FUNCTION = "addInlineLoadingMessage";
-
-    private static final String MY_FACES_PPR_INIT_CODE = "new org.apache.myfaces.PPRCtrl";
-
-
-    public final static String COMMAND_CONFIGURED_MARK = PPRSupport.class.getName() + "_CONFIGURED";
-
-    public final static String PROCESS_COMPONENTS = PPRSupport.class.getName() + "PROCESS_COMPONENTS";
-
-
-    public static boolean isPartialRequest(FacesContext facesContext)
-    {
-        return PPRPhaseListener.isPartialRequest(facesContext);
-    }
-
-
-    /**
-     * Renders inline JavaScript registering an onLoad function for:
-     * <ul>
-     * <li>Initializing the PPRCtrl for the current Form</li>
-     * </ul>
-     *
-     * @param facesContext the current {@link javax.faces.context.FacesContext}
-     * @param uiComponent  the currently rendered {@link PPRPanelGroup}
-     * @throws java.io.IOException if the underlying Layer throws an {@link java.io.IOException}
-     *                             it is passed through
-     */
-    public static void initPPR(FacesContext facesContext, PPRPanelGroup uiComponent) throws IOException
-    {
-        //if(isPartialRequest(facesContext)) {
-        //    return;
-        //}
-        final ExternalContext externalContext = facesContext.getExternalContext();
-        final Map requestMap = externalContext.getRequestMap();
-
-        // Do not render the JavaScript if answering to a PPR response
-
-        //Initialize the client side PPR engine
-        if (!requestMap.containsKey(PPR_INITIALIZED)) {
-            requestMap.put(PPR_INITIALIZED, Boolean.TRUE);
-
-            String encoding = "UTF-8"; // Hardcoded default
-            if (facesContext.getResponseWriter().getCharacterEncoding() != null) {
-                encoding = facesContext.getResponseWriter().getCharacterEncoding();
-            }
-
-            DojoConfig currentConfig = DojoUtils.getDjConfigInstance(facesContext);
-            currentConfig.setBindEncoding(encoding);
-
-            String javascriptLocation = (String) uiComponent.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
-            AddResource addResource = AddResourceFactory.getInstance(facesContext);
-            DojoUtils.addMainInclude(facesContext, uiComponent, javascriptLocation, currentConfig);
-            DojoUtils.addRequire(facesContext, uiComponent, "dojo.io.*");
-            DojoUtils.addRequire(facesContext, uiComponent, "dojo.event.*");
-            DojoUtils.addRequire(facesContext, uiComponent, "dojo.xml.*");
-            addResource.addJavaScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, PPRPanelGroup.class, PPR_JS_FILE);
-        }
-    }
-
-    /**
-     * Renders inline JavaScript registering an onLoad function for:
-     * <ul>
-     * <li>Initializing the PPRCtrl for the current Form</li>
-     * <li>Registering partialTriggers</li>
-     * <li>Registering partialTriggerPatterns</li>
-     * <li>Starting periodical updates</li>
-     * <li>Registering inline Loading messages</li>
-     * </ul>
-     *
-     * @param facesContext the current {@link FacesContext}
-     * @param pprGroup     the currently rendered {@link PPRPanelGroup}
-     * @throws IOException if the underlying Layer throws an {@link IOException}
-     *                     it is passed through
-     */
-    public static void encodeJavaScript(FacesContext facesContext, PPRPanelGroup pprGroup) throws IOException
-    {
-        StringBuffer script = new StringBuffer();
-
-        // all JS is put inside a function passed to dojoOnLoad
-        // this is necessary in order to be able to replace all button onClick
-        // handlers
-
-        script.append("dojo.addOnLoad( function(){ ");
-
-        String pprCtrlReference = initPPRFormControl(facesContext, pprGroup, script);
-
-        encodePeriodicalUpdates(facesContext, pprGroup, script, pprCtrlReference);
-
-        encodePartialTriggerPattern(facesContext, pprGroup, script, pprCtrlReference);
-
-        encodeSubFormFunction(facesContext, pprGroup, script, pprCtrlReference);
-
-        encodeDomUpdateConfig(facesContext, pprGroup, script, pprCtrlReference);
-
-        encodeInlineLoadMsg(facesContext, pprGroup, script, pprCtrlReference);
-
-        encodePartialTriggers(facesContext, pprGroup, script, pprCtrlReference);
-
-        // closing the dojo.addOnLoad call
-        script.append("});");
-
-        //Really render the script
-        renderInlineScript(facesContext, pprGroup, script.toString());
-    }
-
-    public static void encodeJavaScriptTriggerOnly(FacesContext context, UIComponent uiComponent, PPRPanelGroup pprGroup,
-                                        PartialTriggerParser.PartialTrigger trigger) throws IOException
-    {
-        StringBuffer script = new StringBuffer();
-        script.append("dojo.addOnLoad( function(){ ");
-        String pprCtrlReference = initPPRFormControl(context, pprGroup, script);
-        String clientId = pprGroup.getClientId(context);
-        encodePartialTrigger(context, script, pprCtrlReference, clientId, uiComponent, trigger);
-        // closing the dojo.addOnLoad call
-        script.append("});");
-
-        //Really render the script
-        renderInlineScript(context, pprGroup, script.toString());
-    }
-
-    private static void encodePartialTrigger(FacesContext facesContext,
-                                             StringBuffer script,
-                                             String pprCtrlReference,
-                                             String clientId,
-                                             UIComponent partialTriggerComponent,
-                                             PartialTriggerParser.PartialTrigger trigger)
-    {
-        String partialTriggerClientId;
-        String partialTriggerId = trigger.getPartialTriggerId();
-        if (partialTriggerComponent == null) {
-            partialTriggerComponent = facesContext.getViewRoot().findComponent(partialTriggerId);
-        }
-        if (partialTriggerComponent != null) {
-            partialTriggerClientId = partialTriggerComponent.getClientId(facesContext);
-            script.append(pprCtrlReference + "." + ADD_PARTIAL_TRIGGER_FUNCTION + "('" + partialTriggerClientId + "'," + encodeArray(trigger.getEventHooks()) + ",'" + clientId + "');");
-        }
-        else {
-            if (log.isDebugEnabled()) {
-                log.debug("PPRPanelGroupRenderer Component with id " + partialTriggerId + " not found!");
-            }
-        }
-    }
-
-    private static void encodePartialTriggers(FacesContext context, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference)
-    {
-        String clientId = pprGroup.getClientId(context);
-        UIComponent partialTriggerComponent;
-
-        List partialTriggerIds = pprGroup.parsePartialTriggers();
-        for (int i = 0; i < partialTriggerIds.size(); i++) {
-            PartialTriggerParser.PartialTrigger trigger = (PartialTriggerParser.PartialTrigger) partialTriggerIds
-                .get(i);
-            partialTriggerComponent = pprGroup.findComponent(trigger.getPartialTriggerId());
-            encodePartialTrigger(context, script, pprCtrlReference, clientId, partialTriggerComponent, trigger);
-        }
-    }
-
-    private static void encodePartialTriggerPattern(FacesContext context, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference)
-    {
-        String clientId = pprGroup.getClientId(context);
-
-        String partialTriggerPattern = pprGroup.getPartialTriggerPattern();
-
-        //handle partial trigger patterns
-        if (partialTriggerPattern != null && partialTriggerPattern.trim().length() > 0) {
-            script.append(pprCtrlReference + "." + ADD_PARTIAL_TRIGGER_PATTERN_FUNCTION + "('" + partialTriggerPattern + "','" + clientId + "');");
-        }
-
-    }
-
-    private static void encodeInlineLoadMsg(FacesContext context, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference)
-    {
-        String clientId = pprGroup.getClientId(context);
-        String inlineLoadingMessage = pprGroup.getInlineLoadingMessage();
-
-        //handle inline loading messages
-        if (inlineLoadingMessage != null && inlineLoadingMessage.trim().length() > 0) {
-            script.append(pprCtrlReference + "." + ADD_INLINE_LOADING_MESSAGE_FUNCTION + "('" + inlineLoadingMessage + "','" + clientId + "');");
-        }
-    }
-
-    private static void encodeSubFormFunction(FacesContext context, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference)
-    {
-        String clientId = pprGroup.getClientId(context);
-        SubForm subFormParent = findParentSubForm(pprGroup);
-        if (subFormParent != null) {
-            script.append(pprCtrlReference + "." + SET_SUBFORM_ID_FUNCTION + "('" + subFormParent.getId() + "','" + clientId + "');");
-        }
-    }
-
-    private static void encodeDomUpdateConfig(FacesContext context, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference)
-    {
-        String componentUpdateFunction = pprGroup.getComponentUpdateFunction();
-        if (!StringUtils.isEmpty(componentUpdateFunction)) {
-            script.append(pprCtrlReference + "." + SET_COMPONENT_UPDATE_FUNCTION+ "('" + componentUpdateFunction + "');");
-        }
-    }
-
-    private static void encodePeriodicalUpdates(FacesContext facesContext, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference)
-    {
-        String clientId = pprGroup.getClientId(facesContext);
-
-        //Handle periodical updates
-        if (pprGroup.getPeriodicalUpdate() != null) {
-            List partialTriggers = pprGroup.parsePeriodicalTriggers();
-            if (partialTriggers.size() == 0) {
-                Integer wait = null;
-                if (pprGroup.getExcludeFromStoppingPeriodicalUpdate() != null) {
-                    wait = pprGroup.getWaitBeforePeriodicalUpdate();
-                }
-                script.append(pprCtrlReference + ".startPeriodicalUpdate(" + pprGroup.getPeriodicalUpdate() + ",'" + clientId + "', " + wait + ");");
-            }
-            else {
-                String periodicalTriggerId;
-                String periodicalTriggerClientId;
-                UIComponent periodicalTriggerComponent;
-                for (int i = 0; i < partialTriggers.size(); i++) {
-                    PartialTriggerParser.PartialTrigger trigger = (PartialTriggerParser.PartialTrigger) partialTriggers
-                        .get(i);
-                    periodicalTriggerId = trigger.getPartialTriggerId();
-                    periodicalTriggerComponent = pprGroup.findComponent(periodicalTriggerId);
-                    if (periodicalTriggerComponent == null) {
-                        periodicalTriggerComponent = facesContext.getViewRoot().findComponent(periodicalTriggerId);
-                    }
-
-                    // Component found
-                    if (periodicalTriggerComponent != null) {
-                        periodicalTriggerClientId = periodicalTriggerComponent.getClientId(facesContext);
-                        script.append(pprCtrlReference + "." + ADD_PERIODICAL_TRIGGER_FUNCTION +
-                            "('" + periodicalTriggerClientId + "'," +
-                            encodeArray(trigger.getEventHooks()) + ",'" + clientId + "', " +
-                            pprGroup.getPeriodicalUpdate() + ");");
-
-                        // Component missing
-                    }
-                    else {
-                        if (log.isDebugEnabled()) {
-                            log.debug("PPRPanelGroupRenderer Component with id " + periodicalTriggerId + " not found!");
-                        }
-                    }
-                }
-            }
-
-            String idRegex = pprGroup.getExcludeFromStoppingPeriodicalUpdate();
-
-            if (idRegex != null) {
-                script.append(pprCtrlReference + ".excludeFromStoppingPeriodicalUpdate('" + idRegex + "');");
-            }
-        }
-    }
-
-    private static String initPPRFormControl(FacesContext facesContext, PPRPanelGroup pprGroup, StringBuffer script)
-    {
-        FormInfo fi = RendererUtils.findNestingForm(pprGroup, facesContext);
-        if (fi == null) {
-            throw new FacesException("PPRPanelGroup must be embedded in a form.");
-        }
-        final String formName = fi.getFormName();
-        Map requestMap = facesContext.getExternalContext().getRequestMap();
-
-        String pprCtrlReference = "dojo.byId('" + formName + "').myFacesPPRCtrl";
-
-        //Each form containing PPRPanelGroups has its own PPRCtrl
-
-        // the following complicated stuff should deal with the following use-cases:
-        // 1) normal create ppr on non-ppr-response
-        // 2) create ppr on ppr-response
-        // 3) add triggers to ppr on ppr-response (e.g to commands within uidata)
-        //
-        // get state of the ppr component ...
-        boolean pprInited = pprGroup.getInitializationSent();
-        if (!PPRSupport.isPartialRequest(facesContext))
-        {
-            // ... but override with current request state if we are not within an
-            // ppr request.
-            pprInited = Boolean.TRUE.equals(requestMap.get(PPR_INITIALIZED + "." + formName));
-        }
-
-        if (!pprInited) {
-            pprGroup.setInitializationSent(true);
-            requestMap.put(PPR_INITIALIZED + "." + formName, Boolean.TRUE);
-
-            script.append(pprCtrlReference + "=" + MY_FACES_PPR_INIT_CODE + "('" + formName + "'," + pprGroup.getShowDebugMessages().booleanValue() + "," + pprGroup.getStateUpdate().booleanValue() + ");\n");
-
-            if (pprGroup.getPeriodicalUpdate() != null) {
-                script.append(pprCtrlReference + ".registerOnSubmitInterceptor();");
-            }
-        }
-        return pprCtrlReference;
-    }
-
-    public static SubForm findParentSubForm(UIComponent base)
-    {
-        if (base == null) {
-            return null;
-        }
-        if (base instanceof SubForm) {
-            return (SubForm) base;
-        }
-        return findParentSubForm(base.getParent());
-    }
-
-    private static String encodeArray(List eventHooks)
-    {
-        if (eventHooks == null || eventHooks.size() == 0) {
-            return "null";
-        }
-        else {
-            StringBuffer buf = new StringBuffer();
-            buf.append("[");
-
-            for (int i = 0; i < eventHooks.size(); i++) {
-                if (i > 0) {
-                    buf.append(",");
-                }
-                String eventHook = (String) eventHooks.get(i);
-                buf.append("'");
-                buf.append(eventHook);
-                buf.append("'");
-            }
-            buf.append("]");
-
-            return buf.toString();
-        }
-    }
-
-    /**
-     * Helper to write an inline javascript at the exact resource location
-     * of the call.
-     *
-     * @param facesContext The current faces-context.
-     * @param component    The component for which the script is written.
-     * @param script       The script to be written.
-     * @throws IOException A forwarded exception from the underlying renderer.
-     */
-    private static void renderInlineScript(FacesContext facesContext, UIComponent component, String script) throws IOException
-    {
-        ResponseWriter writer = facesContext.getResponseWriter();
-        writer.startElement(HTML.SCRIPT_ELEM, component);
-        writer.writeAttribute(HTML.TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
-        writer.write(script);
-        writer.endElement(HTML.SCRIPT_ELEM);
-    }
-
-    /**
-     * get all components by given id-string-list ("id1,id2,id3") and appropriate type
-     *
-     * @param context
-     * @param comp
-     * @param idList
-     * @param desiredType
-     * @return
-     */
-    public static List getComponentsByCommaSeparatedIdList(FacesContext context, UIComponent comp, String idList, Class desiredType)
-    {
-        List retval = new ArrayList();
-        UIComponent currentComponent = null;
-        String[] ids = StringUtils.split(idList, ',');
-        for (int i = 0; i < ids.length; i++) {
-            String id = StringUtils.trim(ids[i]);
-            currentComponent = comp.findComponent(id);
-            if (nullSafeCheckComponentType(desiredType, currentComponent)) {
-                retval.add(currentComponent);
-            }
-            else {
-                currentComponent = context.getViewRoot().findComponent(id);
-                if (nullSafeCheckComponentType(desiredType, currentComponent)) {
-                    retval.add(currentComponent);
-                }
-            }
-        }
-        return retval;
-    }
-
-    private static boolean nullSafeCheckComponentType(Class desiredType, UIComponent currentComponent)
-    {
-        return currentComponent != null && (desiredType == null || desiredType.isAssignableFrom(currentComponent.getClass()));
-    }
-}
+/*
+ * 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.ppr;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
+import org.apache.myfaces.custom.dojo.DojoConfig;
+import org.apache.myfaces.custom.dojo.DojoUtils;
+import org.apache.myfaces.custom.subform.SubForm;
+import org.apache.myfaces.renderkit.html.util.AddResource;
+import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
+import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+
+/**
+ * @author Ernst Fastl
+ * @author Thomas Spiegl
+ */
+public class PPRSupport
+{
+    private static Log log = LogFactory.getLog(PPRSupport.class);
+
+    private static final String PPR_INITIALIZED = "org.apache.myfaces.ppr.INITIALIZED";
+
+    private static final String PPR_JS_FILE = "ppr.js";
+
+    private static final String ADD_PARTIAL_TRIGGER_FUNCTION = "addPartialTrigger";
+
+    private static final String ADD_PERIODICAL_TRIGGER_FUNCTION = "addPeriodicalTrigger";
+
+    private static final String ADD_PARTIAL_TRIGGER_PATTERN_FUNCTION = "addPartialTriggerPattern";
+
+    private static final String SET_SUBFORM_ID_FUNCTION = "setSubFormId";
+
+    private static final String SET_COMPONENT_UPDATE_FUNCTION = "setComponentUpdateFunction";
+
+    private static final String ADD_INLINE_LOADING_MESSAGE_FUNCTION = "addInlineLoadingMessage";
+
+    private static final String MY_FACES_PPR_INIT_CODE = "new org.apache.myfaces.PPRCtrl";
+
+
+    public final static String COMMAND_CONFIGURED_MARK = PPRSupport.class.getName() + "_CONFIGURED";
+
+    public final static String PROCESS_COMPONENTS = PPRSupport.class.getName() + "PROCESS_COMPONENTS";
+
+
+    public static boolean isPartialRequest(FacesContext facesContext)
+    {
+        return PPRPhaseListener.isPartialRequest(facesContext);
+    }
+
+
+    /**
+     * Renders inline JavaScript registering an onLoad function for:
+     * <ul>
+     * <li>Initializing the PPRCtrl for the current Form</li>
+     * </ul>
+     *
+     * @param facesContext the current {@link javax.faces.context.FacesContext}
+     * @param uiComponent  the currently rendered {@link PPRPanelGroup}
+     * @throws java.io.IOException if the underlying Layer throws an {@link java.io.IOException}
+     *                             it is passed through
+     */
+    public static void initPPR(FacesContext facesContext, PPRPanelGroup uiComponent) throws IOException
+    {
+        //if(isPartialRequest(facesContext)) {
+        //    return;
+        //}
+        final ExternalContext externalContext = facesContext.getExternalContext();
+        final Map requestMap = externalContext.getRequestMap();
+
+        // Do not render the JavaScript if answering to a PPR response
+
+        //Initialize the client side PPR engine
+        if (!requestMap.containsKey(PPR_INITIALIZED)) {
+            requestMap.put(PPR_INITIALIZED, Boolean.TRUE);
+
+            String encoding = "UTF-8"; // Hardcoded default
+            if (facesContext.getResponseWriter().getCharacterEncoding() != null) {
+                encoding = facesContext.getResponseWriter().getCharacterEncoding();
+            }
+
+            DojoConfig currentConfig = DojoUtils.getDjConfigInstance(facesContext);
+            currentConfig.setBindEncoding(encoding);
+
+            String javascriptLocation = (String) uiComponent.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
+            AddResource addResource = AddResourceFactory.getInstance(facesContext);
+            DojoUtils.addMainInclude(facesContext, uiComponent, javascriptLocation, currentConfig);
+            DojoUtils.addRequire(facesContext, uiComponent, "dojo.io.*");
+            DojoUtils.addRequire(facesContext, uiComponent, "dojo.event.*");
+            DojoUtils.addRequire(facesContext, uiComponent, "dojo.xml.*");
+            addResource.addJavaScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, PPRPanelGroup.class, PPR_JS_FILE);
+        }
+    }
+
+    /**
+     * Renders inline JavaScript registering an onLoad function for:
+     * <ul>
+     * <li>Initializing the PPRCtrl for the current Form</li>
+     * <li>Registering partialTriggers</li>
+     * <li>Registering partialTriggerPatterns</li>
+     * <li>Starting periodical updates</li>
+     * <li>Registering inline Loading messages</li>
+     * </ul>
+     *
+     * @param facesContext the current {@link FacesContext}
+     * @param pprGroup     the currently rendered {@link PPRPanelGroup}
+     * @throws IOException if the underlying Layer throws an {@link IOException}
+     *                     it is passed through
+     */
+    public static void encodeJavaScript(FacesContext facesContext, PPRPanelGroup pprGroup) throws IOException
+    {
+        StringBuffer script = new StringBuffer();
+
+        // all JS is put inside a function passed to dojoOnLoad
+        // this is necessary in order to be able to replace all button onClick
+        // handlers
+
+        script.append("dojo.addOnLoad( function(){ ");
+
+        String pprCtrlReference = initPPRFormControl(facesContext, pprGroup, script);
+
+        encodePeriodicalUpdates(facesContext, pprGroup, script, pprCtrlReference);
+
+        encodePartialTriggerPattern(facesContext, pprGroup, script, pprCtrlReference);
+
+        encodeSubFormFunction(facesContext, pprGroup, script, pprCtrlReference);
+
+        encodeDomUpdateConfig(facesContext, pprGroup, script, pprCtrlReference);
+
+        encodeInlineLoadMsg(facesContext, pprGroup, script, pprCtrlReference);
+
+        encodePartialTriggers(facesContext, pprGroup, script, pprCtrlReference);
+
+        // closing the dojo.addOnLoad call
+        script.append("});");
+
+        //Really render the script
+        renderInlineScript(facesContext, pprGroup, script.toString());
+    }
+
+    public static void encodeJavaScriptTriggerOnly(FacesContext context, UIComponent uiComponent, PPRPanelGroup pprGroup,
+                                        PartialTriggerParser.PartialTrigger trigger) throws IOException
+    {
+        StringBuffer script = new StringBuffer();
+        script.append("dojo.addOnLoad( function(){ ");
+        String pprCtrlReference = initPPRFormControl(context, pprGroup, script);
+        String clientId = pprGroup.getClientId(context);
+        encodePartialTrigger(context, script, pprCtrlReference, clientId, uiComponent, trigger);
+        // closing the dojo.addOnLoad call
+        script.append("});");
+
+        //Really render the script
+        renderInlineScript(context, pprGroup, script.toString());
+    }
+
+    private static void encodePartialTrigger(FacesContext facesContext,
+                                             StringBuffer script,
+                                             String pprCtrlReference,
+                                             String clientId,
+                                             UIComponent partialTriggerComponent,
+                                             PartialTriggerParser.PartialTrigger trigger)
+    {
+        String partialTriggerClientId;
+        String partialTriggerId = trigger.getPartialTriggerId();
+        if (partialTriggerComponent == null) {
+            partialTriggerComponent = facesContext.getViewRoot().findComponent(partialTriggerId);
+        }
+        if (partialTriggerComponent != null) {
+            partialTriggerClientId = partialTriggerComponent.getClientId(facesContext);
+            script.append(pprCtrlReference + "." + ADD_PARTIAL_TRIGGER_FUNCTION + "('" + partialTriggerClientId + "'," + encodeArray(trigger.getEventHooks()) + ",'" + clientId + "');");
+        }
+        else {
+            if (log.isDebugEnabled()) {
+                log.debug("PPRPanelGroupRenderer Component with id " + partialTriggerId + " not found!");
+            }
+        }
+    }
+
+    private static void encodePartialTriggers(FacesContext context, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference)
+    {
+        String clientId = pprGroup.getClientId(context);
+        UIComponent partialTriggerComponent;
+
+        List partialTriggerIds = pprGroup.parsePartialTriggers();
+        for (int i = 0; i < partialTriggerIds.size(); i++) {
+            PartialTriggerParser.PartialTrigger trigger = (PartialTriggerParser.PartialTrigger) partialTriggerIds
+                .get(i);
+            partialTriggerComponent = pprGroup.findComponent(trigger.getPartialTriggerId());
+            encodePartialTrigger(context, script, pprCtrlReference, clientId, partialTriggerComponent, trigger);
+        }
+    }
+
+    private static void encodePartialTriggerPattern(FacesContext context, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference)
+    {
+        String clientId = pprGroup.getClientId(context);
+
+        String partialTriggerPattern = pprGroup.getPartialTriggerPattern();
+
+        //handle partial trigger patterns
+        if (partialTriggerPattern != null && partialTriggerPattern.trim().length() > 0) {
+            script.append(pprCtrlReference + "." + ADD_PARTIAL_TRIGGER_PATTERN_FUNCTION + "('" + partialTriggerPattern + "','" + clientId + "');");
+        }
+
+    }
+
+    private static void encodeInlineLoadMsg(FacesContext context, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference)
+    {
+        String clientId = pprGroup.getClientId(context);
+        String inlineLoadingMessage = pprGroup.getInlineLoadingMessage();
+
+        //handle inline loading messages
+        if (inlineLoadingMessage != null && inlineLoadingMessage.trim().length() > 0) {
+            script.append(pprCtrlReference + "." + ADD_INLINE_LOADING_MESSAGE_FUNCTION + "('" + inlineLoadingMessage + "','" + clientId + "');");
+        }
+    }
+
+    private static void encodeSubFormFunction(FacesContext context, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference)
+    {
+        String clientId = pprGroup.getClientId(context);
+        SubForm subFormParent = findParentSubForm(pprGroup);
+        if (subFormParent != null) {
+            script.append(pprCtrlReference + "." + SET_SUBFORM_ID_FUNCTION + "('" + subFormParent.getId() + "','" + clientId + "');");
+        }
+    }
+
+    private static void encodeDomUpdateConfig(FacesContext context, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference)
+    {
+        String componentUpdateFunction = pprGroup.getComponentUpdateFunction();
+        if (!StringUtils.isEmpty(componentUpdateFunction)) {
+            script.append(pprCtrlReference + "." + SET_COMPONENT_UPDATE_FUNCTION+ "('" + componentUpdateFunction + "');");
+        }
+    }
+
+    private static void encodePeriodicalUpdates(FacesContext facesContext, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference)
+    {
+        String clientId = pprGroup.getClientId(facesContext);
+
+        //Handle periodical updates
+        if (pprGroup.getPeriodicalUpdate() != null) {
+            List partialTriggers = pprGroup.parsePeriodicalTriggers();
+            if (partialTriggers.size() == 0) {
+                Integer wait = null;
+                if (pprGroup.getExcludeFromStoppingPeriodicalUpdate() != null) {
+                    wait = pprGroup.getWaitBeforePeriodicalUpdate();
+                }
+                script.append(pprCtrlReference + ".startPeriodicalUpdate(" + pprGroup.getPeriodicalUpdate() + ",'" + clientId + "', " + wait + ");");
+            }
+            else {
+                String periodicalTriggerId;
+                String periodicalTriggerClientId;
+                UIComponent periodicalTriggerComponent;
+                for (int i = 0; i < partialTriggers.size(); i++) {
+                    PartialTriggerParser.PartialTrigger trigger = (PartialTriggerParser.PartialTrigger) partialTriggers
+                        .get(i);
+                    periodicalTriggerId = trigger.getPartialTriggerId();
+                    periodicalTriggerComponent = pprGroup.findComponent(periodicalTriggerId);
+                    if (periodicalTriggerComponent == null) {
+                        periodicalTriggerComponent = facesContext.getViewRoot().findComponent(periodicalTriggerId);
+                    }
+
+                    // Component found
+                    if (periodicalTriggerComponent != null) {
+                        periodicalTriggerClientId = periodicalTriggerComponent.getClientId(facesContext);
+                        script.append(pprCtrlReference + "." + ADD_PERIODICAL_TRIGGER_FUNCTION +
+                            "('" + periodicalTriggerClientId + "'," +
+                            encodeArray(trigger.getEventHooks()) + ",'" + clientId + "', " +
+                            pprGroup.getPeriodicalUpdate() + ");");
+
+                        // Component missing
+                    }
+                    else {
+                        if (log.isDebugEnabled()) {
+                            log.debug("PPRPanelGroupRenderer Component with id " + periodicalTriggerId + " not found!");
+                        }
+                    }
+                }
+            }
+
+            String idRegex = pprGroup.getExcludeFromStoppingPeriodicalUpdate();
+
+            if (idRegex != null) {
+                script.append(pprCtrlReference + ".excludeFromStoppingPeriodicalUpdate('" + idRegex + "');");
+            }
+        }
+    }
+
+    private static String initPPRFormControl(FacesContext facesContext, PPRPanelGroup pprGroup, StringBuffer script)
+    {
+        FormInfo fi = RendererUtils.findNestingForm(pprGroup, facesContext);
+        if (fi == null) {
+            throw new FacesException("PPRPanelGroup must be embedded in a form.");
+        }
+        final String formName = fi.getFormName();
+        Map requestMap = facesContext.getExternalContext().getRequestMap();
+
+        String pprCtrlReference = "dojo.byId('" + formName + "').myFacesPPRCtrl";
+
+        //Each form containing PPRPanelGroups has its own PPRCtrl
+
+        // the following complicated stuff should deal with the following use-cases:
+        // 1) normal create ppr on non-ppr-response
+        // 2) create ppr on ppr-response
+        // 3) add triggers to ppr on ppr-response (e.g to commands within uidata)
+        //
+        // get state of the ppr component ...
+        boolean pprInited = pprGroup.getInitializationSent();
+        if (!PPRSupport.isPartialRequest(facesContext))
+        {
+            // ... but override with current request state if we are not within an
+            // ppr request.
+            pprInited = Boolean.TRUE.equals(requestMap.get(PPR_INITIALIZED + "." + formName));
+        }
+
+        if (!pprInited) {
+            pprGroup.setInitializationSent(true);
+            requestMap.put(PPR_INITIALIZED + "." + formName, Boolean.TRUE);
+
+            script.append(pprCtrlReference + "=" + MY_FACES_PPR_INIT_CODE + "('" + formName + "'," + pprGroup.getShowDebugMessages().booleanValue() + "," + pprGroup.getStateUpdate().booleanValue() + ");\n");
+
+            if (pprGroup.getPeriodicalUpdate() != null) {
+                script.append(pprCtrlReference + ".registerOnSubmitInterceptor();");
+            }
+        }
+        return pprCtrlReference;
+    }
+
+    public static SubForm findParentSubForm(UIComponent base)
+    {
+        if (base == null) {
+            return null;
+        }
+        if (base instanceof SubForm) {
+            return (SubForm) base;
+        }
+        return findParentSubForm(base.getParent());
+    }
+
+    private static String encodeArray(List eventHooks)
+    {
+        if (eventHooks == null || eventHooks.size() == 0) {
+            return "null";
+        }
+        else {
+            StringBuffer buf = new StringBuffer();
+            buf.append("[");
+
+            for (int i = 0; i < eventHooks.size(); i++) {
+                if (i > 0) {
+                    buf.append(",");
+                }
+                String eventHook = (String) eventHooks.get(i);
+                buf.append("'");
+                buf.append(eventHook);
+                buf.append("'");
+            }
+            buf.append("]");
+
+            return buf.toString();
+        }
+    }
+
+    /**
+     * Helper to write an inline javascript at the exact resource location
+     * of the call.
+     *
+     * @param facesContext The current faces-context.
+     * @param component    The component for which the script is written.
+     * @param script       The script to be written.
+     * @throws IOException A forwarded exception from the underlying renderer.
+     */
+    private static void renderInlineScript(FacesContext facesContext, UIComponent component, String script) throws IOException
+    {
+        ResponseWriter writer = facesContext.getResponseWriter();
+        writer.startElement(HTML.SCRIPT_ELEM, component);
+        writer.writeAttribute(HTML.TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
+        writer.write(script);
+        writer.endElement(HTML.SCRIPT_ELEM);
+    }
+
+    /**
+     * get all components by given id-string-list ("id1,id2,id3") and appropriate type
+     *
+     * @param context
+     * @param comp
+     * @param idList
+     * @param desiredType
+     * @return
+     */
+    public static List getComponentsByCommaSeparatedIdList(FacesContext context, UIComponent comp, String idList, Class desiredType)
+    {
+        List retval = new ArrayList();
+        UIComponent currentComponent = null;
+        String[] ids = StringUtils.split(idList, ',');
+        for (int i = 0; i < ids.length; i++) {
+            String id = StringUtils.trim(ids[i]);
+            currentComponent = comp.findComponent(id);
+            if (nullSafeCheckComponentType(desiredType, currentComponent)) {
+                retval.add(currentComponent);
+            }
+            else {
+                currentComponent = context.getViewRoot().findComponent(id);
+                if (nullSafeCheckComponentType(desiredType, currentComponent)) {
+                    retval.add(currentComponent);
+                }
+            }
+        }
+        return retval;
+    }
+
+    private static boolean nullSafeCheckComponentType(Class desiredType, UIComponent currentComponent)
+    {
+        return currentComponent != null && (desiredType == null || desiredType.isAssignableFrom(currentComponent.getClass()));
+    }
+}

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRViewRootWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PartialTriggerParser.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PartialTriggerParser.java?rev=673836&r1=673835&r2=673836&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PartialTriggerParser.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PartialTriggerParser.java Thu Jul  3 15:03:29 2008
@@ -1,115 +1,115 @@
-package org.apache.myfaces.custom.ppr;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author Martin Marinschek
- */
-public class PartialTriggerParser
-{
-
-    public List parse(String partialTriggerString)
-    {
-
-        int lastTokenEnd = 0;
-        boolean subLevelMode = false;
-
-        List partialTriggers = new ArrayList();
-        PartialTrigger currentTrigger = null;
-
-        for (int i = 0, length = partialTriggerString.length(); i <= length; i++) {
-            boolean newTokenMode = false;
-            boolean endTopLevelMode = false;
-            boolean endSubLevelMode = false;
-
-            if (!(i == partialTriggerString.length())) {
-                char c = partialTriggerString.charAt(i);
-
-                if (c == ',' || c == ';' || c == ' ') {
-                    newTokenMode = true;
-                }
-                else if (c == '(') {
-                    newTokenMode = true;
-                    subLevelMode = true;
-                    endTopLevelMode = true;
-                }
-                else if (c == ')') {
-                    newTokenMode = true;
-                    subLevelMode = false;
-                    endSubLevelMode = true;
-                }
-            }
-            else {
-                newTokenMode = true;
-            }
-
-            if (newTokenMode) {
-                if (((!subLevelMode && !endSubLevelMode) || endTopLevelMode) && i > lastTokenEnd) {
-                    currentTrigger = new PartialTrigger();
-                    partialTriggers.add(currentTrigger);
-                    currentTrigger.setPartialTriggerId(partialTriggerString.substring(lastTokenEnd, i));
-                }
-                else if ((subLevelMode || endSubLevelMode) && i > lastTokenEnd) {
-                    currentTrigger.addEventHook(partialTriggerString.substring(lastTokenEnd, i));
-                }
-
-                lastTokenEnd = i + 1;
-            }
-        }
-
-        return partialTriggers;
-    }
-
-
-    public static class PartialTrigger
-    {
-        private String partialTriggerId;
-        private List eventHooks;
-
-        public void addEventHook(String eventHook)
-        {
-            if (eventHooks == null) {
-                eventHooks = new ArrayList();
-            }
-            eventHooks.add(eventHook);
-        }
-
-        public String getPartialTriggerId()
-        {
-            return partialTriggerId;
-        }
-
-        public void setPartialTriggerId(String partialTriggerId)
-        {
-            this.partialTriggerId = partialTriggerId;
-        }
-
-        public List getEventHooks()
-        {
-            if (eventHooks == null) {
-                return Collections.EMPTY_LIST;
-            }
-
-            return eventHooks;
-        }
-    }
-
-    public static void main(String[] args)
-    {
-        PartialTriggerParser parser = new PartialTriggerParser();
-        List li = parser.parse(/*", ; ,, test1id   (onkeyup,onkeydown,,,test2id test3id;test4id"*/"testid(onchange)");
-
-        for (int i = 0; i < li.size(); i++) {
-            PartialTrigger partialTrigger = (PartialTrigger) li.get(i);
-            System.out.println("partialTrigger.partialTriggerId = " + partialTrigger.getPartialTriggerId());
-
-            for (int j = 0; j < partialTrigger.getEventHooks().size(); j++) {
-                String eventHook = (String) partialTrigger.getEventHooks().get(j);
-                System.out.println("eventHook = " + eventHook);
-            }
-        }
-    }
-
-}
+package org.apache.myfaces.custom.ppr;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Martin Marinschek
+ */
+public class PartialTriggerParser
+{
+
+    public List parse(String partialTriggerString)
+    {
+
+        int lastTokenEnd = 0;
+        boolean subLevelMode = false;
+
+        List partialTriggers = new ArrayList();
+        PartialTrigger currentTrigger = null;
+
+        for (int i = 0, length = partialTriggerString.length(); i <= length; i++) {
+            boolean newTokenMode = false;
+            boolean endTopLevelMode = false;
+            boolean endSubLevelMode = false;
+
+            if (!(i == partialTriggerString.length())) {
+                char c = partialTriggerString.charAt(i);
+
+                if (c == ',' || c == ';' || c == ' ') {
+                    newTokenMode = true;
+                }
+                else if (c == '(') {
+                    newTokenMode = true;
+                    subLevelMode = true;
+                    endTopLevelMode = true;
+                }
+                else if (c == ')') {
+                    newTokenMode = true;
+                    subLevelMode = false;
+                    endSubLevelMode = true;
+                }
+            }
+            else {
+                newTokenMode = true;
+            }
+
+            if (newTokenMode) {
+                if (((!subLevelMode && !endSubLevelMode) || endTopLevelMode) && i > lastTokenEnd) {
+                    currentTrigger = new PartialTrigger();
+                    partialTriggers.add(currentTrigger);
+                    currentTrigger.setPartialTriggerId(partialTriggerString.substring(lastTokenEnd, i));
+                }
+                else if ((subLevelMode || endSubLevelMode) && i > lastTokenEnd) {
+                    currentTrigger.addEventHook(partialTriggerString.substring(lastTokenEnd, i));
+                }
+
+                lastTokenEnd = i + 1;
+            }
+        }
+
+        return partialTriggers;
+    }
+
+
+    public static class PartialTrigger
+    {
+        private String partialTriggerId;
+        private List eventHooks;
+
+        public void addEventHook(String eventHook)
+        {
+            if (eventHooks == null) {
+                eventHooks = new ArrayList();
+            }
+            eventHooks.add(eventHook);
+        }
+
+        public String getPartialTriggerId()
+        {
+            return partialTriggerId;
+        }
+
+        public void setPartialTriggerId(String partialTriggerId)
+        {
+            this.partialTriggerId = partialTriggerId;
+        }
+
+        public List getEventHooks()
+        {
+            if (eventHooks == null) {
+                return Collections.EMPTY_LIST;
+            }
+
+            return eventHooks;
+        }
+    }
+
+    public static void main(String[] args)
+    {
+        PartialTriggerParser parser = new PartialTriggerParser();
+        List li = parser.parse(/*", ; ,, test1id   (onkeyup,onkeydown,,,test2id test3id;test4id"*/"testid(onchange)");
+
+        for (int i = 0; i < li.size(); i++) {
+            PartialTrigger partialTrigger = (PartialTrigger) li.get(i);
+            System.out.println("partialTrigger.partialTriggerId = " + partialTrigger.getPartialTriggerId());
+
+            for (int j = 0; j < partialTrigger.getEventHooks().size(); j++) {
+                String eventHook = (String) partialTrigger.getEventHooks().get(j);
+                System.out.println("eventHook = " + eventHook);
+            }
+        }
+    }
+
+}

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PartialTriggerParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/table/FilterTableRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/table/FilterTableRenderer.java?rev=673836&r1=673835&r2=673836&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/table/FilterTableRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/table/FilterTableRenderer.java Thu Jul  3 15:03:29 2008
@@ -1,226 +1,226 @@
-/*
- * 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.table;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.custom.dojo.DojoUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
-import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
-
-import javax.faces.component.UIColumn;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIData;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.util.List;
-import java.util.Iterator;
-
-/**
- * 
- * @JSFRenderer
- *   renderKitId = "HTML_BASIC" 
- *   family = "javax.faces.Data"
- *   type = "org.apache.myfaces.FilterTable"
- * 
- * @author Thomas Spiegl
- */
-public class FilterTableRenderer extends HtmlRenderer {
-
-    public static final String RENDERER_TYPE = "org.apache.myfaces.FilterTable";
-
-    private Log log = LogFactory.getLog(FilterTableRenderer.class);
-
-    public boolean getRendersChildren() {
-        return true;
-    }
-
-    public void decode(FacesContext context, UIComponent component) {
-        super.decode(context, component);
-    }
-
-    public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
-        RendererUtils.checkParamValidity(context, component, FilterTable.class);
-        ResponseWriter writer = context.getResponseWriter();
-        
-        FilterTable table = (FilterTable) component;
-
-        String javascriptLocation = (String) component.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
-        DojoUtils.addMainInclude(context, component, javascriptLocation, DojoUtils.getDjConfigInstance(context));
-        DojoUtils.addRequire(context, component, "dojo.widget.FilteringTable");
-
-        writer.write("<table dojoType=\"filteringTable\" id=\"" + component.getClientId(context) +  "\" ");
-        if (table.getStyleClass() != null) {
-             writer.write("class=\"" + table.getStyleClass() + "\" " );
-        }
-        if (table.getHeadClass() != null) {
-            writer.write("headClass=\"" + table.getHeadClass() + "\" " );
-        } else {
-            writer.write("headClass=\"fixedHeader\" " );
-        }
-        if (table.getTbodyClass() != null) {
-            writer.write("tbodyClass=\"" + table.getTbodyClass() + "\" ");
-        } else {
-            writer.write("tbodyClass=\"scrollContent\" ");
-        }
-        if (table.getMultiple() != null) {
-            String value = table.getMultiple().booleanValue() ? "true" : "false";
-            writer.write("multiple=\"" + value + "\" ");
-        } else {
-            writer.write("multiple=\"true\" ");
-        }
-        if (table.getAlternateRows() != null) {
-            String value = table.getAlternateRows().booleanValue() ? "true" : "false";
-            writer.write("alternateRows=\""+ value + "\" ");
-        } else {
-            writer.write("alternateRows=\"true\" ");
-        }
-        if (table.getMaxSortable() != null) {
-            writer.write("maxSortable=\"" + table.getMaxSortable() + "\" ");
-        } else {
-            writer.write("maxSortable=\"1\" ");
-        }
-        if (table.getCellpadding() != null) {
-            writer.write("cellpadding=\"" + table.getCellpadding() + "\" ");
-        } else {
-            writer.write("cellpadding=\"0\" ");
-        }
-        if (table.getCellspacing() != null) {
-            writer.write("cellspacing=\"" + table.getCellspacing() + "\" ");
-        } else {
-            writer.write("cellspacing=\"0\" ");
-        }
-        if (table.getBorder() != null) {
-            writer.write("border=\"" + table.getBorder() + "\"");
-        } else {
-            writer.write("border=\"0\"");
-        }
-        writer.write(">");
-        encodeHeader(context, component);
-    }
-
-    public void encodeHeader(FacesContext context, UIComponent component) throws IOException {
-        ResponseWriter writer = context.getResponseWriter();
-        writer.startElement(HTML.THEAD_ELEM, component);
-        writer.startElement(HTML.TR_ELEM, component);
-        for (Iterator it = component.getChildren().iterator(); it.hasNext(); ) {
-            UIComponent child = (UIComponent) it.next();
-            if (child.isRendered() && child instanceof SortableColumn) {
-                SortableColumn col = (SortableColumn) child;
-                writer.startElement(HTML.TH_ELEM, col);
-                if (col.getField() != null) {
-                    writer.writeAttribute("field", col.getField(), null);
-                }
-                if (col.getDataType() != null) {
-                    writer.writeAttribute("dataType", col.getDataType(), null);
-                } else {
-                    writer.writeAttribute("dataType", "String", null);
-                }
-                if (col.getSort() != null) {
-                     writer.writeAttribute("sort", col.getSort(), null);
-                 }
-                 if (col.getAlign() != null) {
-                     writer.writeAttribute("align", col.getAlign(), null);
-                 }
-                 if (col.getValign() != null) {
-                     writer.writeAttribute("valign", col.getValign(), null);
-                 }
-                 if (col.getFormat() != null) {
-                     writer.writeAttribute("format", col.getFormat(), null);
-                 }
-                Boolean escape = col.getEscape();
-                if (escape == null || escape.booleanValue())  {
-                    writer.writeText(col.getText(), JSFAttr.VALUE_ATTR);
-                } else {
-                    writer.writeText(col.getText(), null);
-                }
-                writer.endElement(HTML.TH_ELEM);
-            }
-        }
-        writer.endElement(HTML.TR_ELEM);
-        writer.endElement(HTML.THEAD_ELEM);
-    }
-
-    public void encodeChildren(FacesContext facesContext, UIComponent component) throws IOException
-    {
-        HtmlRendererUtils.writePrettyLineSeparator(facesContext);
-        ResponseWriter writer = facesContext.getResponseWriter();
-
-        writer.startElement(HTML.TBODY_ELEM, component);
-        encodeInnerHtml(facesContext, component);
-        writer.endElement(HTML.TBODY_ELEM);
-    }
-
-    protected void encodeInnerHtml(FacesContext facesContext, UIComponent component)throws IOException{
-        UIData uiData = (UIData) component;
-        ResponseWriter writer = facesContext.getResponseWriter();
-
-        int first = uiData.getFirst();
-        int rows = uiData.getRows();
-        int last;
-        if (rows <= 0) {
-            last = uiData.getRowCount();
-        }
-        else {
-            last = first + rows;
-            if (last > uiData.getRowCount()) {
-                last=uiData.getRowCount();
-            }
-        }
-        for(int idx = first; idx < last; idx++) {
-            // bail if any row does not exist
-            uiData.setRowIndex(idx);
-            if(!uiData.isRowAvailable()) {
-                log.error("Row is not available. Rowindex = " + idx);
-                break;
-            }
-
-            writer.startElement(HTML.TR_ELEM, component);
-            writer.writeAttribute("value", Integer.toString(idx + 1), null);
-            List children = getChildren(component);
-            for (int j = 0, size = getChildCount(component); j < size; j++) {
-                UIComponent child = (UIComponent) children.get(j);
-                if (child.isRendered()) {
-                    boolean columnRendering = child instanceof UIColumn;
-                    if (columnRendering)
-                        encodeColumnChild(facesContext, writer, uiData, child);
-                }
-            }
-            writer.endElement(HTML.TR_ELEM);
-        }
-    }
-
-    protected void encodeColumnChild(FacesContext facesContext,  ResponseWriter writer, UIData uiData,
-                                     UIComponent component) throws IOException {
-        writer.startElement(HTML.TD_ELEM, uiData);
-        RendererUtils.renderChild(facesContext, component);
-        writer.endElement(HTML.TD_ELEM);
-    }
-
-    public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
-        RendererUtils.checkParamValidity(context, component, UIData.class);
-        ResponseWriter writer = context.getResponseWriter();
-        writer.endElement(HTML.TABLE_ELEM);
-        HtmlRendererUtils.writePrettyLineSeparator(context);
-    }
-}
+/*
+ * 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.table;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.custom.dojo.DojoUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIData;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.util.List;
+import java.util.Iterator;
+
+/**
+ * 
+ * @JSFRenderer
+ *   renderKitId = "HTML_BASIC" 
+ *   family = "javax.faces.Data"
+ *   type = "org.apache.myfaces.FilterTable"
+ * 
+ * @author Thomas Spiegl
+ */
+public class FilterTableRenderer extends HtmlRenderer {
+
+    public static final String RENDERER_TYPE = "org.apache.myfaces.FilterTable";
+
+    private Log log = LogFactory.getLog(FilterTableRenderer.class);
+
+    public boolean getRendersChildren() {
+        return true;
+    }
+
+    public void decode(FacesContext context, UIComponent component) {
+        super.decode(context, component);
+    }
+
+    public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
+        RendererUtils.checkParamValidity(context, component, FilterTable.class);
+        ResponseWriter writer = context.getResponseWriter();
+        
+        FilterTable table = (FilterTable) component;
+
+        String javascriptLocation = (String) component.getAttributes().get(JSFAttr.JAVASCRIPT_LOCATION);
+        DojoUtils.addMainInclude(context, component, javascriptLocation, DojoUtils.getDjConfigInstance(context));
+        DojoUtils.addRequire(context, component, "dojo.widget.FilteringTable");
+
+        writer.write("<table dojoType=\"filteringTable\" id=\"" + component.getClientId(context) +  "\" ");
+        if (table.getStyleClass() != null) {
+             writer.write("class=\"" + table.getStyleClass() + "\" " );
+        }
+        if (table.getHeadClass() != null) {
+            writer.write("headClass=\"" + table.getHeadClass() + "\" " );
+        } else {
+            writer.write("headClass=\"fixedHeader\" " );
+        }
+        if (table.getTbodyClass() != null) {
+            writer.write("tbodyClass=\"" + table.getTbodyClass() + "\" ");
+        } else {
+            writer.write("tbodyClass=\"scrollContent\" ");
+        }
+        if (table.getMultiple() != null) {
+            String value = table.getMultiple().booleanValue() ? "true" : "false";
+            writer.write("multiple=\"" + value + "\" ");
+        } else {
+            writer.write("multiple=\"true\" ");
+        }
+        if (table.getAlternateRows() != null) {
+            String value = table.getAlternateRows().booleanValue() ? "true" : "false";
+            writer.write("alternateRows=\""+ value + "\" ");
+        } else {
+            writer.write("alternateRows=\"true\" ");
+        }
+        if (table.getMaxSortable() != null) {
+            writer.write("maxSortable=\"" + table.getMaxSortable() + "\" ");
+        } else {
+            writer.write("maxSortable=\"1\" ");
+        }
+        if (table.getCellpadding() != null) {
+            writer.write("cellpadding=\"" + table.getCellpadding() + "\" ");
+        } else {
+            writer.write("cellpadding=\"0\" ");
+        }
+        if (table.getCellspacing() != null) {
+            writer.write("cellspacing=\"" + table.getCellspacing() + "\" ");
+        } else {
+            writer.write("cellspacing=\"0\" ");
+        }
+        if (table.getBorder() != null) {
+            writer.write("border=\"" + table.getBorder() + "\"");
+        } else {
+            writer.write("border=\"0\"");
+        }
+        writer.write(">");
+        encodeHeader(context, component);
+    }
+
+    public void encodeHeader(FacesContext context, UIComponent component) throws IOException {
+        ResponseWriter writer = context.getResponseWriter();
+        writer.startElement(HTML.THEAD_ELEM, component);
+        writer.startElement(HTML.TR_ELEM, component);
+        for (Iterator it = component.getChildren().iterator(); it.hasNext(); ) {
+            UIComponent child = (UIComponent) it.next();
+            if (child.isRendered() && child instanceof SortableColumn) {
+                SortableColumn col = (SortableColumn) child;
+                writer.startElement(HTML.TH_ELEM, col);
+                if (col.getField() != null) {
+                    writer.writeAttribute("field", col.getField(), null);
+                }
+                if (col.getDataType() != null) {
+                    writer.writeAttribute("dataType", col.getDataType(), null);
+                } else {
+                    writer.writeAttribute("dataType", "String", null);
+                }
+                if (col.getSort() != null) {
+                     writer.writeAttribute("sort", col.getSort(), null);
+                 }
+                 if (col.getAlign() != null) {
+                     writer.writeAttribute("align", col.getAlign(), null);
+                 }
+                 if (col.getValign() != null) {
+                     writer.writeAttribute("valign", col.getValign(), null);
+                 }
+                 if (col.getFormat() != null) {
+                     writer.writeAttribute("format", col.getFormat(), null);
+                 }
+                Boolean escape = col.getEscape();
+                if (escape == null || escape.booleanValue())  {
+                    writer.writeText(col.getText(), JSFAttr.VALUE_ATTR);
+                } else {
+                    writer.writeText(col.getText(), null);
+                }
+                writer.endElement(HTML.TH_ELEM);
+            }
+        }
+        writer.endElement(HTML.TR_ELEM);
+        writer.endElement(HTML.THEAD_ELEM);
+    }
+
+    public void encodeChildren(FacesContext facesContext, UIComponent component) throws IOException
+    {
+        HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+        ResponseWriter writer = facesContext.getResponseWriter();
+
+        writer.startElement(HTML.TBODY_ELEM, component);
+        encodeInnerHtml(facesContext, component);
+        writer.endElement(HTML.TBODY_ELEM);
+    }
+
+    protected void encodeInnerHtml(FacesContext facesContext, UIComponent component)throws IOException{
+        UIData uiData = (UIData) component;
+        ResponseWriter writer = facesContext.getResponseWriter();
+
+        int first = uiData.getFirst();
+        int rows = uiData.getRows();
+        int last;
+        if (rows <= 0) {
+            last = uiData.getRowCount();
+        }
+        else {
+            last = first + rows;
+            if (last > uiData.getRowCount()) {
+                last=uiData.getRowCount();
+            }
+        }
+        for(int idx = first; idx < last; idx++) {
+            // bail if any row does not exist
+            uiData.setRowIndex(idx);
+            if(!uiData.isRowAvailable()) {
+                log.error("Row is not available. Rowindex = " + idx);
+                break;
+            }
+
+            writer.startElement(HTML.TR_ELEM, component);
+            writer.writeAttribute("value", Integer.toString(idx + 1), null);
+            List children = getChildren(component);
+            for (int j = 0, size = getChildCount(component); j < size; j++) {
+                UIComponent child = (UIComponent) children.get(j);
+                if (child.isRendered()) {
+                    boolean columnRendering = child instanceof UIColumn;
+                    if (columnRendering)
+                        encodeColumnChild(facesContext, writer, uiData, child);
+                }
+            }
+            writer.endElement(HTML.TR_ELEM);
+        }
+    }
+
+    protected void encodeColumnChild(FacesContext facesContext,  ResponseWriter writer, UIData uiData,
+                                     UIComponent component) throws IOException {
+        writer.startElement(HTML.TD_ELEM, uiData);
+        RendererUtils.renderChild(facesContext, component);
+        writer.endElement(HTML.TD_ELEM);
+    }
+
+    public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
+        RendererUtils.checkParamValidity(context, component, UIData.class);
+        ResponseWriter writer = context.getResponseWriter();
+        writer.endElement(HTML.TABLE_ELEM);
+        HtmlRendererUtils.writePrettyLineSeparator(context);
+    }
+}

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/table/FilterTableRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/toggle/ToggleGroupRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native