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 2008/11/27 11:53:02 UTC
svn commit: r721155 - in /myfaces/core/branches/2_0_0/impl/src:
main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
test/java/org/apache/myfaces/context/TestIsAjaxRequest.java
Author: werpu
Date: Thu Nov 27 02:53:02 2008
New Revision: 721155
URL: http://svn.apache.org/viewvc?rev=721155&view=rev
Log:
https://issues.apache.org/jira/browse/MYFACES-1992
Added:
myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/TestIsAjaxRequest.java (with props)
Modified:
myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
Modified: myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java?rev=721155&r1=721154&r2=721155&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java (original)
+++ myfaces/core/branches/2_0_0/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java Thu Nov 27 02:53:02 2008
@@ -65,6 +65,7 @@
*/
public class FacesContextImpl extends FacesContext {
+ public static final String METHOD_ISAJAXREQUEST = "isAjaxRequest";
private static final String METHOD_ADDMESSAGE = "addMessage";
private static final String METHOD_ENABLERESPONSEWRITING = "enableResponseWriting";
private static final String METHOD_GETAPPLICATION = "getApplication";
@@ -121,6 +122,9 @@
private List<String> _executePhaseClientIds = null;
private Boolean _renderAll = null;
+ /*helper to speed things up on the isAjaxRequest method*/
+ private Boolean _ajaxRequest = null;
+
// ~ Constructors -------------------------------------------------------------------------------
public FacesContextImpl(final ServletContext servletContext, final ServletRequest servletRequest,
final ServletResponse servletResponse) {
@@ -344,7 +348,7 @@
* (probably to trigger some clearance methods
* on possible added entries before nullifying everything)
*/
- if(_attributes != null) {
+ if (_attributes != null) {
_attributes.clear();
_attributes = null;
}
@@ -355,7 +359,7 @@
_responseStream = null;
_responseWriter = null;
_viewRoot = null;
-
+
_released = true;
FacesContext.setCurrentInstance(null);
@@ -480,7 +484,7 @@
public List<String> getExecutePhaseClientIds() {
assertNotReleased(METHOD_GETEXECUTEPHASECLIENTIDS);
- if(_executePhaseClientIds != null) {
+ if (_executePhaseClientIds != null) {
return _executePhaseClientIds;
}
@@ -593,11 +597,37 @@
* can push in a request wrapper!
*
*/
- /* @Override
+ @Override
public boolean isAjaxRequest() {
- Map requestMap = getExternalContext().getRequestMap();
- return requestMap.containsKey(AJAX_REQ_KEY);
- }*/
+
+ assertNotReleased(METHOD_ISAJAXREQUEST);
+
+ /*
+ * A speed shortcut here is feasable
+ * but it has to be discussed we have those
+ * in several parts of the facesContext and even most of them implicetly
+ * enforced by the spec itself. Hence i set it here.
+ *
+ *
+ * The problem is that request parameter maps can be
+ * delivered by RequestWrappers hence, you cannot rely
+ * on the map being entirely immutable.
+ * But leaving it out probably is also a no option since
+ * this method probably will be called by every component
+ * renderer and a O(log(n)) lookup is not a serious performance impact
+ * but serious enough!
+ *
+ * This has to be cleared up with the spec people!
+ * This should not cause a problem under normal circumstances
+ * however!
+ */
+ if (_ajaxRequest == null) {
+ Map requestParamMap = getExternalContext().getRequestParameterMap();
+ _ajaxRequest = requestParamMap.containsKey(AJAX_REQ_KEY);
+ }
+ return _ajaxRequest;
+ }
+
/**
* @return is render none return true if {@link #PARTIAL_EXECUTE_PARAM_NAME} is set in the current request
* map!
Added: myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/TestIsAjaxRequest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/TestIsAjaxRequest.java?rev=721155&view=auto
==============================================================================
--- myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/TestIsAjaxRequest.java (added)
+++ myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/TestIsAjaxRequest.java Thu Nov 27 02:53:02 2008
@@ -0,0 +1,65 @@
+/*
+ * Licensed 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.
+ * under the License.
+ */
+
+package org.apache.myfaces.context;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.faces.context.FacesContext;
+import org.apache.myfaces.context.servlet.FacesContextImpl;
+import org.apache.shale.test.base.AbstractJsfTestCase;
+
+/**
+ * Tests the facesContext isAjaxRequest
+ * with all its sideconditions
+ *
+ * @author Werner Punz(latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class TestIsAjaxRequest extends AbstractJsfTestCase {
+ Map requestParameterMap = null;
+ FacesContext context = null;
+
+ public TestIsAjaxRequest() {
+ super("TestIsAjaxRequest");
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ requestParameterMap = new HashMap<String, String>();
+ ContextTestRequestWrapper wrapper = new ContextTestRequestWrapper(request, requestParameterMap);
+ context = new FacesContextImpl(servletContext, wrapper, response);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ requestParameterMap.clear();
+ }
+
+ public void testNoEntry() {
+
+ assertFalse("no ajax request found", context.isAjaxRequest());
+ }
+
+ public void testEntry() {
+ requestParameterMap.put("javax.faces.partial.ajax", "yess");
+
+ assertTrue("no ajax request found", context.isAjaxRequest());
+ }
+
+
+
+}
Propchange: myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/TestIsAjaxRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: myfaces/core/branches/2_0_0/impl/src/test/java/org/apache/myfaces/context/TestIsAjaxRequest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL