You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2016/08/21 12:37:11 UTC

svn commit: r1757055 - in /myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago: ajax/AjaxUtils.java util/AjaxUtils.java

Author: weber
Date: Sun Aug 21 12:37:11 2016
New Revision: 1757055

URL: http://svn.apache.org/viewvc?rev=1757055&view=rev
Log:
TOBAGO-1524: Use standard AJAX mechanism: Revert remove of AjaxUtils

Added:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/AjaxUtils.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/AjaxUtils.java

Added: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/AjaxUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/AjaxUtils.java?rev=1757055&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/AjaxUtils.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/AjaxUtils.java Sun Aug 21 12:37:11 2016
@@ -0,0 +1,88 @@
+/*
+ * 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.tobago.ajax;
+
+
+import org.apache.myfaces.tobago.internal.ajax.AjaxInternalUtils;
+import org.apache.myfaces.tobago.util.ComponentUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+/**
+ * @deprecated use org.apache.myfaces.tobago.util.AjaxUtils
+ */
+@Deprecated
+public final class AjaxUtils {
+
+  private static final Logger LOG = LoggerFactory.getLogger(AjaxUtils.class);
+
+  private AjaxUtils() {
+  }
+
+  public static boolean isAjaxRequest(final FacesContext facesContext) {
+    return org.apache.myfaces.tobago.util.AjaxUtils.isAjaxRequest(facesContext);
+  }
+
+  public static boolean isAjaxRequest(final ServletRequest request) {
+    return org.apache.myfaces.tobago.util.AjaxUtils.isAjaxRequest(request);
+  }
+
+  public static void removeAjaxComponent(final FacesContext facesContext, final String clientId) {
+    org.apache.myfaces.tobago.util.AjaxUtils.removeRenderIds(facesContext, clientId);
+  }
+
+  public static void addAjaxComponent(final FacesContext facesContext, final String clientId) {
+    org.apache.myfaces.tobago.util.AjaxUtils.addRenderIds(facesContext, clientId);
+  }
+
+  public static void addAjaxComponent(final FacesContext facesContext, final UIComponent component) {
+    org.apache.myfaces.tobago.util.AjaxUtils.addRenderIds(facesContext, component.getClientId(facesContext));
+  }
+
+  public static Set<String> getRequestPartialIds(final FacesContext facesContext) {
+    return org.apache.myfaces.tobago.util.AjaxUtils.getRenderIds(facesContext);
+  }
+
+  public static boolean addUIMessagesToRenderedPartially(final FacesContext facesContext) {
+    final String message = "org.apache.myfaces.tobago.ajax.AjaxUtils.addUIMessagesToRenderedPartially";
+    throw new UnsupportedOperationException(message);
+  }
+
+  public static boolean redirect(final FacesContext facesContext, final String url) throws IOException {
+    return AjaxInternalUtils.redirect(facesContext, url);
+  }
+
+  public static void redirect(final HttpServletResponse response, final String url) throws IOException {
+    AjaxInternalUtils.redirect(response, url);
+  }
+}

Added: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/AjaxUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/AjaxUtils.java?rev=1757055&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/AjaxUtils.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/util/AjaxUtils.java Sun Aug 21 12:37:11 2016
@@ -0,0 +1,77 @@
+/*
+ * 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.tobago.util;
+
+import javax.faces.application.Application;
+import javax.faces.application.NavigationHandler;
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+public class AjaxUtils {
+
+  public static boolean isAjaxRequest(final FacesContext facesContext) {
+    return facesContext.getPartialViewContext().isAjaxRequest();
+  }
+
+  public static boolean isAjaxRequest(final ServletRequest request) {
+    String requestType = null;
+    if (request instanceof HttpServletRequest) {
+      final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
+      requestType = httpServletRequest.getHeader("Faces-Request");
+    }
+    return "partial/ajax".equalsIgnoreCase(requestType)
+        || "true".equalsIgnoreCase(request.getParameter("javax.faces.partial.ajax"));
+  }
+
+  public static void addRenderIds(final String... renderIds) {
+    addRenderIds(FacesContext.getCurrentInstance(), renderIds);
+  }
+
+  public static void addRenderIds(final FacesContext facesContext, final String... renderIds) {
+    Collections.addAll(facesContext.getPartialViewContext().getRenderIds(), renderIds);
+  }
+
+  public static void removeRenderIds(final String... renderIds) {
+    removeRenderIds(FacesContext.getCurrentInstance(), renderIds);
+  }
+
+  public static void removeRenderIds(final FacesContext facesContext, final String... renderIds) {
+    final Collection<String> collection = facesContext.getPartialViewContext().getRenderIds();
+    for (String renderId : renderIds) {
+      collection.remove(renderId);
+    }
+  }
+
+  public static Set<String> getRenderIds(final FacesContext facesContext) {
+    return new HashSet<String>(facesContext.getPartialViewContext().getRenderIds());
+  }
+
+  public static void navigate(FacesContext facesContext, Object outcome) {
+    final Application application = facesContext.getApplication();
+    NavigationHandler navigationHandler = application.getNavigationHandler();
+    navigationHandler.handleNavigation(facesContext, null, outcome.toString());
+    facesContext.renderResponse();
+  }
+}