JBoss Rich Faces SVN: r16141 - branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-12-15 13:21:49 -0500 (Tue, 15 Dec 2009)
New Revision: 16141
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib/ValueBindingValueExpressionAdaptor.java
Log:
ValueBindingValueExpressionAdaptor: added missing handler for "transient" attribute
Modified: branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib/ValueBindingValueExpressionAdaptor.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib/ValueBindingValueExpressionAdaptor.java 2009-12-15 17:57:25 UTC (rev 16140)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/webapp/taglib/ValueBindingValueExpressionAdaptor.java 2009-12-15 18:21:49 UTC (rev 16141)
@@ -117,7 +117,11 @@
}
public Object saveState(FacesContext context) {
- return UIComponentBase.saveAttachedState(context, expression);
+ if (!tranzient) {
+ return UIComponentBase.saveAttachedState(context, expression);
+ } else {
+ return null;
+ }
}
public void setTransient(boolean newTransientValue) {
14 years, 5 months
JBoss Rich Faces SVN: r16140 - in branches/community/3.3.X/framework: impl/src/main and 18 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-12-15 12:57:25 -0500 (Tue, 15 Dec 2009)
New Revision: 16140
Added:
branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/
branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/AjaxStateHolder.java
branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/AjaxStateManager.java
branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/ComponentsLoader.java
branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/ComponentsLoaderImpl.java
branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/TreeStructureNode.java
branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/ajax4jsf/application/
branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/ajax4jsf/application/AjaxStateManager.java
branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/richfaces/
branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/richfaces/context/
branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/richfaces/context/PartialViewContextFactoryImpl.java
branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/richfaces/context/PartialViewContextImpl.java
branches/community/3.3.X/framework/impl/src/main/resources-jsf20/
branches/community/3.3.X/framework/impl/src/main/resources-jsf20/META-INF/
branches/community/3.3.X/framework/impl/src/main/resources-jsf20/META-INF/ajax-context.faces-config.xml
branches/community/3.3.X/framework/test/src/test/java-jsf12/
branches/community/3.3.X/framework/test/src/test/java-jsf12/org/
branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/
branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/
branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/AjaxStateHolderTest.java
branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/AjaxStateManagerTest.java
branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/ComponentLoaderTest.java
branches/community/3.3.X/framework/test/src/test/java-jsf20/
Removed:
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoader.java
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoaderImpl.java
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/TreeStructureNode.java
branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateHolderTest.java
branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateManagerTest.java
branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/ComponentLoaderTest.java
Modified:
branches/community/3.3.X/framework/impl/pom.xml
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
branches/community/3.3.X/framework/test/pom.xml
Log:
https://jira.jboss.org/jira/browse/RF-8204
Modified: branches/community/3.3.X/framework/impl/pom.xml
===================================================================
--- branches/community/3.3.X/framework/impl/pom.xml 2009-12-15 16:57:51 UTC (rev 16139)
+++ branches/community/3.3.X/framework/impl/pom.xml 2009-12-15 17:57:25 UTC (rev 16140)
@@ -39,7 +39,7 @@
<configuration>
<sources>
<source>${frameworkAdditionalSourceFolder}</source>
- </sources>
+ </sources>
</configuration>
</execution>
</executions>
@@ -168,6 +168,11 @@
</configuration>
</plugin>
</plugins>
+ <resources>
+ <resource>
+ <directory>src/main/resources-jsf20</directory>
+ </resource>
+ </resources>
</build>
<dependencies>
<dependency>
Deleted: branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java 2009-12-15 16:57:51 UTC (rev 16139)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -1,227 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.ajax4jsf.application;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.Map;
-
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.context.ContextInitParameters;
-import org.ajax4jsf.util.LRUMap;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * @author asmirnov
- *
- */
-public class AjaxStateHolder implements Serializable, StateHolder {
-
- private static final Log _log = LogFactory.getLog(AjaxStateHolder.class);
- /**
- *
- */
- private static final long serialVersionUID = 6414488517358423537L;
- private static final String STATE_HOLDER = AjaxStateHolder.class.getName();
-
- private final LRUMap<String, LRUMap<String, StateReference>> views;
-
- private final int numberOfViews;
-
- private AjaxStateHolder(int capacity, int numberOfViews) {
- views = new LRUMap<String, LRUMap<String, StateReference>>(capacity+1);
- this.numberOfViews = numberOfViews;
- }
-
- public static StateHolder getInstance(FacesContext context) {
- if (null == context) {
- throw new NullPointerException(
- "FacesContext parameter for get view states object is null");
- }
- ExternalContext externalContext = context.getExternalContext();
- Object session = externalContext.getSession(true);
- Map<String, Object> sessionMap = externalContext.getSessionMap();
- if (_log.isDebugEnabled()) {
- _log.debug("Request for a view states holder instance");
- }
- StateHolder instance = (StateHolder) sessionMap.get(STATE_HOLDER);
- if (instance == null) {
- synchronized (session) {
- instance = (StateHolder) sessionMap.get(STATE_HOLDER);
- if (null == instance) {
- // Create and store in session new state holder.
- int numbersOfViewsInSession = ContextInitParameters
- .getNumbersOfViewsInSession(context);
- int numbersOfLogicalViews = ContextInitParameters
- .getNumbersOfLogicalViews(context);
- if (_log.isDebugEnabled()) {
- _log
- .debug("No AjaxStateHolder instance in session, create new for hold "
- + numbersOfViewsInSession
- + " viewId and "
- + numbersOfLogicalViews
- + " logical views for each");
- }
- instance = new AjaxStateHolder(numbersOfViewsInSession,
- numbersOfLogicalViews);
- sessionMap.put(STATE_HOLDER, instance);
- }
- }
- }
-
- return instance;
- }
-
- /**
- * Updates instance of AjaxStateHolder saved in session in order
- * to force replication in clustered environment
- *
- * @param context
- */
- protected void updateInstance(FacesContext context) {
- ExternalContext externalContext = context.getExternalContext();
- Object session = externalContext.getSession(true);
- Map<String, Object> sessionMap = externalContext.getSessionMap();
-
- synchronized (session) {
- sessionMap.put(STATE_HOLDER, this);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.application.StateHolder#getState(java.lang.String,
- * java.lang.Object)
- */
- public Object[] getState(FacesContext context, String viewId, String sequence) {
- if (null == viewId) {
- throw new NullPointerException(
- "viewId parameter for get saved view state is null");
- }
- Object state[] = null;
- synchronized (views) {
- LRUMap<String, StateReference> viewVersions = views.get(viewId);
- if (null != viewVersions) {
- if (null != sequence) {
- StateReference stateReference = viewVersions.get(sequence);
- if (null != stateReference) {
- state = stateReference.getState();
- }
- }
- if (null == state) {
- if (_log.isDebugEnabled()) {
- _log.debug("No saved view state for sequence "
- + sequence);
- }
- // state = viewVersions.getMostRecent();
- }
- } else if (_log.isDebugEnabled()) {
- _log.debug("No saved view states for viewId " + viewId);
- }
- }
- return state;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.application.StateHolder#saveState(java.lang.String,
- * java.lang.Object, java.lang.Object)
- */
- public void saveState(FacesContext context, String viewId, String sequence, Object[] state) {
- if (null == viewId) {
- throw new NullPointerException(
- "viewId parameter for save view state is null");
- }
- if (null == sequence) {
- throw new NullPointerException(
- "sequence parameter for save view state is null");
- }
- if (null != state) {
- if (_log.isDebugEnabled()) {
- _log.debug("Save new viewState in session for viewId " + viewId
- + " and sequence " + sequence);
- }
- synchronized (views) {
- LRUMap<String, StateReference> viewVersions = views.get(viewId);
- StateReference stateReference = null;
- if (null == viewVersions) {
- // TODO - make size parameter configurable
- viewVersions = new LRUMap<String, StateReference>(
- this.numberOfViews+1);
- views.put(viewId, viewVersions);
- stateReference = new StateReference(state);
- viewVersions.put(sequence, stateReference);
- } else {
- stateReference = viewVersions.get(sequence);
- if(null == stateReference){
- stateReference = new StateReference(state);
- viewVersions.put(sequence, stateReference);
- } else {
- stateReference.setState(state);
- }
- }
- }
-
- //serialization is synchronized in writeObject()
- updateInstance(context);
- }
- }
-
- private void writeObject(java.io.ObjectOutputStream stream)
- throws IOException {
-
- synchronized (views) {
- stream.defaultWriteObject();
- }
- }
-
- private void readObject(java.io.ObjectInputStream stream)
- throws IOException, ClassNotFoundException {
-
- stream.defaultReadObject();
- }
-
- @SuppressWarnings("serial")
- private static class StateReference implements Serializable {
- private Object[] state;
-
- public Object[] getState() {
- return state;
- }
-
- public void setState(Object[] state) {
- this.state = state;
- }
-
- /**
- * @param state
- */
- public StateReference(Object[] state) {
- super();
- this.state = state;
- }
- }
-}
Deleted: branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2009-12-15 16:57:51 UTC (rev 16139)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -1,690 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.ajax4jsf.application;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamClass;
-import java.io.OutputStream;
-import java.io.StringWriter;
-import java.lang.reflect.Constructor;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
-
-import javax.faces.FacesException;
-import javax.faces.FactoryFinder;
-import javax.faces.application.StateManager;
-import javax.faces.component.UIComponentBase;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.render.RenderKit;
-import javax.faces.render.RenderKitFactory;
-import javax.faces.render.ResponseStateManager;
-
-import org.ajax4jsf.context.AjaxContext;
-import org.ajax4jsf.context.ContextInitParameters;
-import org.ajax4jsf.model.KeepAlive;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * @author shura
- *
- */
-public class AjaxStateManager extends StateManager {
-
-
- public static final String CAPTURED_VIEW_STATE = "org.ajax4jsf.captured_view_state";
-
- private final class SeamStateManagerWrapper extends StateManager {
- protected Object getComponentStateToSave(FacesContext arg0) {
- // do nothing
- return null;
- }
-
- protected Object getTreeStructureToSave(FacesContext arg0) {
- // do nothing
- return null;
- }
-
- protected void restoreComponentState(FacesContext arg0,
- UIViewRoot arg1, String arg2) {
- // do nothing
-
- }
-
- protected UIViewRoot restoreTreeStructure(FacesContext arg0,
- String arg1, String arg2) {
- // do nothing
- return null;
- }
-
- public UIViewRoot restoreView(FacesContext arg0, String arg1,
- String arg2) {
- // do nothing
- return null;
- }
-
- @SuppressWarnings("deprecation")
- public SerializedView saveSerializedView(FacesContext context) {
- // delegate to enclosed class method.
- Object[] viewState = buildViewState(context);
- return new SerializedView(viewState[0],viewState[1]);
- }
-
- @Override
- public Object saveView(FacesContext context) {
- // TODO Auto-generated method stub
- return buildViewState(context);
- }
- @SuppressWarnings("deprecation")
- public void writeState(FacesContext arg0, SerializedView arg1)
- throws IOException {
- // do nothing
- }
- }
-
- private static final Class<StateManager> STATE_MANAGER_ARGUMENTS = StateManager.class;
-
- public static final int DEFAULT_NUMBER_OF_VIEWS = 16;
-
- public static final String AJAX_VIEW_SEQUENCE = AjaxStateManager.class.getName()
- + ".AJAX_VIEW_SEQUENCE";
- public static final String VIEW_SEQUENCE = AjaxStateManager.class.getName()
- + ".VIEW_SEQUENCE";
-
- private final StateManager parent;
-
- private StateManager seamStateManager;
-
- private final ComponentsLoader componentLoader;
-
- private static final Log _log = LogFactory.getLog(AjaxStateManager.class);
-
- public static final String VIEW_SEQUENCE_ATTRIBUTE = AjaxStateManager.class
- .getName()
- + ".view_sequence";
-
- private static final int UNCOMPRESSED_FLAG = 0;
- private static final int COMPRESSED_FLAG = 1;
-
- /**
- * @param parent
- */
- public AjaxStateManager(StateManager parent) {
- super();
- this.parent = parent;
- componentLoader = new ComponentsLoaderImpl();
- // HACK - Seam perform significant operations before save tree state.
- // Try to create it instance by reflection,
- // to call in real state saving operations.
- ClassLoader classLoader = Thread.currentThread()
- .getContextClassLoader();
- if (null == classLoader) {
- classLoader = AjaxStateManager.class.getClassLoader();
- }
- try {
- Class<? extends StateManager> seamStateManagerClass = classLoader
- .loadClass("org.jboss.seam.jsf.SeamStateManager")
- .asSubclass(StateManager.class);
- Constructor<? extends StateManager> constructor = seamStateManagerClass
- .getConstructor(STATE_MANAGER_ARGUMENTS);
- seamStateManager = constructor
- .newInstance(new Object[] { new SeamStateManagerWrapper() });
- if (_log.isDebugEnabled()) {
- _log.debug("Create instance of the SeamStateManager");
- }
- } catch (Exception e) {
- seamStateManager = null;
- if (_log.isDebugEnabled()) {
- _log.debug("SeamStateManager is not present");
- }
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.application.StateManager#getComponentStateToSave(javax.faces.context.FacesContext)
- */
- protected Object getComponentStateToSave(FacesContext context) {
- Object treeState = context.getViewRoot().processSaveState(context);
- Object state[] = { treeState, getAdditionalState(context) };
- return state;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.application.StateManager#getTreeStructureToSave(javax.faces.context.FacesContext)
- */
- protected Object getTreeStructureToSave(FacesContext context) {
- TreeStructureNode treeStructure = new TreeStructureNode();
- treeStructure.apply(context, context.getViewRoot(),
- new HashSet<String>());
- return treeStructure;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.application.StateManager#restoreComponentState(javax.faces.context.FacesContext,
- * javax.faces.component.UIViewRoot, java.lang.String)
- */
- protected void restoreComponentState(FacesContext context,
- UIViewRoot viewRoot, String renderKitId) {
- throw new UnsupportedOperationException();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.application.StateManager#restoreTreeStructure(javax.faces.context.FacesContext,
- * java.lang.String, java.lang.String)
- */
- protected UIViewRoot restoreTreeStructure(FacesContext context,
- String viewId, String renderKitId) {
- throw new UnsupportedOperationException();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.application.StateManager#writeState(javax.faces.context.FacesContext,
- * javax.faces.application.StateManager.SerializedView)
- */
- public void writeState(FacesContext context, Object state)
- throws IOException {
- RenderKit renderKit = getRenderKit(context);
- ResponseStateManager responseStateManager = renderKit
- .getResponseStateManager();
- Object[] stateArray = getStateArray( state );
- if(null == stateArray[0] && null == stateArray[1]){
- // Myfaces https://issues.apache.org/jira/browse/MYFACES-1753 hack.
- stateArray=new Object[]{getLogicalViewId(context),null};
- }
- writeState(context, responseStateManager, stateArray);
- if (_log.isDebugEnabled()) {
- _log.debug("Write view state to the response");
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.application.StateManager#writeState(javax.faces.context.FacesContext,
- * javax.faces.application.StateManager.SerializedView)
- */
- @SuppressWarnings("deprecation")
- public void writeState(FacesContext context, SerializedView state)
- throws IOException {
- RenderKit renderKit = getRenderKit(context);
- ResponseStateManager responseStateManager = renderKit
- .getResponseStateManager();
- Object[] stateArray;
- if(null == state.getState() && null == state.getStructure()){
- // MyFaces https://issues.apache.org/jira/browse/MYFACES-1753 hack
- stateArray = new Object[]{getLogicalViewId(context),null};
- } else {
- stateArray = new Object[] {
- state.getStructure(),state.getState() };
- }
- writeState(context, responseStateManager, stateArray);
- if (_log.isDebugEnabled()) {
- _log.debug("Write view state to the response");
- }
- }
-
- /**
- * @param context
- * @param state
- * @param responseStateManager
- * @throws IOException
- * @throws FacesException
- */
- private Object[] getStateArray(Object state) throws IOException,
- FacesException {
- if (null != state && state.getClass().isArray()
- && state.getClass().getComponentType().equals(Object.class)) {
- Object stateArray[] = (Object[]) state;
- if (2 == stateArray.length) {
- return stateArray;
- } else {
- throw new FacesException("Unexpected length of the state object array "+stateArray.length);
- }
- } else {
- throw new FacesException("Unexpected type of the state "+state.getClass().getName());
- }
- }
-
- private void writeState(FacesContext context,
- ResponseStateManager responseStateManager, Object[] stateArray)
- throws IOException {
- // Capture writed state into string.
- ResponseWriter originalWriter = context.getResponseWriter();
- StringWriter buff = new StringWriter(128);
- try {
- ResponseWriter stateResponseWriter = originalWriter
- .cloneWithWriter(buff);
- context.setResponseWriter(stateResponseWriter);
- responseStateManager.writeState(context, stateArray);
- stateResponseWriter.flush();
- String stateString = buff.toString();
- originalWriter.write(stateString);
- String stateValue = getStateValue(stateString);
- context.getExternalContext().getRequestMap().put(CAPTURED_VIEW_STATE, stateValue);
- if (null != stateValue) {
- } else {
- }
- } finally {
- context.setResponseWriter(originalWriter);
- }
- }
-
- static final Pattern PATTERN = Pattern.compile(".*<input.*(?:\\svalue=[\"\'](\\S*)[\"\']\\s).*name=[\"']"+ResponseStateManager.VIEW_STATE_PARAM+"[\"'].*>");
- static final Pattern PATTERN2 = Pattern.compile(".*<input .*name=[\"']"+ResponseStateManager.VIEW_STATE_PARAM+"[\"'].*(?:\\svalue=[\"\'](\\S*)[\"\']\\s).*>");
-
-
- /**
- * Parse content of the writed viewState hidden input field for a state value.
- * @param input
- * @return
- */
- private String getStateValue(String input) {
- Matcher matcher = PATTERN.matcher(input);
- if(!matcher.matches()){
- matcher = PATTERN2.matcher(input);
- if(!matcher.matches()){
- return null;
- }
- }
- return matcher.group(1);
- }
-
- private static final Map<String,Class<?>> PRIMITIVE_CLASSES =
- new HashMap<String,Class<?>>(9, 1.0F);
-
- static {
- PRIMITIVE_CLASSES.put("boolean", boolean.class);
- PRIMITIVE_CLASSES.put("byte", byte.class);
- PRIMITIVE_CLASSES.put("char", char.class);
- PRIMITIVE_CLASSES.put("short", short.class);
- PRIMITIVE_CLASSES.put("int", int.class);
- PRIMITIVE_CLASSES.put("long", long.class);
- PRIMITIVE_CLASSES.put("float", float.class);
- PRIMITIVE_CLASSES.put("double", double.class);
- PRIMITIVE_CLASSES.put("void", void.class);
- }
-
- private static final Object handleRestoreState(FacesContext context, Object state) {
- if (ContextInitParameters.isSerializeServerState(context)) {
- ObjectInputStream ois = null;
- try {
- ByteArrayInputStream bais = new ByteArrayInputStream((byte[]) state);
- InputStream is = bais;
-
- int compressionFlag = is.read();
- if(compressionFlag == COMPRESSED_FLAG) {
- is = new GZIPInputStream(is);
- }
-
- ois = new ObjectInputStream(is) {
- @Override
- protected Class<?> resolveClass(ObjectStreamClass desc)
- throws IOException, ClassNotFoundException {
- String name = desc.getName();
- try {
- return Class.forName(name, true,
- Thread.currentThread().getContextClassLoader());
- } catch (ClassNotFoundException cnfe) {
- Class<?> clazz = PRIMITIVE_CLASSES.get(name);
- if (clazz != null) {
- return clazz;
- } else {
- throw cnfe;
- }
- }
- }
- };
- return ois.readObject();
- } catch (Exception e) {
- throw new FacesException(e);
- } finally {
- if (ois != null) {
- try {
- ois.close();
- } catch (IOException ignored) { }
- }
- }
- } else {
- return state;
- }
- }
-
- private static final Object handleSaveState(FacesContext context, Object state) {
- if (ContextInitParameters.isSerializeServerState(context)) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- ObjectOutputStream oas = null;
- try {
- OutputStream os = baos;
- if (ContextInitParameters.isCompressServerState(context)) {
- os.write(COMPRESSED_FLAG);
- os = new GZIPOutputStream(os, 1024);
- } else {
- os.write(UNCOMPRESSED_FLAG);
- }
-
- oas = new ObjectOutputStream(os);
- oas.writeObject(state);
- oas.flush();
- } catch (Exception e) {
- throw new FacesException(e);
- } finally {
- if (oas != null) {
- try {
- oas.close();
- } catch (IOException ignored) { }
- }
- }
- return baos.toByteArray();
- } else {
- return state;
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.application.StateManager#restoreView(javax.faces.context.FacesContext,
- * java.lang.String, java.lang.String)
- */
- public UIViewRoot restoreView(FacesContext context, String viewId,
- String renderKitId) {
- UIViewRoot viewRoot = null;
- ResponseStateManager responseStateManager = getRenderKit(context,
- renderKitId).getResponseStateManager();
- TreeStructureNode treeStructure = null;
- Object[] state = null;
- Object[] serializedView = null;
- if (isSavingStateInClient(context)) {
- serializedView = (Object[]) responseStateManager.getState(context,
- viewId);
-
- if (null != serializedView) {
- treeStructure = (TreeStructureNode) serializedView[0];
- state = (Object[]) serializedView[1];
- }
- } else {
- serializedView = restoreStateFromSession(context, viewId,
- renderKitId);
-
- if (null != serializedView) {
- treeStructure = (TreeStructureNode) serializedView[0];
- state = (Object[]) handleRestoreState(context, serializedView[1]);
- }
- }
-
- if (null != treeStructure) {
- viewRoot = (UIViewRoot) treeStructure.restore(componentLoader);
- if (null != viewRoot && null != state) {
- viewRoot.processRestoreState(context, state[0]);
- restoreAdditionalState(context, state[1]);
- }
- }
- return viewRoot;
-
- }
-
- @SuppressWarnings("deprecation")
- public SerializedView saveSerializedView(FacesContext context) {
- Object[] stateViewArray;
- if (null == seamStateManager) {
- stateViewArray = buildViewState(context);
- } else {
- // Delegate save method to seam State Manager.
- stateViewArray=(Object[]) seamStateManager.saveView(context);
- }
- return new SerializedView(stateViewArray[0],stateViewArray[1]);
- }
-
- @Override
- public Object saveView(FacesContext context) {
- if (null == seamStateManager) {
- return buildViewState(context);
- } else {
- // Delegate save method to seam State Manager.
- return seamStateManager.saveView(context);
- }
- }
- /**
- * @param context
- * @return
- * @see javax.faces.application.StateManager#isSavingStateInClient(javax.faces.context.FacesContext)
- */
- public boolean isSavingStateInClient(FacesContext context) {
- return parent.isSavingStateInClient(context);
- }
-
- protected Object[] restoreStateFromSession(FacesContext context,
- String viewId, String renderKitId) {
- String id = restoreLogicalViewId(context, viewId, renderKitId);
- StateHolder stateHolder = getStateHolder(context);
- Object[] restoredState = stateHolder.getState(context, viewId, id);
-
- if (restoredState != null && id != null) {
- context.getExternalContext().getRequestMap().put(AJAX_VIEW_SEQUENCE, id);
- }
-
- return restoredState;
- }
-
- /**
- * @param context
- * @return
- */
- protected Object[] buildViewState(FacesContext context) {
- Object[] viewStateArray = null;
- UIViewRoot viewRoot = context.getViewRoot();
- if (null != viewRoot && !viewRoot.isTransient()) {
- TreeStructureNode treeStructure = (TreeStructureNode) getTreeStructureToSave(context);
- Object state = getComponentStateToSave(context);
- if (isSavingStateInClient(context)) {
- viewStateArray = new Object[]{treeStructure, state};
- } else {
- viewStateArray = saveStateInSession(context, treeStructure,
- handleSaveState(context, state));
- }
-
- }
- return viewStateArray;
- }
-
- /**
- * @param context
- * @param treeStructure
- * @param state
- * @return
- */
- protected Object[] saveStateInSession(FacesContext context,
- Object treeStructure, Object state) {
- Object[] serializedView;
- UIViewRoot viewRoot = context.getViewRoot();
- StateHolder stateHolder = getStateHolder(context);
- String id = getLogicalViewId(context);
- stateHolder.saveState(context, viewRoot.getViewId(), id, new Object[] {
- treeStructure, state });
- serializedView = new Object[]{id, null};
- return serializedView;
- }
-
- /**
- * @param context
- * @return
- */
- protected StateHolder getStateHolder(FacesContext context) {
- return AjaxStateHolder.getInstance(context);
- }
-
- protected Object getAdditionalState(FacesContext context) {
- Map<String, Object> keepAliveBeans = new HashMap<String, Object>();
- Map<String, Object> requestMap = context.getExternalContext()
- .getRequestMap();
- // Save all objects form request map wich marked by @KeepAlive
- // annotations
- for (Entry<String, Object> requestEntry : requestMap.entrySet()) {
- Object bean = requestEntry.getValue();
- // check value for a NULL -
- // http://jira.jboss.com/jira/browse/RF-3576
- if (null != bean
- && bean.getClass().isAnnotationPresent(KeepAlive.class)) {
- keepAliveBeans.put(requestEntry.getKey(), bean);
- }
- }
- if (keepAliveBeans.size() > 0) {
- return UIComponentBase.saveAttachedState(context, keepAliveBeans);
- } else {
- return null;
- }
- }
-
- @SuppressWarnings("unchecked")
- protected void restoreAdditionalState(FacesContext context, Object state) {
- if (null != state) {
- boolean isAjax = AjaxContext.getCurrentInstance(context).isAjaxRequest();
-
- // Append all saved beans to the request map.
- Map beansMap = (Map) UIComponentBase.restoreAttachedState(context,
- state);
- Map<String, Object> requestMap = context.getExternalContext()
- .getRequestMap();
- for (Object key : beansMap.keySet()) {
- Object bean = beansMap.get(key);
- if (bean != null) {
- KeepAlive annotation = bean.getClass().getAnnotation(KeepAlive.class);
- if (annotation != null) {
- if (!isAjax && annotation.ajaxOnly()) {
-
- //skip ajax-only beans for non-ajax requests
- continue;
- }
- }
- }
-
- requestMap.put((String) key, bean);
- }
- }
- }
-
- /**
- * Restore logical view id from request.
- *
- * @param context
- * @param viewId
- * @param renderKitId
- * @return
- */
- @SuppressWarnings("deprecation")
- protected String restoreLogicalViewId(FacesContext context, String viewId,
- String renderKitId) {
- String id = (String) getRenderKit(context, renderKitId)
- .getResponseStateManager().getTreeStructureToRestore(context,
- viewId);
- return id;
- }
-
- /**
- * Return logical Id for current request view state. For a faces requests,
- * generate sequence numbers. For a ajax request, attempt to re-use id from
- * request submit.
- *
- * @param context
- * @return
- */
- protected String getLogicalViewId(FacesContext context) {
- AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
- ExternalContext externalContext = context.getExternalContext();
- Object id=null;
- Map<String, Object> requestMap = externalContext.getRequestMap();
- id = requestMap.get(ajaxContext.isAjaxRequest()?AJAX_VIEW_SEQUENCE:VIEW_SEQUENCE);
- if (null != id) {
- return id.toString();
- }
- // Store sequence in session, to avoyd claster configuration problem
- // see https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=662
- Object session = externalContext.getSession(true);
- int viewSequence;
- synchronized (session) {
- Map<String, Object> sessionMap = externalContext.getSessionMap();
- Integer sequence = (Integer) sessionMap
- .get(VIEW_SEQUENCE_ATTRIBUTE);
- if (null != sequence) {
- viewSequence = sequence.intValue();
- } else {
- viewSequence = 0;
- }
- if (viewSequence++ == Character.MAX_VALUE) {
- viewSequence = 0;
- }
- sessionMap.put(VIEW_SEQUENCE_ATTRIBUTE, new Integer(viewSequence));
- }
- String logicalViewId = UIViewRoot.UNIQUE_ID_PREFIX + ((int) viewSequence);
- // Store new viewId in the request parameters, to avoid re-increments in the same request.
- requestMap.put(VIEW_SEQUENCE,logicalViewId);
- return logicalViewId;
- }
-
- protected RenderKit getRenderKit(FacesContext context) {
- String renderKitId = null;
- UIViewRoot viewRoot = context.getViewRoot();
- if (null != viewRoot) {
- renderKitId = viewRoot.getRenderKitId();
- }
- if (null == renderKitId) {
- renderKitId = context.getApplication().getViewHandler()
- .calculateRenderKitId(context);
- }
- return getRenderKit(context, renderKitId);
- }
-
- protected RenderKit getRenderKit(FacesContext context, String renderKitId) {
- RenderKit renderKit = context.getRenderKit();
- if (null == renderKit) {
- RenderKitFactory factory = (RenderKitFactory) FactoryFinder
- .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- renderKit = factory.getRenderKit(context, renderKitId);
- }
- return renderKit;
- }
-
-}
Deleted: branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoader.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoader.java 2009-12-15 16:57:51 UTC (rev 16139)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoader.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -1,29 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.ajax4jsf.application;
-
-import javax.faces.component.UIComponent;
-
-public interface ComponentsLoader {
-
- public abstract UIComponent createComponent(String type);
-
-}
\ No newline at end of file
Deleted: branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoaderImpl.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoaderImpl.java 2009-12-15 16:57:51 UTC (rev 16139)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoaderImpl.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -1,83 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.ajax4jsf.application;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.faces.FacesException;
-import javax.faces.component.UIComponent;
-
-/**
- * @author asmirnov
- *
- */
-public class ComponentsLoaderImpl implements ComponentsLoader {
-
- private Map<String, Class<? extends UIComponent>> classes;
-
- private ClassLoader loader;
-
- public ComponentsLoaderImpl() {
- classes = new ConcurrentHashMap<String, Class<? extends UIComponent>>(
- 64);
- loader = Thread.currentThread().getContextClassLoader();
- if (loader == null) {
- loader = ComponentsLoaderImpl.class.getClassLoader();
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.ajax4jsf.portlet.application.ComponentsLoader#createComponent(java
- * .lang.String)
- */
- public UIComponent createComponent(String type) {
- // Classes is a lazy Map, new object will be create on the fly.
- Class<? extends UIComponent> componentClass = classes.get(type);
- if(null == componentClass){
- try {
- componentClass = loader.loadClass(type).asSubclass(UIComponent.class);
- classes.put(type, componentClass);
- } catch (ClassNotFoundException e) {
- throw new FacesException("Can't load class " + type, e);
- }
-
- }
- try {
- return componentClass.newInstance();
- } catch (InstantiationException e) {
- throw new FacesException(
- "Error on create new instance of the component with class "
- + type, e);
- } catch (IllegalAccessException e) {
- throw new FacesException(
- "IllegalAccess on attempt to create new instance of the component with class "
- + type, e);
- }
- }
-
- ClassLoader getClassLoader() {
- return loader;
- }
-}
Deleted: branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/TreeStructureNode.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/TreeStructureNode.java 2009-12-15 16:57:51 UTC (rev 16139)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/TreeStructureNode.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -1,264 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.ajax4jsf.application;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-/**
- * @author asmirnov
- *
- */
-final class TreeStructureNode implements Externalizable {
- /**
- * TODO - implement Externalizable to reduce serialized state.
- */
- private static final long serialVersionUID = -9038742487716977912L;
-
- private static final String NULL_ID = "";
-
- private List<FacetEntry> facets = null;
-
- private List<TreeStructureNode> children = null;
-
- private String type;
-
- private String id;
-
- public TreeStructureNode() {
- }
-
- public void apply(FacesContext context, UIComponent component,
- Set<String> uniqueIds) {
- type = component.getClass().getName();
- id = component.getId();
- String clientId = component.getClientId(context);
- if (!uniqueIds.add(clientId)) {
- throw new IllegalStateException("duplicate Id for a component "
- + clientId);
- }
- Map<String, UIComponent> componentFacets = component.getFacets();
- for (Iterator<Entry<String, UIComponent>> i = componentFacets
- .entrySet().iterator(); i.hasNext();) {
- Entry<String, UIComponent> element = i.next();
- UIComponent f = element.getValue();
- if (!f.isTransient()) {
- TreeStructureNode facet = new TreeStructureNode();
- facet.apply(context, f, uniqueIds);
- if (null == facets) {
- facets = new ArrayList<FacetEntry>(componentFacets.size());
- }
- facets.add(new FacetEntry(element.getKey(), facet));
-
- }
- }
- List<UIComponent> componentChildren = component.getChildren();
- for (Iterator<UIComponent> i = componentChildren.iterator(); i
- .hasNext();) {
- UIComponent child = i.next();
- if (!child.isTransient()) {
- TreeStructureNode t = new TreeStructureNode();
- t.apply(context, child, uniqueIds);
- if (null == children) {
- children = new ArrayList<TreeStructureNode>(
- componentChildren.size());
- }
- children.add(t);
-
- }
- }
- }
-
- public UIComponent restore(ComponentsLoader loader) {
- UIComponent component;
- component = loader.createComponent(type);
- component.setId(id);
- if (null != facets) {
- for (Iterator<FacetEntry> i = facets.iterator(); i.hasNext();) {
- FacetEntry element = i.next();
- UIComponent facet = (element.getNode()).restore(loader);
- component.getFacets().put(element.getName(), facet);
- }
-
- }
- if (null != children) {
- for (Iterator<TreeStructureNode> i = children.iterator(); i
- .hasNext();) {
- TreeStructureNode node = i.next();
- UIComponent child = node.restore(loader);
- component.getChildren().add(child);
- }
-
- }
- return component;
- }
-
- /**
- * @return the facets
- */
- public List<FacetEntry> getFacets() {
- return facets;
- }
-
-
- /**
- * @return the children
- */
- public List<TreeStructureNode> getChildren() {
- return children;
- }
-
-
- /**
- * @return the type
- */
- public String getType() {
- return type;
- }
-
- /**
- * @param type
- * the type to set
- */
- public void setType(String type) {
- this.type = type;
- }
-
- /**
- * @return the id
- */
- public String getId() {
- return id;
- }
-
- /**
- * @param id
- * the id to set
- */
- public void setId(String id) {
- this.id = id;
- }
-
- public void readExternal(ObjectInput in) throws IOException,
- ClassNotFoundException {
- type = in.readUTF();
- id = in.readUTF();
- if (NULL_ID.equals(id)) {
- id = null;
- }
- int facetsSize = in.readInt();
- if (facetsSize > 0) {
- facets = new ArrayList<FacetEntry>(facetsSize);
- for (int i = 0; i < facetsSize; i++) {
- String facetName = in.readUTF();
- TreeStructureNode facet = new TreeStructureNode();
- facet.readExternal(in);
- facets.add(new FacetEntry(facetName, facet));
- }
- }
- int childrenSize = in.readInt();
- if (childrenSize > 0) {
- children = new ArrayList<TreeStructureNode>(childrenSize);
- for (int i = 0; i < childrenSize; i++) {
- TreeStructureNode child = new TreeStructureNode();
- child.readExternal(in);
- children.add(child);
- }
- }
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeUTF(type);
- out.writeUTF(null == id ? NULL_ID : id);
- if (null != facets) {
- out.writeInt(facets.size());
- for (Iterator<FacetEntry> i = facets.iterator(); i.hasNext();) {
- FacetEntry entry = i.next();
- out.writeUTF(entry.getName());
- TreeStructureNode node = entry.getNode();
- node.writeExternal(out);
- }
-
- } else {
- out.writeInt(0);
- }
- if (null != children) {
- out.writeInt(children.size());
- for (Iterator<TreeStructureNode> i = children.iterator(); i
- .hasNext();) {
- TreeStructureNode child = i.next();
- child.writeExternal(out);
- }
-
- } else {
- out.writeInt(0);
- }
- }
-
- @SuppressWarnings("serial")
- static final class FacetEntry implements Externalizable {
- private String name;
- private TreeStructureNode node;
-
- public String getName() {
- return name;
- }
-
- public TreeStructureNode getNode() {
- return node;
- }
-
- /**
- * @param name
- * @param node
- */
- public FacetEntry(String name, TreeStructureNode node) {
- super();
- this.name = name;
- this.node = node;
- }
-
- public void readExternal(ObjectInput in) throws IOException,
- ClassNotFoundException {
- this.name = in.readUTF();
- this.node = new TreeStructureNode();
- this.node.readExternal(in);
- }
-
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeUTF(name);
- node.writeExternal(out);
- }
- }
-}
\ No newline at end of file
Modified: branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java 2009-12-15 16:57:51 UTC (rev 16139)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -23,16 +23,20 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
+import java.util.Map.Entry;
import javax.el.MethodExpression;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
import javax.faces.component.ContextCallback;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
@@ -51,6 +55,7 @@
import org.ajax4jsf.context.ViewIdHolder;
import org.ajax4jsf.event.AjaxListener;
import org.ajax4jsf.event.EventsQueue;
+import org.ajax4jsf.model.KeepAlive;
import org.ajax4jsf.renderkit.AjaxContainerRenderer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -690,4 +695,71 @@
return _brige;
}
+ protected Object getAdditionalState(FacesContext context) {
+ Map<String, Object> keepAliveBeans = new HashMap<String, Object>();
+ Map<String, Object> requestMap = context.getExternalContext()
+ .getRequestMap();
+ // Save all objects form request map wich marked by @KeepAlive
+ // annotations
+ for (Entry<String, Object> requestEntry : requestMap.entrySet()) {
+ Object bean = requestEntry.getValue();
+ // check value for a NULL -
+ // http://jira.jboss.com/jira/browse/RF-3576
+ if (null != bean
+ && bean.getClass().isAnnotationPresent(KeepAlive.class)) {
+ keepAliveBeans.put(requestEntry.getKey(), bean);
+ }
+ }
+ if (keepAliveBeans.size() > 0) {
+ return UIComponentBase.saveAttachedState(context, keepAliveBeans);
+ } else {
+ return null;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void restoreAdditionalState(FacesContext context, Object state) {
+ if (null != state) {
+ boolean isAjax = AjaxContext.getCurrentInstance(context).isAjaxRequest();
+
+ // Append all saved beans to the request map.
+ Map beansMap = (Map) UIComponentBase.restoreAttachedState(context,
+ state);
+ Map<String, Object> requestMap = context.getExternalContext()
+ .getRequestMap();
+ for (Object key : beansMap.keySet()) {
+ Object bean = beansMap.get(key);
+ if (bean != null) {
+ KeepAlive annotation = bean.getClass().getAnnotation(KeepAlive.class);
+ if (annotation != null) {
+ if (!isAjax && annotation.ajaxOnly()) {
+
+ //skip ajax-only beans for non-ajax requests
+ continue;
+ }
+ }
+ }
+
+ requestMap.put((String) key, bean);
+ }
+ }
+ }
+
+ @Override
+ public Object processSaveState(FacesContext context) {
+ Object[] state = new Object[2];
+ state[0] = super.processSaveState(context);
+ state[1] = getAdditionalState(context);
+
+ return state;
+ }
+
+ @Override
+ public void processRestoreState(FacesContext context, Object stateObject) {
+ Object[] state = (Object[]) stateObject;
+
+ super.processRestoreState(context, state[0]);
+ restoreAdditionalState(context, state[1]);
+ }
+
}
Copied: branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/AjaxStateHolder.java (from rev 16112, branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateHolder.java)
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/AjaxStateHolder.java (rev 0)
+++ branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/AjaxStateHolder.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -0,0 +1,227 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.ajax4jsf.application;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.context.ContextInitParameters;
+import org.ajax4jsf.util.LRUMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class AjaxStateHolder implements Serializable, StateHolder {
+
+ private static final Log _log = LogFactory.getLog(AjaxStateHolder.class);
+ /**
+ *
+ */
+ private static final long serialVersionUID = 6414488517358423537L;
+ private static final String STATE_HOLDER = AjaxStateHolder.class.getName();
+
+ private final LRUMap<String, LRUMap<String, StateReference>> views;
+
+ private final int numberOfViews;
+
+ private AjaxStateHolder(int capacity, int numberOfViews) {
+ views = new LRUMap<String, LRUMap<String, StateReference>>(capacity+1);
+ this.numberOfViews = numberOfViews;
+ }
+
+ public static StateHolder getInstance(FacesContext context) {
+ if (null == context) {
+ throw new NullPointerException(
+ "FacesContext parameter for get view states object is null");
+ }
+ ExternalContext externalContext = context.getExternalContext();
+ Object session = externalContext.getSession(true);
+ Map<String, Object> sessionMap = externalContext.getSessionMap();
+ if (_log.isDebugEnabled()) {
+ _log.debug("Request for a view states holder instance");
+ }
+ StateHolder instance = (StateHolder) sessionMap.get(STATE_HOLDER);
+ if (instance == null) {
+ synchronized (session) {
+ instance = (StateHolder) sessionMap.get(STATE_HOLDER);
+ if (null == instance) {
+ // Create and store in session new state holder.
+ int numbersOfViewsInSession = ContextInitParameters
+ .getNumbersOfViewsInSession(context);
+ int numbersOfLogicalViews = ContextInitParameters
+ .getNumbersOfLogicalViews(context);
+ if (_log.isDebugEnabled()) {
+ _log
+ .debug("No AjaxStateHolder instance in session, create new for hold "
+ + numbersOfViewsInSession
+ + " viewId and "
+ + numbersOfLogicalViews
+ + " logical views for each");
+ }
+ instance = new AjaxStateHolder(numbersOfViewsInSession,
+ numbersOfLogicalViews);
+ sessionMap.put(STATE_HOLDER, instance);
+ }
+ }
+ }
+
+ return instance;
+ }
+
+ /**
+ * Updates instance of AjaxStateHolder saved in session in order
+ * to force replication in clustered environment
+ *
+ * @param context
+ */
+ protected void updateInstance(FacesContext context) {
+ ExternalContext externalContext = context.getExternalContext();
+ Object session = externalContext.getSession(true);
+ Map<String, Object> sessionMap = externalContext.getSessionMap();
+
+ synchronized (session) {
+ sessionMap.put(STATE_HOLDER, this);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.application.StateHolder#getState(java.lang.String,
+ * java.lang.Object)
+ */
+ public Object[] getState(FacesContext context, String viewId, String sequence) {
+ if (null == viewId) {
+ throw new NullPointerException(
+ "viewId parameter for get saved view state is null");
+ }
+ Object state[] = null;
+ synchronized (views) {
+ LRUMap<String, StateReference> viewVersions = views.get(viewId);
+ if (null != viewVersions) {
+ if (null != sequence) {
+ StateReference stateReference = viewVersions.get(sequence);
+ if (null != stateReference) {
+ state = stateReference.getState();
+ }
+ }
+ if (null == state) {
+ if (_log.isDebugEnabled()) {
+ _log.debug("No saved view state for sequence "
+ + sequence);
+ }
+ // state = viewVersions.getMostRecent();
+ }
+ } else if (_log.isDebugEnabled()) {
+ _log.debug("No saved view states for viewId " + viewId);
+ }
+ }
+ return state;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.application.StateHolder#saveState(java.lang.String,
+ * java.lang.Object, java.lang.Object)
+ */
+ public void saveState(FacesContext context, String viewId, String sequence, Object[] state) {
+ if (null == viewId) {
+ throw new NullPointerException(
+ "viewId parameter for save view state is null");
+ }
+ if (null == sequence) {
+ throw new NullPointerException(
+ "sequence parameter for save view state is null");
+ }
+ if (null != state) {
+ if (_log.isDebugEnabled()) {
+ _log.debug("Save new viewState in session for viewId " + viewId
+ + " and sequence " + sequence);
+ }
+ synchronized (views) {
+ LRUMap<String, StateReference> viewVersions = views.get(viewId);
+ StateReference stateReference = null;
+ if (null == viewVersions) {
+ // TODO - make size parameter configurable
+ viewVersions = new LRUMap<String, StateReference>(
+ this.numberOfViews+1);
+ views.put(viewId, viewVersions);
+ stateReference = new StateReference(state);
+ viewVersions.put(sequence, stateReference);
+ } else {
+ stateReference = viewVersions.get(sequence);
+ if(null == stateReference){
+ stateReference = new StateReference(state);
+ viewVersions.put(sequence, stateReference);
+ } else {
+ stateReference.setState(state);
+ }
+ }
+ }
+
+ //serialization is synchronized in writeObject()
+ updateInstance(context);
+ }
+ }
+
+ private void writeObject(java.io.ObjectOutputStream stream)
+ throws IOException {
+
+ synchronized (views) {
+ stream.defaultWriteObject();
+ }
+ }
+
+ private void readObject(java.io.ObjectInputStream stream)
+ throws IOException, ClassNotFoundException {
+
+ stream.defaultReadObject();
+ }
+
+ @SuppressWarnings("serial")
+ private static class StateReference implements Serializable {
+ private Object[] state;
+
+ public Object[] getState() {
+ return state;
+ }
+
+ public void setState(Object[] state) {
+ this.state = state;
+ }
+
+ /**
+ * @param state
+ */
+ public StateReference(Object[] state) {
+ super();
+ this.state = state;
+ }
+ }
+}
Copied: branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/AjaxStateManager.java (from rev 16112, branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/AjaxStateManager.java)
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/AjaxStateManager.java (rev 0)
+++ branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/AjaxStateManager.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -0,0 +1,634 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.application;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+import javax.faces.FacesException;
+import javax.faces.FactoryFinder;
+import javax.faces.application.StateManager;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+import javax.faces.render.ResponseStateManager;
+
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.context.ContextInitParameters;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author shura
+ *
+ */
+public class AjaxStateManager extends StateManager {
+
+
+ public static final String CAPTURED_VIEW_STATE = "org.ajax4jsf.captured_view_state";
+
+ private final class SeamStateManagerWrapper extends StateManager {
+ protected Object getComponentStateToSave(FacesContext arg0) {
+ // do nothing
+ return null;
+ }
+
+ protected Object getTreeStructureToSave(FacesContext arg0) {
+ // do nothing
+ return null;
+ }
+
+ protected void restoreComponentState(FacesContext arg0,
+ UIViewRoot arg1, String arg2) {
+ // do nothing
+
+ }
+
+ protected UIViewRoot restoreTreeStructure(FacesContext arg0,
+ String arg1, String arg2) {
+ // do nothing
+ return null;
+ }
+
+ public UIViewRoot restoreView(FacesContext arg0, String arg1,
+ String arg2) {
+ // do nothing
+ return null;
+ }
+
+ @SuppressWarnings("deprecation")
+ public SerializedView saveSerializedView(FacesContext context) {
+ // delegate to enclosed class method.
+ Object[] viewState = buildViewState(context);
+ return new SerializedView(viewState[0],viewState[1]);
+ }
+
+ @Override
+ public Object saveView(FacesContext context) {
+ // TODO Auto-generated method stub
+ return buildViewState(context);
+ }
+ @SuppressWarnings("deprecation")
+ public void writeState(FacesContext arg0, SerializedView arg1)
+ throws IOException {
+ // do nothing
+ }
+ }
+
+ private static final Class<StateManager> STATE_MANAGER_ARGUMENTS = StateManager.class;
+
+ public static final int DEFAULT_NUMBER_OF_VIEWS = 16;
+
+ public static final String AJAX_VIEW_SEQUENCE = AjaxStateManager.class.getName()
+ + ".AJAX_VIEW_SEQUENCE";
+ public static final String VIEW_SEQUENCE = AjaxStateManager.class.getName()
+ + ".VIEW_SEQUENCE";
+
+ private final StateManager parent;
+
+ private StateManager seamStateManager;
+
+ private final ComponentsLoader componentLoader;
+
+ private static final Log _log = LogFactory.getLog(AjaxStateManager.class);
+
+ public static final String VIEW_SEQUENCE_ATTRIBUTE = AjaxStateManager.class
+ .getName()
+ + ".view_sequence";
+
+ private static final int UNCOMPRESSED_FLAG = 0;
+ private static final int COMPRESSED_FLAG = 1;
+
+ /**
+ * @param parent
+ */
+ public AjaxStateManager(StateManager parent) {
+ super();
+ this.parent = parent;
+ componentLoader = new ComponentsLoaderImpl();
+ // HACK - Seam perform significant operations before save tree state.
+ // Try to create it instance by reflection,
+ // to call in real state saving operations.
+ ClassLoader classLoader = Thread.currentThread()
+ .getContextClassLoader();
+ if (null == classLoader) {
+ classLoader = AjaxStateManager.class.getClassLoader();
+ }
+ try {
+ Class<? extends StateManager> seamStateManagerClass = classLoader
+ .loadClass("org.jboss.seam.jsf.SeamStateManager")
+ .asSubclass(StateManager.class);
+ Constructor<? extends StateManager> constructor = seamStateManagerClass
+ .getConstructor(STATE_MANAGER_ARGUMENTS);
+ seamStateManager = constructor
+ .newInstance(new Object[] { new SeamStateManagerWrapper() });
+ if (_log.isDebugEnabled()) {
+ _log.debug("Create instance of the SeamStateManager");
+ }
+ } catch (Exception e) {
+ seamStateManager = null;
+ if (_log.isDebugEnabled()) {
+ _log.debug("SeamStateManager is not present");
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.StateManager#getComponentStateToSave(javax.faces.context.FacesContext)
+ */
+ protected Object getComponentStateToSave(FacesContext context) {
+ return context.getViewRoot().processSaveState(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.StateManager#getTreeStructureToSave(javax.faces.context.FacesContext)
+ */
+ protected Object getTreeStructureToSave(FacesContext context) {
+ TreeStructureNode treeStructure = new TreeStructureNode();
+ treeStructure.apply(context, context.getViewRoot(),
+ new HashSet<String>());
+ return treeStructure;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.StateManager#restoreComponentState(javax.faces.context.FacesContext,
+ * javax.faces.component.UIViewRoot, java.lang.String)
+ */
+ protected void restoreComponentState(FacesContext context,
+ UIViewRoot viewRoot, String renderKitId) {
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.StateManager#restoreTreeStructure(javax.faces.context.FacesContext,
+ * java.lang.String, java.lang.String)
+ */
+ protected UIViewRoot restoreTreeStructure(FacesContext context,
+ String viewId, String renderKitId) {
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.StateManager#writeState(javax.faces.context.FacesContext,
+ * javax.faces.application.StateManager.SerializedView)
+ */
+ public void writeState(FacesContext context, Object state)
+ throws IOException {
+ RenderKit renderKit = getRenderKit(context);
+ ResponseStateManager responseStateManager = renderKit
+ .getResponseStateManager();
+ Object[] stateArray = getStateArray( state );
+ if(null == stateArray[0] && null == stateArray[1]){
+ // Myfaces https://issues.apache.org/jira/browse/MYFACES-1753 hack.
+ stateArray=new Object[]{getLogicalViewId(context),null};
+ }
+ writeState(context, responseStateManager, stateArray);
+ if (_log.isDebugEnabled()) {
+ _log.debug("Write view state to the response");
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.StateManager#writeState(javax.faces.context.FacesContext,
+ * javax.faces.application.StateManager.SerializedView)
+ */
+ @SuppressWarnings("deprecation")
+ public void writeState(FacesContext context, SerializedView state)
+ throws IOException {
+ RenderKit renderKit = getRenderKit(context);
+ ResponseStateManager responseStateManager = renderKit
+ .getResponseStateManager();
+ Object[] stateArray;
+ if(null == state.getState() && null == state.getStructure()){
+ // MyFaces https://issues.apache.org/jira/browse/MYFACES-1753 hack
+ stateArray = new Object[]{getLogicalViewId(context),null};
+ } else {
+ stateArray = new Object[] {
+ state.getStructure(),state.getState() };
+ }
+ writeState(context, responseStateManager, stateArray);
+ if (_log.isDebugEnabled()) {
+ _log.debug("Write view state to the response");
+ }
+ }
+
+ /**
+ * @param context
+ * @param state
+ * @param responseStateManager
+ * @throws IOException
+ * @throws FacesException
+ */
+ private Object[] getStateArray(Object state) throws IOException,
+ FacesException {
+ if (null != state && state.getClass().isArray()
+ && state.getClass().getComponentType().equals(Object.class)) {
+ Object stateArray[] = (Object[]) state;
+ if (2 == stateArray.length) {
+ return stateArray;
+ } else {
+ throw new FacesException("Unexpected length of the state object array "+stateArray.length);
+ }
+ } else {
+ throw new FacesException("Unexpected type of the state "+state.getClass().getName());
+ }
+ }
+
+ private void writeState(FacesContext context,
+ ResponseStateManager responseStateManager, Object[] stateArray)
+ throws IOException {
+ // Capture writed state into string.
+ ResponseWriter originalWriter = context.getResponseWriter();
+ StringWriter buff = new StringWriter(128);
+ try {
+ ResponseWriter stateResponseWriter = originalWriter
+ .cloneWithWriter(buff);
+ context.setResponseWriter(stateResponseWriter);
+ responseStateManager.writeState(context, stateArray);
+ stateResponseWriter.flush();
+ String stateString = buff.toString();
+ originalWriter.write(stateString);
+ String stateValue = getStateValue(stateString);
+ context.getExternalContext().getRequestMap().put(CAPTURED_VIEW_STATE, stateValue);
+ if (null != stateValue) {
+ } else {
+ }
+ } finally {
+ context.setResponseWriter(originalWriter);
+ }
+ }
+
+ static final Pattern PATTERN = Pattern.compile(".*<input.*(?:\\svalue=[\"\'](\\S*)[\"\']\\s).*name=[\"']"+ResponseStateManager.VIEW_STATE_PARAM+"[\"'].*>");
+ static final Pattern PATTERN2 = Pattern.compile(".*<input .*name=[\"']"+ResponseStateManager.VIEW_STATE_PARAM+"[\"'].*(?:\\svalue=[\"\'](\\S*)[\"\']\\s).*>");
+
+
+ /**
+ * Parse content of the writed viewState hidden input field for a state value.
+ * @param input
+ * @return
+ */
+ private String getStateValue(String input) {
+ Matcher matcher = PATTERN.matcher(input);
+ if(!matcher.matches()){
+ matcher = PATTERN2.matcher(input);
+ if(!matcher.matches()){
+ return null;
+ }
+ }
+ return matcher.group(1);
+ }
+
+ private static final Map<String,Class<?>> PRIMITIVE_CLASSES =
+ new HashMap<String,Class<?>>(9, 1.0F);
+
+ static {
+ PRIMITIVE_CLASSES.put("boolean", boolean.class);
+ PRIMITIVE_CLASSES.put("byte", byte.class);
+ PRIMITIVE_CLASSES.put("char", char.class);
+ PRIMITIVE_CLASSES.put("short", short.class);
+ PRIMITIVE_CLASSES.put("int", int.class);
+ PRIMITIVE_CLASSES.put("long", long.class);
+ PRIMITIVE_CLASSES.put("float", float.class);
+ PRIMITIVE_CLASSES.put("double", double.class);
+ PRIMITIVE_CLASSES.put("void", void.class);
+ }
+
+ private static final Object handleRestoreState(FacesContext context, Object state) {
+ if (ContextInitParameters.isSerializeServerState(context)) {
+ ObjectInputStream ois = null;
+ try {
+ ByteArrayInputStream bais = new ByteArrayInputStream((byte[]) state);
+ InputStream is = bais;
+
+ int compressionFlag = is.read();
+ if(compressionFlag == COMPRESSED_FLAG) {
+ is = new GZIPInputStream(is);
+ }
+
+ ois = new ObjectInputStream(is) {
+ @Override
+ protected Class<?> resolveClass(ObjectStreamClass desc)
+ throws IOException, ClassNotFoundException {
+ String name = desc.getName();
+ try {
+ return Class.forName(name, true,
+ Thread.currentThread().getContextClassLoader());
+ } catch (ClassNotFoundException cnfe) {
+ Class<?> clazz = PRIMITIVE_CLASSES.get(name);
+ if (clazz != null) {
+ return clazz;
+ } else {
+ throw cnfe;
+ }
+ }
+ }
+ };
+ return ois.readObject();
+ } catch (Exception e) {
+ throw new FacesException(e);
+ } finally {
+ if (ois != null) {
+ try {
+ ois.close();
+ } catch (IOException ignored) { }
+ }
+ }
+ } else {
+ return state;
+ }
+ }
+
+ private static final Object handleSaveState(FacesContext context, Object state) {
+ if (ContextInitParameters.isSerializeServerState(context)) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+ ObjectOutputStream oas = null;
+ try {
+ OutputStream os = baos;
+ if (ContextInitParameters.isCompressServerState(context)) {
+ os.write(COMPRESSED_FLAG);
+ os = new GZIPOutputStream(os, 1024);
+ } else {
+ os.write(UNCOMPRESSED_FLAG);
+ }
+
+ oas = new ObjectOutputStream(os);
+ oas.writeObject(state);
+ oas.flush();
+ } catch (Exception e) {
+ throw new FacesException(e);
+ } finally {
+ if (oas != null) {
+ try {
+ oas.close();
+ } catch (IOException ignored) { }
+ }
+ }
+ return baos.toByteArray();
+ } else {
+ return state;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.application.StateManager#restoreView(javax.faces.context.FacesContext,
+ * java.lang.String, java.lang.String)
+ */
+ public UIViewRoot restoreView(FacesContext context, String viewId,
+ String renderKitId) {
+ UIViewRoot viewRoot = null;
+ ResponseStateManager responseStateManager = getRenderKit(context,
+ renderKitId).getResponseStateManager();
+ TreeStructureNode treeStructure = null;
+ Object state = null;
+ Object[] serializedView = null;
+ if (isSavingStateInClient(context)) {
+ serializedView = (Object[]) responseStateManager.getState(context,
+ viewId);
+
+ if (null != serializedView) {
+ treeStructure = (TreeStructureNode) serializedView[0];
+ state = serializedView[1];
+ }
+ } else {
+ serializedView = restoreStateFromSession(context, viewId,
+ renderKitId);
+
+ if (null != serializedView) {
+ treeStructure = (TreeStructureNode) serializedView[0];
+ state = handleRestoreState(context, serializedView[1]);
+ }
+ }
+
+ if (null != treeStructure) {
+ viewRoot = (UIViewRoot) treeStructure.restore(componentLoader);
+ if (null != viewRoot && null != state) {
+ viewRoot.processRestoreState(context, state);
+ }
+ }
+ return viewRoot;
+
+ }
+
+ @SuppressWarnings("deprecation")
+ public SerializedView saveSerializedView(FacesContext context) {
+ Object[] stateViewArray;
+ if (null == seamStateManager) {
+ stateViewArray = buildViewState(context);
+ } else {
+ // Delegate save method to seam State Manager.
+ stateViewArray=(Object[]) seamStateManager.saveView(context);
+ }
+ return new SerializedView(stateViewArray[0],stateViewArray[1]);
+ }
+
+ @Override
+ public Object saveView(FacesContext context) {
+ if (null == seamStateManager) {
+ return buildViewState(context);
+ } else {
+ // Delegate save method to seam State Manager.
+ return seamStateManager.saveView(context);
+ }
+ }
+ /**
+ * @param context
+ * @return
+ * @see javax.faces.application.StateManager#isSavingStateInClient(javax.faces.context.FacesContext)
+ */
+ public boolean isSavingStateInClient(FacesContext context) {
+ return parent.isSavingStateInClient(context);
+ }
+
+ protected Object[] restoreStateFromSession(FacesContext context,
+ String viewId, String renderKitId) {
+ String id = restoreLogicalViewId(context, viewId, renderKitId);
+ StateHolder stateHolder = getStateHolder(context);
+ Object[] restoredState = stateHolder.getState(context, viewId, id);
+
+ if (restoredState != null && id != null) {
+ context.getExternalContext().getRequestMap().put(AJAX_VIEW_SEQUENCE, id);
+ }
+
+ return restoredState;
+ }
+
+ /**
+ * @param context
+ * @return
+ */
+ protected Object[] buildViewState(FacesContext context) {
+ Object[] viewStateArray = null;
+ UIViewRoot viewRoot = context.getViewRoot();
+ if (null != viewRoot && !viewRoot.isTransient()) {
+ TreeStructureNode treeStructure = (TreeStructureNode) getTreeStructureToSave(context);
+ Object state = getComponentStateToSave(context);
+ if (isSavingStateInClient(context)) {
+ viewStateArray = new Object[]{treeStructure, state};
+ } else {
+ viewStateArray = saveStateInSession(context, treeStructure,
+ handleSaveState(context, state));
+ }
+
+ }
+ return viewStateArray;
+ }
+
+ /**
+ * @param context
+ * @param treeStructure
+ * @param state
+ * @return
+ */
+ protected Object[] saveStateInSession(FacesContext context,
+ Object treeStructure, Object state) {
+ Object[] serializedView;
+ UIViewRoot viewRoot = context.getViewRoot();
+ StateHolder stateHolder = getStateHolder(context);
+ String id = getLogicalViewId(context);
+ stateHolder.saveState(context, viewRoot.getViewId(), id, new Object[] {
+ treeStructure, state });
+ serializedView = new Object[]{id, null};
+ return serializedView;
+ }
+
+ /**
+ * @param context
+ * @return
+ */
+ protected StateHolder getStateHolder(FacesContext context) {
+ return AjaxStateHolder.getInstance(context);
+ }
+
+ /**
+ * Restore logical view id from request.
+ *
+ * @param context
+ * @param viewId
+ * @param renderKitId
+ * @return
+ */
+ @SuppressWarnings("deprecation")
+ protected String restoreLogicalViewId(FacesContext context, String viewId,
+ String renderKitId) {
+ String id = (String) getRenderKit(context, renderKitId)
+ .getResponseStateManager().getTreeStructureToRestore(context,
+ viewId);
+ return id;
+ }
+
+ /**
+ * Return logical Id for current request view state. For a faces requests,
+ * generate sequence numbers. For a ajax request, attempt to re-use id from
+ * request submit.
+ *
+ * @param context
+ * @return
+ */
+ protected String getLogicalViewId(FacesContext context) {
+ AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
+ ExternalContext externalContext = context.getExternalContext();
+ Object id=null;
+ Map<String, Object> requestMap = externalContext.getRequestMap();
+ id = requestMap.get(ajaxContext.isAjaxRequest()?AJAX_VIEW_SEQUENCE:VIEW_SEQUENCE);
+ if (null != id) {
+ return id.toString();
+ }
+ // Store sequence in session, to avoyd claster configuration problem
+ // see https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=662
+ Object session = externalContext.getSession(true);
+ int viewSequence;
+ synchronized (session) {
+ Map<String, Object> sessionMap = externalContext.getSessionMap();
+ Integer sequence = (Integer) sessionMap
+ .get(VIEW_SEQUENCE_ATTRIBUTE);
+ if (null != sequence) {
+ viewSequence = sequence.intValue();
+ } else {
+ viewSequence = 0;
+ }
+ if (viewSequence++ == Character.MAX_VALUE) {
+ viewSequence = 0;
+ }
+ sessionMap.put(VIEW_SEQUENCE_ATTRIBUTE, new Integer(viewSequence));
+ }
+ String logicalViewId = UIViewRoot.UNIQUE_ID_PREFIX + ((int) viewSequence);
+ // Store new viewId in the request parameters, to avoid re-increments in the same request.
+ requestMap.put(VIEW_SEQUENCE,logicalViewId);
+ return logicalViewId;
+ }
+
+ protected RenderKit getRenderKit(FacesContext context) {
+ String renderKitId = null;
+ UIViewRoot viewRoot = context.getViewRoot();
+ if (null != viewRoot) {
+ renderKitId = viewRoot.getRenderKitId();
+ }
+ if (null == renderKitId) {
+ renderKitId = context.getApplication().getViewHandler()
+ .calculateRenderKitId(context);
+ }
+ return getRenderKit(context, renderKitId);
+ }
+
+ protected RenderKit getRenderKit(FacesContext context, String renderKitId) {
+ RenderKit renderKit = context.getRenderKit();
+ if (null == renderKit) {
+ RenderKitFactory factory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ renderKit = factory.getRenderKit(context, renderKitId);
+ }
+ return renderKit;
+ }
+
+}
Copied: branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/ComponentsLoader.java (from rev 16112, branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoader.java)
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/ComponentsLoader.java (rev 0)
+++ branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/ComponentsLoader.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -0,0 +1,29 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.ajax4jsf.application;
+
+import javax.faces.component.UIComponent;
+
+public interface ComponentsLoader {
+
+ public abstract UIComponent createComponent(String type);
+
+}
\ No newline at end of file
Copied: branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/ComponentsLoaderImpl.java (from rev 16112, branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/ComponentsLoaderImpl.java)
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/ComponentsLoaderImpl.java (rev 0)
+++ branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/ComponentsLoaderImpl.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -0,0 +1,83 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.ajax4jsf.application;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ComponentsLoaderImpl implements ComponentsLoader {
+
+ private Map<String, Class<? extends UIComponent>> classes;
+
+ private ClassLoader loader;
+
+ public ComponentsLoaderImpl() {
+ classes = new ConcurrentHashMap<String, Class<? extends UIComponent>>(
+ 64);
+ loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null) {
+ loader = ComponentsLoaderImpl.class.getClassLoader();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.portlet.application.ComponentsLoader#createComponent(java
+ * .lang.String)
+ */
+ public UIComponent createComponent(String type) {
+ // Classes is a lazy Map, new object will be create on the fly.
+ Class<? extends UIComponent> componentClass = classes.get(type);
+ if(null == componentClass){
+ try {
+ componentClass = loader.loadClass(type).asSubclass(UIComponent.class);
+ classes.put(type, componentClass);
+ } catch (ClassNotFoundException e) {
+ throw new FacesException("Can't load class " + type, e);
+ }
+
+ }
+ try {
+ return componentClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new FacesException(
+ "Error on create new instance of the component with class "
+ + type, e);
+ } catch (IllegalAccessException e) {
+ throw new FacesException(
+ "IllegalAccess on attempt to create new instance of the component with class "
+ + type, e);
+ }
+ }
+
+ ClassLoader getClassLoader() {
+ return loader;
+ }
+}
Copied: branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/TreeStructureNode.java (from rev 16112, branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/application/TreeStructureNode.java)
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/TreeStructureNode.java (rev 0)
+++ branches/community/3.3.X/framework/impl/src/main/java-jsf12/org/ajax4jsf/application/TreeStructureNode.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -0,0 +1,264 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.ajax4jsf.application;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author asmirnov
+ *
+ */
+final class TreeStructureNode implements Externalizable {
+ /**
+ * TODO - implement Externalizable to reduce serialized state.
+ */
+ private static final long serialVersionUID = -9038742487716977912L;
+
+ private static final String NULL_ID = "";
+
+ private List<FacetEntry> facets = null;
+
+ private List<TreeStructureNode> children = null;
+
+ private String type;
+
+ private String id;
+
+ public TreeStructureNode() {
+ }
+
+ public void apply(FacesContext context, UIComponent component,
+ Set<String> uniqueIds) {
+ type = component.getClass().getName();
+ id = component.getId();
+ String clientId = component.getClientId(context);
+ if (!uniqueIds.add(clientId)) {
+ throw new IllegalStateException("duplicate Id for a component "
+ + clientId);
+ }
+ Map<String, UIComponent> componentFacets = component.getFacets();
+ for (Iterator<Entry<String, UIComponent>> i = componentFacets
+ .entrySet().iterator(); i.hasNext();) {
+ Entry<String, UIComponent> element = i.next();
+ UIComponent f = element.getValue();
+ if (!f.isTransient()) {
+ TreeStructureNode facet = new TreeStructureNode();
+ facet.apply(context, f, uniqueIds);
+ if (null == facets) {
+ facets = new ArrayList<FacetEntry>(componentFacets.size());
+ }
+ facets.add(new FacetEntry(element.getKey(), facet));
+
+ }
+ }
+ List<UIComponent> componentChildren = component.getChildren();
+ for (Iterator<UIComponent> i = componentChildren.iterator(); i
+ .hasNext();) {
+ UIComponent child = i.next();
+ if (!child.isTransient()) {
+ TreeStructureNode t = new TreeStructureNode();
+ t.apply(context, child, uniqueIds);
+ if (null == children) {
+ children = new ArrayList<TreeStructureNode>(
+ componentChildren.size());
+ }
+ children.add(t);
+
+ }
+ }
+ }
+
+ public UIComponent restore(ComponentsLoader loader) {
+ UIComponent component;
+ component = loader.createComponent(type);
+ component.setId(id);
+ if (null != facets) {
+ for (Iterator<FacetEntry> i = facets.iterator(); i.hasNext();) {
+ FacetEntry element = i.next();
+ UIComponent facet = (element.getNode()).restore(loader);
+ component.getFacets().put(element.getName(), facet);
+ }
+
+ }
+ if (null != children) {
+ for (Iterator<TreeStructureNode> i = children.iterator(); i
+ .hasNext();) {
+ TreeStructureNode node = i.next();
+ UIComponent child = node.restore(loader);
+ component.getChildren().add(child);
+ }
+
+ }
+ return component;
+ }
+
+ /**
+ * @return the facets
+ */
+ public List<FacetEntry> getFacets() {
+ return facets;
+ }
+
+
+ /**
+ * @return the children
+ */
+ public List<TreeStructureNode> getChildren() {
+ return children;
+ }
+
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @param type
+ * the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @param id
+ * the id to set
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ type = in.readUTF();
+ id = in.readUTF();
+ if (NULL_ID.equals(id)) {
+ id = null;
+ }
+ int facetsSize = in.readInt();
+ if (facetsSize > 0) {
+ facets = new ArrayList<FacetEntry>(facetsSize);
+ for (int i = 0; i < facetsSize; i++) {
+ String facetName = in.readUTF();
+ TreeStructureNode facet = new TreeStructureNode();
+ facet.readExternal(in);
+ facets.add(new FacetEntry(facetName, facet));
+ }
+ }
+ int childrenSize = in.readInt();
+ if (childrenSize > 0) {
+ children = new ArrayList<TreeStructureNode>(childrenSize);
+ for (int i = 0; i < childrenSize; i++) {
+ TreeStructureNode child = new TreeStructureNode();
+ child.readExternal(in);
+ children.add(child);
+ }
+ }
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeUTF(type);
+ out.writeUTF(null == id ? NULL_ID : id);
+ if (null != facets) {
+ out.writeInt(facets.size());
+ for (Iterator<FacetEntry> i = facets.iterator(); i.hasNext();) {
+ FacetEntry entry = i.next();
+ out.writeUTF(entry.getName());
+ TreeStructureNode node = entry.getNode();
+ node.writeExternal(out);
+ }
+
+ } else {
+ out.writeInt(0);
+ }
+ if (null != children) {
+ out.writeInt(children.size());
+ for (Iterator<TreeStructureNode> i = children.iterator(); i
+ .hasNext();) {
+ TreeStructureNode child = i.next();
+ child.writeExternal(out);
+ }
+
+ } else {
+ out.writeInt(0);
+ }
+ }
+
+ @SuppressWarnings("serial")
+ static final class FacetEntry implements Externalizable {
+ private String name;
+ private TreeStructureNode node;
+
+ public String getName() {
+ return name;
+ }
+
+ public TreeStructureNode getNode() {
+ return node;
+ }
+
+ /**
+ * @param name
+ * @param node
+ */
+ public FacetEntry(String name, TreeStructureNode node) {
+ super();
+ this.name = name;
+ this.node = node;
+ }
+
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ this.name = in.readUTF();
+ this.node = new TreeStructureNode();
+ this.node.readExternal(in);
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeUTF(name);
+ node.writeExternal(out);
+ }
+ }
+}
\ No newline at end of file
Added: branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/ajax4jsf/application/AjaxStateManager.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/ajax4jsf/application/AjaxStateManager.java (rev 0)
+++ branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/ajax4jsf/application/AjaxStateManager.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.ajax4jsf.application;
+
+import java.io.IOException;
+
+import javax.faces.application.StateManager;
+import javax.faces.application.StateManagerWrapper;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.context.PartialViewContextImpl;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class AjaxStateManager extends StateManagerWrapper {
+
+ private StateManager parent;
+
+ public static final int DEFAULT_NUMBER_OF_VIEWS = 16;
+
+ public AjaxStateManager(StateManager parent) {
+ super();
+ this.parent = parent;
+ }
+
+ @Override
+ public StateManager getWrapped() {
+ return parent;
+ }
+
+ @Override
+ public void writeState(FacesContext context, Object state)
+ throws IOException {
+ try {
+ PartialViewContextImpl.setupPartialViewContextIndicator(context);
+ super.writeState(context, state);
+ } finally {
+ PartialViewContextImpl.resetPartialViewContextIndicator(context);
+ }
+ }
+
+ @Override
+ public void writeState(FacesContext context, SerializedView state)
+ throws IOException {
+ try {
+ PartialViewContextImpl.setupPartialViewContextIndicator(context);
+ super.writeState(context, state);
+ } finally {
+ PartialViewContextImpl.resetPartialViewContextIndicator(context);
+ }
+ }
+}
Added: branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/richfaces/context/PartialViewContextFactoryImpl.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/richfaces/context/PartialViewContextFactoryImpl.java (rev 0)
+++ branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/richfaces/context/PartialViewContextFactoryImpl.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.context;
+
+import javax.faces.context.FacesContext;
+import javax.faces.context.PartialViewContext;
+import javax.faces.context.PartialViewContextFactory;
+
+import org.ajax4jsf.context.AjaxContext;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class PartialViewContextFactoryImpl extends PartialViewContextFactory {
+
+ private PartialViewContextFactory defaultFactory;
+
+ public PartialViewContextFactoryImpl(PartialViewContextFactory defaultFactory) {
+ this.defaultFactory = defaultFactory;
+ }
+
+ @Override
+ public PartialViewContext getPartialViewContext(FacesContext facesContext) {
+ PartialViewContext partialViewContext = this.defaultFactory.getPartialViewContext(facesContext);
+
+ boolean isAjaxRequest = AjaxContext.getCurrentInstance(facesContext).isAjaxRequest(facesContext);
+ if (isAjaxRequest) {
+ partialViewContext = new PartialViewContextImpl(partialViewContext, facesContext);
+ }
+
+ return partialViewContext;
+ }
+
+
+}
Added: branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/richfaces/context/PartialViewContextImpl.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/richfaces/context/PartialViewContextImpl.java (rev 0)
+++ branches/community/3.3.X/framework/impl/src/main/java-jsf20/org/richfaces/context/PartialViewContextImpl.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.context;
+
+import javax.faces.context.FacesContext;
+import javax.faces.context.PartialViewContext;
+import javax.faces.context.PartialViewContextWrapper;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class PartialViewContextImpl extends PartialViewContextWrapper {
+
+ private static final String PARTIAL_REQUEST_INDICATOR_ATTTRIBUTE_NAME = PartialViewContextImpl.class.getName();
+
+ private PartialViewContext partialViewContext;
+
+ private FacesContext facesContext;
+
+ public PartialViewContextImpl(PartialViewContext partialViewContext, FacesContext facesContext) {
+ this.partialViewContext = partialViewContext;
+ this.facesContext = facesContext;
+ }
+
+ /* Hack for Sun RI implementation of StateManager/ResponseStateManager */
+ private static Object getPartialViewContextIndicator(FacesContext facesContext) {
+ return facesContext.getAttributes().get(PARTIAL_REQUEST_INDICATOR_ATTTRIBUTE_NAME);
+ }
+
+ private static void setPartialViewContextIndicator(FacesContext facesContext, Object value) {
+ facesContext.getAttributes().put(PARTIAL_REQUEST_INDICATOR_ATTTRIBUTE_NAME, value);
+ }
+
+ /**
+ * Hack for Sun RI implementation of StateManager/ResponseStateManager
+ * @param facesContext
+ */
+ public static void setupPartialViewContextIndicator(FacesContext facesContext) {
+ setPartialViewContextIndicator(facesContext, Boolean.TRUE);
+ }
+
+ /**
+ * Hack for Sun RI implementation of StateManager/ResponseStateManager
+ * @param facesContext
+ */
+ public static void resetPartialViewContextIndicator(FacesContext facesContext) {
+ setPartialViewContextIndicator(facesContext, null);
+ }
+ /* End hack */
+
+
+ @Override
+ public PartialViewContext getWrapped() {
+ return partialViewContext;
+ }
+
+ @Override
+ public boolean isPartialRequest() {
+ if (partialViewContext.isPartialRequest()) {
+ return true;
+ }
+
+ /* Hack for Sun RI implementation of StateManager/ResponseStateManager */
+ return Boolean.TRUE.equals(getPartialViewContextIndicator(facesContext));
+ }
+
+ @Override
+ public void setPartialRequest(boolean isPartialRequest) {
+ partialViewContext.setPartialRequest(isPartialRequest);
+ }
+}
Added: branches/community/3.3.X/framework/impl/src/main/resources-jsf20/META-INF/ajax-context.faces-config.xml
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/resources-jsf20/META-INF/ajax-context.faces-config.xml (rev 0)
+++ branches/community/3.3.X/framework/impl/src/main/resources-jsf20/META-INF/ajax-context.faces-config.xml 2009-12-15 17:57:25 UTC (rev 16140)
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
+ version="2.0">
+
+ <factory>
+ <partial-view-context-factory>org.richfaces.context.PartialViewContextFactoryImpl</partial-view-context-factory>
+ </factory>
+
+</faces-config>
\ No newline at end of file
Modified: branches/community/3.3.X/framework/test/pom.xml
===================================================================
--- branches/community/3.3.X/framework/test/pom.xml 2009-12-15 16:57:51 UTC (rev 16139)
+++ branches/community/3.3.X/framework/test/pom.xml 2009-12-15 17:57:25 UTC (rev 16140)
@@ -23,6 +23,9 @@
<scope>provided</scope>
</dependency>
</dependencies>
+ <properties>
+ <additionalTestFolder>src/test/java-jsf20</additionalTestFolder>
+ </properties>
</profile>
<profile>
<id>jsf1_2</id>
@@ -37,6 +40,9 @@
<activation>
<activeByDefault>true</activeByDefault>
</activation>
+ <properties>
+ <additionalTestFolder>src/test/java-jsf12</additionalTestFolder>
+ </properties>
</profile>
</profiles>
@@ -122,6 +128,25 @@
</excludes>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.4</version>
+ <executions>
+ <execution>
+ <id>add-test-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${additionalTestFolder}</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
Deleted: branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateHolderTest.java
===================================================================
--- branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateHolderTest.java 2009-12-15 16:57:51 UTC (rev 16139)
+++ branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateHolderTest.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -1,85 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.ajax4jsf.application;
-
-import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-
-/**
- * @author asmirnov
- *
- */
-public class AjaxStateHolderTest extends AbstractAjax4JsfTestCase {
-
- /**
- * @param name
- */
- public AjaxStateHolderTest(String name) {
- super(name);
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
- */
- public void setUp() throws Exception {
- super.setUp();
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
- */
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * Test method for {@link org.ajax4jsf.application.AjaxStateHolder#getInstance(javax.faces.context.FacesContext)}.
- */
- public void testGetInstance() {
- StateHolder ajaxStateHolder = AjaxStateHolder.getInstance(facesContext);
- assertNotNull(ajaxStateHolder);
- StateHolder ajaxStateHolder2 = AjaxStateHolder.getInstance(facesContext);
- assertSame(ajaxStateHolder, ajaxStateHolder2);
- }
-
- /**
- * Test method for {@link org.ajax4jsf.application.AjaxStateHolder#getState(java.lang.String, String)}.
- */
- public void testGetState() {
- Object state = new Object();
- Object state2 = new Object();
- StateHolder ajaxStateHolder = AjaxStateHolder.getInstance(facesContext);
- assertNull(ajaxStateHolder.getState(facesContext, "foo", "_id1"));
- ajaxStateHolder.saveState(facesContext, "foo", "_id1", new Object[]{state});
- ajaxStateHolder.saveState(facesContext, "foo", "_id2", new Object[]{state2});
- assertNull(ajaxStateHolder.getState(facesContext, "bar", "_id1"));
- assertSame(state2,ajaxStateHolder.getState(facesContext, "foo",null));
- assertSame(state,ajaxStateHolder.getState(facesContext, "foo","_id1"));
- assertSame(state,ajaxStateHolder.getState(facesContext, "foo","_id3"));
- Object state3 = new Object();
- Object state4 = new Object();
- ajaxStateHolder.saveState(facesContext, "bar", "_id1", new Object[]{state3});
- ajaxStateHolder.saveState(facesContext, "bar", "_id2", new Object[]{state4});
- assertSame(state3,ajaxStateHolder.getState(facesContext, "bar","_id1"));
- assertSame(state,ajaxStateHolder.getState(facesContext, "foo","_id3"));
- }
-
-
-}
Deleted: branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateManagerTest.java
===================================================================
--- branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateManagerTest.java 2009-12-15 16:57:51 UTC (rev 16139)
+++ branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateManagerTest.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -1,219 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.ajax4jsf.application;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.HashSet;
-
-import javax.faces.FactoryFinder;
-import javax.faces.application.StateManager;
-import javax.faces.application.ViewHandler;
-import javax.faces.application.StateManager.SerializedView;
-import javax.faces.component.UIColumn;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIData;
-import javax.faces.component.UIInput;
-import javax.faces.component.UIOutput;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-import javax.faces.render.RenderKit;
-import javax.faces.render.RenderKitFactory;
-import javax.faces.render.ResponseStateManager;
-
-import org.ajax4jsf.application.TreeStructureNode.FacetEntry;
-import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
-import org.apache.shale.test.mock.MockRenderKit;
-
-
-/**
- * @author asmirnov
- *
- */
-public class AjaxStateManagerTest extends AbstractAjax4JsfTestCase {
-
- private static final String FACET_B = "facetB";
- private static final String FACET_A = "facetA";
- private static final String AJAX_RENDER_KIT = "AJAX";
- private AjaxStateManager ajaxStateManager;
-
- private Object treeStructure;
-
- private Object state;
- /**
- * @param name
- */
- public AjaxStateManagerTest(String name) {
- super(name);
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
- */
- public void setUp() throws Exception {
- super.setUp();
- RenderKitFactory renderKitFactory = (RenderKitFactory)
- FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
- renderKit = new MockRenderKit(){
- public ResponseStateManager getResponseStateManager() {
- return new ResponseStateManager(){
-
- public Object getComponentStateToRestore(FacesContext arg0) {
- return state;
- }
-
- public Object getTreeStructureToRestore(FacesContext arg0,
- String arg1) {
- return treeStructure;
- }
-
- public void writeState(FacesContext context,
- SerializedView serializedView) throws IOException {
- treeStructure = serializedView.getStructure();
- state = serializedView.getState();
- }
-
- };
- }
- };
- renderKitFactory.addRenderKit(AJAX_RENDER_KIT, renderKit);
- facesContext.getViewRoot().setRenderKitId(AJAX_RENDER_KIT);
- ajaxStateManager = new AjaxStateManager(application.getStateManager());
- application.setStateManager(ajaxStateManager);
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
- */
- public void tearDown() throws Exception {
- super.tearDown();
- ajaxStateManager = null;
- treeStructure = null;
- state = null;
- }
-
- /**
- * Test method for {@link org.ajax4jsf.application.AjaxStateManager#restoreStateFromSession(javax.faces.context.FacesContext, java.lang.String, java.lang.String)}.
- */
- public void testRestoreStateFromSession() {
- Object structure = new Object();
- Object treeState = new Object();
- ajaxStateManager.saveStateInSession(facesContext, structure, treeState);
- treeStructure = UIViewRoot.UNIQUE_ID_PREFIX+"1";
- Object[] stateFromSession = ajaxStateManager.restoreStateFromSession(facesContext, facesContext.getViewRoot().getViewId(), AJAX_RENDER_KIT);
- assertSame(structure, stateFromSession[0]);
- assertSame(treeState, stateFromSession[1]);
- }
-
- /**
- * Test method for {@link org.ajax4jsf.application.AjaxStateManager#getLogicalViewId(javax.faces.context.FacesContext)}.
- */
- public void testGetNextViewId() {
- Object nextViewId = ajaxStateManager.getLogicalViewId(facesContext);
- Object expected = ajaxStateManager.getLogicalViewId(facesContext);
- assertTrue(expected.equals(nextViewId));
- ajaxContext.setAjaxRequest(true);
- request.setAttribute(AjaxStateManager.AJAX_VIEW_SEQUENCE, expected);
- nextViewId = ajaxStateManager.getLogicalViewId(facesContext);
- assertEquals(expected, nextViewId);
- }
-
-
- /**
- * Test method for {@link org.ajax4jsf.application.AjaxStateManager#getRenderKit(javax.faces.context.FacesContext, java.lang.String)}.
- */
- public void testGetRenderKit() {
- AjaxStateManager stateManager = getAjaxStateManager();
- RenderKit kit = stateManager.getRenderKit(facesContext, AJAX_RENDER_KIT);
- assertSame(renderKit, kit);
- }
-
- public void testTreeNodeApply() throws Exception {
- buildTestTree();
- TreeStructureNode node = new TreeStructureNode();
- node.apply(facesContext, facesContext.getViewRoot(), new HashSet<String>());
- assertEquals(2, node.getChildren().size());
- assertEquals(1, node.getFacets().size());
- FacetEntry nodeA = node.getFacets().get(0);
- assertNotNull(nodeA);
- assertEquals(FACET_A, nodeA.getName());
- assertEquals(1, nodeA.getNode().getChildren().size());
- assertEquals(1, nodeA.getNode().getFacets().size());
-
- }
-
- public void testTreeNodeCheckUniqueId() throws Exception {
- buildTestTree();
- TreeStructureNode node = new TreeStructureNode();
- UIViewRoot viewRoot = facesContext.getViewRoot();
- ((UIComponent)viewRoot.getChildren().get(0)).setId(FACET_A);
- ((UIComponent)viewRoot.getChildren().get(1)).setId(FACET_A);
- try {
- node.apply(facesContext, facesContext.getViewRoot(), new HashSet());
- } catch (IllegalStateException e) {
- assertTrue(e.getMessage().startsWith("duplicate"));
- return;
- }
- assertTrue("Duplicate components Id's not detected ",false);
- }
-
-
- public void testTreeNodeSerialisation() throws Exception {
- buildTestTree();
- TreeStructureNode node = new TreeStructureNode();
- node.apply(facesContext, facesContext.getViewRoot(), new HashSet());
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(byteOut);
- out.writeObject(node);
- ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
- ObjectInputStream in = new ObjectInputStream(byteIn);
- TreeStructureNode nodeIn = (TreeStructureNode) in.readObject();
- assertEquals(2, nodeIn.getChildren().size());
- assertEquals(1, nodeIn.getFacets().size());
- FacetEntry nodeA = nodeIn.getFacets().get(0);
- assertNotNull(nodeA);
- assertEquals(FACET_A, nodeA.getName());
- assertEquals(1, nodeA.getNode().getChildren().size());
- assertEquals(1, nodeA.getNode().getFacets().size());
- }
- /**
- *
- */
- private void buildTestTree() {
- facesContext.getViewRoot().getChildren().add(new UIInput());
- facesContext.getViewRoot().getChildren().add(new UIOutput());
- UIData data = new UIData();
- facesContext.getViewRoot().getFacets().put(FACET_A, data);
- data.getChildren().add(new UIColumn());
- data.getFacets().put(FACET_B, new UIOutput());
- }
-
- /**
- * @return
- */
- private AjaxStateManager getAjaxStateManager() {
- return ajaxStateManager;
- }
-
-}
Deleted: branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/ComponentLoaderTest.java
===================================================================
--- branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/ComponentLoaderTest.java 2009-12-15 16:57:51 UTC (rev 16139)
+++ branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/ComponentLoaderTest.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -1,76 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-package org.ajax4jsf.application;
-
-import java.net.URL;
-import java.net.URLClassLoader;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIInput;
-
-import junit.framework.TestCase;
-
-/**
- * @author asmirnov
- *
- */
-public class ComponentLoaderTest extends TestCase {
-
- private ComponentsLoaderImpl loader;
- private ClassLoader contextClassLoader;
- private URLClassLoader classLoader;
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- contextClassLoader = Thread.currentThread().getContextClassLoader();
- classLoader = new URLClassLoader(new URL[0],
- this.getClass().getClassLoader());
- Thread.currentThread().setContextClassLoader(classLoader);
- loader = new ComponentsLoaderImpl();
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- loader = null;
- Thread.currentThread().setContextClassLoader(contextClassLoader);
- contextClassLoader = null;
- }
-
- /**
- * Test method for {@link org.ajax4jsf.application.ComponentsLoaderImpl#createComponent(java.lang.String)}.
- */
- public void testCreateComponent() {
- UIComponent input = loader.createComponent(UIInput.class.getName());
- assertNotNull(input);
- assertEquals(UIInput.class, input.getClass());
- }
-
-
- public void testGetLoader() throws Exception {
- assertSame(classLoader,loader.getClassLoader());
- }
-}
Copied: branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/AjaxStateHolderTest.java (from rev 16112, branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateHolderTest.java)
===================================================================
--- branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/AjaxStateHolderTest.java (rev 0)
+++ branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/AjaxStateHolderTest.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -0,0 +1,85 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.ajax4jsf.application;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class AjaxStateHolderTest extends AbstractAjax4JsfTestCase {
+
+ /**
+ * @param name
+ */
+ public AjaxStateHolderTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.application.AjaxStateHolder#getInstance(javax.faces.context.FacesContext)}.
+ */
+ public void testGetInstance() {
+ StateHolder ajaxStateHolder = AjaxStateHolder.getInstance(facesContext);
+ assertNotNull(ajaxStateHolder);
+ StateHolder ajaxStateHolder2 = AjaxStateHolder.getInstance(facesContext);
+ assertSame(ajaxStateHolder, ajaxStateHolder2);
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.application.AjaxStateHolder#getState(java.lang.String, String)}.
+ */
+ public void testGetState() {
+ Object state = new Object();
+ Object state2 = new Object();
+ StateHolder ajaxStateHolder = AjaxStateHolder.getInstance(facesContext);
+ assertNull(ajaxStateHolder.getState(facesContext, "foo", "_id1"));
+ ajaxStateHolder.saveState(facesContext, "foo", "_id1", new Object[]{state});
+ ajaxStateHolder.saveState(facesContext, "foo", "_id2", new Object[]{state2});
+ assertNull(ajaxStateHolder.getState(facesContext, "bar", "_id1"));
+ assertSame(state2,ajaxStateHolder.getState(facesContext, "foo",null));
+ assertSame(state,ajaxStateHolder.getState(facesContext, "foo","_id1"));
+ assertSame(state,ajaxStateHolder.getState(facesContext, "foo","_id3"));
+ Object state3 = new Object();
+ Object state4 = new Object();
+ ajaxStateHolder.saveState(facesContext, "bar", "_id1", new Object[]{state3});
+ ajaxStateHolder.saveState(facesContext, "bar", "_id2", new Object[]{state4});
+ assertSame(state3,ajaxStateHolder.getState(facesContext, "bar","_id1"));
+ assertSame(state,ajaxStateHolder.getState(facesContext, "foo","_id3"));
+ }
+
+
+}
Copied: branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/AjaxStateManagerTest.java (from rev 16112, branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/AjaxStateManagerTest.java)
===================================================================
--- branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/AjaxStateManagerTest.java (rev 0)
+++ branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/AjaxStateManagerTest.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -0,0 +1,219 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.ajax4jsf.application;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.HashSet;
+
+import javax.faces.FactoryFinder;
+import javax.faces.application.StateManager;
+import javax.faces.application.ViewHandler;
+import javax.faces.application.StateManager.SerializedView;
+import javax.faces.component.UIColumn;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIData;
+import javax.faces.component.UIInput;
+import javax.faces.component.UIOutput;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+import javax.faces.render.ResponseStateManager;
+
+import org.ajax4jsf.application.TreeStructureNode.FacetEntry;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.apache.shale.test.mock.MockRenderKit;
+
+
+/**
+ * @author asmirnov
+ *
+ */
+public class AjaxStateManagerTest extends AbstractAjax4JsfTestCase {
+
+ private static final String FACET_B = "facetB";
+ private static final String FACET_A = "facetA";
+ private static final String AJAX_RENDER_KIT = "AJAX";
+ private AjaxStateManager ajaxStateManager;
+
+ private Object treeStructure;
+
+ private Object state;
+ /**
+ * @param name
+ */
+ public AjaxStateManagerTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp()
+ */
+ public void setUp() throws Exception {
+ super.setUp();
+ RenderKitFactory renderKitFactory = (RenderKitFactory)
+ FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ renderKit = new MockRenderKit(){
+ public ResponseStateManager getResponseStateManager() {
+ return new ResponseStateManager(){
+
+ public Object getComponentStateToRestore(FacesContext arg0) {
+ return state;
+ }
+
+ public Object getTreeStructureToRestore(FacesContext arg0,
+ String arg1) {
+ return treeStructure;
+ }
+
+ public void writeState(FacesContext context,
+ SerializedView serializedView) throws IOException {
+ treeStructure = serializedView.getStructure();
+ state = serializedView.getState();
+ }
+
+ };
+ }
+ };
+ renderKitFactory.addRenderKit(AJAX_RENDER_KIT, renderKit);
+ facesContext.getViewRoot().setRenderKitId(AJAX_RENDER_KIT);
+ ajaxStateManager = new AjaxStateManager(application.getStateManager());
+ application.setStateManager(ajaxStateManager);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ ajaxStateManager = null;
+ treeStructure = null;
+ state = null;
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.application.AjaxStateManager#restoreStateFromSession(javax.faces.context.FacesContext, java.lang.String, java.lang.String)}.
+ */
+ public void testRestoreStateFromSession() {
+ Object structure = new Object();
+ Object treeState = new Object();
+ ajaxStateManager.saveStateInSession(facesContext, structure, treeState);
+ treeStructure = UIViewRoot.UNIQUE_ID_PREFIX+"1";
+ Object[] stateFromSession = ajaxStateManager.restoreStateFromSession(facesContext, facesContext.getViewRoot().getViewId(), AJAX_RENDER_KIT);
+ assertSame(structure, stateFromSession[0]);
+ assertSame(treeState, stateFromSession[1]);
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.application.AjaxStateManager#getLogicalViewId(javax.faces.context.FacesContext)}.
+ */
+ public void testGetNextViewId() {
+ Object nextViewId = ajaxStateManager.getLogicalViewId(facesContext);
+ Object expected = ajaxStateManager.getLogicalViewId(facesContext);
+ assertTrue(expected.equals(nextViewId));
+ ajaxContext.setAjaxRequest(true);
+ request.setAttribute(AjaxStateManager.AJAX_VIEW_SEQUENCE, expected);
+ nextViewId = ajaxStateManager.getLogicalViewId(facesContext);
+ assertEquals(expected, nextViewId);
+ }
+
+
+ /**
+ * Test method for {@link org.ajax4jsf.application.AjaxStateManager#getRenderKit(javax.faces.context.FacesContext, java.lang.String)}.
+ */
+ public void testGetRenderKit() {
+ AjaxStateManager stateManager = getAjaxStateManager();
+ RenderKit kit = stateManager.getRenderKit(facesContext, AJAX_RENDER_KIT);
+ assertSame(renderKit, kit);
+ }
+
+ public void testTreeNodeApply() throws Exception {
+ buildTestTree();
+ TreeStructureNode node = new TreeStructureNode();
+ node.apply(facesContext, facesContext.getViewRoot(), new HashSet<String>());
+ assertEquals(2, node.getChildren().size());
+ assertEquals(1, node.getFacets().size());
+ FacetEntry nodeA = node.getFacets().get(0);
+ assertNotNull(nodeA);
+ assertEquals(FACET_A, nodeA.getName());
+ assertEquals(1, nodeA.getNode().getChildren().size());
+ assertEquals(1, nodeA.getNode().getFacets().size());
+
+ }
+
+ public void testTreeNodeCheckUniqueId() throws Exception {
+ buildTestTree();
+ TreeStructureNode node = new TreeStructureNode();
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+ ((UIComponent)viewRoot.getChildren().get(0)).setId(FACET_A);
+ ((UIComponent)viewRoot.getChildren().get(1)).setId(FACET_A);
+ try {
+ node.apply(facesContext, facesContext.getViewRoot(), new HashSet());
+ } catch (IllegalStateException e) {
+ assertTrue(e.getMessage().startsWith("duplicate"));
+ return;
+ }
+ assertTrue("Duplicate components Id's not detected ",false);
+ }
+
+
+ public void testTreeNodeSerialisation() throws Exception {
+ buildTestTree();
+ TreeStructureNode node = new TreeStructureNode();
+ node.apply(facesContext, facesContext.getViewRoot(), new HashSet());
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(byteOut);
+ out.writeObject(node);
+ ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
+ ObjectInputStream in = new ObjectInputStream(byteIn);
+ TreeStructureNode nodeIn = (TreeStructureNode) in.readObject();
+ assertEquals(2, nodeIn.getChildren().size());
+ assertEquals(1, nodeIn.getFacets().size());
+ FacetEntry nodeA = nodeIn.getFacets().get(0);
+ assertNotNull(nodeA);
+ assertEquals(FACET_A, nodeA.getName());
+ assertEquals(1, nodeA.getNode().getChildren().size());
+ assertEquals(1, nodeA.getNode().getFacets().size());
+ }
+ /**
+ *
+ */
+ private void buildTestTree() {
+ facesContext.getViewRoot().getChildren().add(new UIInput());
+ facesContext.getViewRoot().getChildren().add(new UIOutput());
+ UIData data = new UIData();
+ facesContext.getViewRoot().getFacets().put(FACET_A, data);
+ data.getChildren().add(new UIColumn());
+ data.getFacets().put(FACET_B, new UIOutput());
+ }
+
+ /**
+ * @return
+ */
+ private AjaxStateManager getAjaxStateManager() {
+ return ajaxStateManager;
+ }
+
+}
Copied: branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/ComponentLoaderTest.java (from rev 16112, branches/community/3.3.X/framework/test/src/test/java/org/ajax4jsf/application/ComponentLoaderTest.java)
===================================================================
--- branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/ComponentLoaderTest.java (rev 0)
+++ branches/community/3.3.X/framework/test/src/test/java-jsf12/org/ajax4jsf/application/ComponentLoaderTest.java 2009-12-15 17:57:25 UTC (rev 16140)
@@ -0,0 +1,76 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+package org.ajax4jsf.application;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+
+import junit.framework.TestCase;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ComponentLoaderTest extends TestCase {
+
+ private ComponentsLoaderImpl loader;
+ private ClassLoader contextClassLoader;
+ private URLClassLoader classLoader;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ contextClassLoader = Thread.currentThread().getContextClassLoader();
+ classLoader = new URLClassLoader(new URL[0],
+ this.getClass().getClassLoader());
+ Thread.currentThread().setContextClassLoader(classLoader);
+ loader = new ComponentsLoaderImpl();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ loader = null;
+ Thread.currentThread().setContextClassLoader(contextClassLoader);
+ contextClassLoader = null;
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.application.ComponentsLoaderImpl#createComponent(java.lang.String)}.
+ */
+ public void testCreateComponent() {
+ UIComponent input = loader.createComponent(UIInput.class.getName());
+ assertNotNull(input);
+ assertEquals(UIInput.class, input.getClass());
+ }
+
+
+ public void testGetLoader() throws Exception {
+ assertSame(classLoader,loader.getClassLoader());
+ }
+}
14 years, 5 months
JBoss Rich Faces SVN: r16139 - branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2009-12-15 11:57:51 -0500 (Tue, 15 Dec 2009)
New Revision: 16139
Modified:
branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator/ObjectValidator.java
Log:
Fix RF-8149
Modified: branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator/ObjectValidator.java
===================================================================
--- branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator/ObjectValidator.java 2009-12-15 16:30:56 UTC (rev 16138)
+++ branches/community/3.3.X/ui/beanValidator/src/main/java/org/richfaces/validator/ObjectValidator.java 2009-12-15 16:57:51 UTC (rev 16139)
@@ -49,18 +49,20 @@
// TODO - get instance class name from a "META-INF/service"
// If the Seam framework is active, org.jboss.seam.core.Validators
// component should be used.
- ObjectValidator validator;
+ ObjectValidator validator = null;
try {
validator = new BeanValidator();
- } catch (Throwable e) {
- log.warn("Bean Validator could not be instantiated", e);
+ } catch (Exception e) {
try {
validator = new HibernateValidator();
} catch (Throwable e2) {
- log.warn("Hibernate Validator could not be instantiated, use stub instead", e);
- validator = new NullValidator();
+ //Hibernate-validators not available
}
}
+ if(validator == null){
+ log.warn("Validator implementations not found at classpath, default NullValidator will be used.");
+ validator = new NullValidator();
+ }
return validator;
}
14 years, 5 months
JBoss Rich Faces SVN: r16138 - branches/community/3.3.X/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2009-12-15 11:30:56 -0500 (Tue, 15 Dec 2009)
New Revision: 16138
Modified:
branches/community/3.3.X/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTableSelection.js
Log:
Fix RF-8179
Modified: branches/community/3.3.X/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTableSelection.js
===================================================================
--- branches/community/3.3.X/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTableSelection.js 2009-12-15 13:53:51 UTC (rev 16137)
+++ branches/community/3.3.X/ui/extendedDataTable/src/main/javascript/ClientUI/controls/datatable/ExtendedDataTableSelection.js 2009-12-15 16:30:56 UTC (rev 16138)
@@ -627,11 +627,16 @@
return;
}
var i = range[0];
- range[1] = (range[1] + 1) % this.rowCount;
+ if((range[1] != this.rowCount-1)&& this.rowCount > 1){
+ range[1] = (range[1] + 1) % this.rowCount;
+ }
while (i != range[1]) {
this.addRowToSelection(i);
i = (i + 1) % this.rowCount;
}
+ if((range[1] == this.rowCount-1)&& this.rowCount > 1){
+ this.addRowToSelection(this.rowCount-1);
+ }
},
resetSelection: function(e) {
14 years, 5 months
JBoss Rich Faces SVN: r16137 - branches/community/3.3.X/samples/richfaces-demo/functional-test.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2009-12-15 08:53:51 -0500 (Tue, 15 Dec 2009)
New Revision: 16137
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/profiles.jboss-qa.xml
Log:
rf-demo ftest - typo in URL of installater for AS 6.0.0.M1 (RF-8190)
Modified: branches/community/3.3.X/samples/richfaces-demo/functional-test/profiles.jboss-qa.xml
===================================================================
--- branches/community/3.3.X/samples/richfaces-demo/functional-test/profiles.jboss-qa.xml 2009-12-15 11:43:14 UTC (rev 16136)
+++ branches/community/3.3.X/samples/richfaces-demo/functional-test/profiles.jboss-qa.xml 2009-12-15 13:53:51 UTC (rev 16137)
@@ -141,7 +141,7 @@
<id>container-installation-jsf2</id>
<properties>
<jboss5x.version>6.0.0.M1</jboss5x.version>
- <jboss5x.installer.url.unix>file:/qa/home/lfryc/jboss-jsf2/jboss-5.1.0.GA.zip</jboss5x.installer.url.unix>
+ <jboss5x.installer.url.unix>file:/qa/home/lfryc/jboss-jsf2/jboss-6.0.0.M1.zip</jboss5x.installer.url.unix>
<jboss5x.installer.url.windows>file:h:\lfryc\jboss-jsf2\jboss-6.0.0.M1.zip</jboss5x.installer.url.windows>
</properties>
</profile>
14 years, 5 months
JBoss Rich Faces SVN: r16136 - branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2009-12-15 06:43:14 -0500 (Tue, 15 Dec 2009)
New Revision: 16136
Modified:
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/RichfacesSelenium.java
Log:
* GENERAL
- refactored RichfacesSelenium to be straightway
- added toString to AjaxCommand to print out commandName and args when failure
Modified: branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/RichfacesSelenium.java
===================================================================
--- branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/RichfacesSelenium.java 2009-12-15 11:16:00 UTC (rev 16135)
+++ branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/RichfacesSelenium.java 2009-12-15 11:43:14 UTC (rev 16136)
@@ -2,6 +2,7 @@
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.jboss.test.selenium.waiting.Retrieve;
import org.jboss.test.selenium.waiting.Wait;
@@ -28,7 +29,7 @@
super(serverHost, serverPort, browserStartCommand, browserURL);
}
- private abstract class Command<T> {
+ private abstract class AjaxCommand<T> {
public abstract T command();
}
@@ -36,31 +37,32 @@
"ERROR: Threw an exception: Error executing strategy function jquery: Permission denied",
"ERROR: Threw an exception: Permission denied",
"ERROR: Threw an exception: Object doesn't support this property or method",
- "ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window. The error message is: Permission denied"};
+ "ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window. The error message is: Permission denied" };
- private <T> T doAjax(final Command<T> command) {
+ private <T> T doAjax(final AjaxCommand<T> ajaxCommand) {
final AssertionError fail = new AssertionError("Fails with Permission denied when trying to execute jQuery");
-
+
final T start = null;
return Wait.timeout(Wait.DEFAULT_TIMEOUT).interval(1000).failWith(fail).waitForChangeAndReturn(start,
new Retrieve<T>() {
boolean exceptionLogged = false;
-
+
public T retrieve() {
try {
- return command.command();
+ return ajaxCommand.command();
} catch (SeleniumException e) {
final String message = StringUtils.defaultString(e.getMessage());
if (ArrayUtils.contains(PERMISSION_DENIED, message)) {
+ System.err.println(message);
if (!exceptionLogged) {
exceptionLogged = true;
+ System.err.println(ajaxCommand);
e.printStackTrace();
} else {
- System.err.println(message);
}
return null;
}
-
+
throw e;
}
}
@@ -69,11 +71,16 @@
@Override
public String doCommand(final String commandName, final String[] args) {
- return doAjax(new Command<String>() {
+ return doAjax(new AjaxCommand<String>() {
@Override
public String command() {
return RichfacesCommandProcessor.super.doCommand(commandName, args);
}
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("commandName", commandName).append("args", args).toString();
+ }
});
}
}
14 years, 5 months
JBoss Rich Faces SVN: r16135 - branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2009-12-15 06:16:00 -0500 (Tue, 15 Dec 2009)
New Revision: 16135
Modified:
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/RichfacesSelenium.java
Log:
* GENERAL
- seleniumLoggingListener creation and registration moved to @BeforeSuite (object made as static), referencing selenium in @BeforeClass initializeContext and unreferencing in @AfterClass finalizeContext
- added logic to Permission Denied treatment - first catch prints stacktrace, each other only logs exception message
Modified: branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java
===================================================================
--- branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java 2009-12-15 10:27:28 UTC (rev 16134)
+++ branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java 2009-12-15 11:16:00 UTC (rev 16135)
@@ -39,7 +39,7 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.BeforeTest;
+import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;
/**
@@ -76,33 +76,23 @@
protected Waiting waitModelUpdate = Wait.interval(100).timeout(30000);
protected Waiting waitGuiInteraction = Wait.interval(100).timeout(500);
- /**
- * Test listener used to logging to selenium's server.log
- * via getEval() method (see {@link SeleniumLoggingTestListener})
- *
- * Don't forget to use SeleniumLoggingTestListener.setSelenium(Selenium)
- * to initialize selenium-side logging properly
- */
- SeleniumLoggingTestListener loggingTestListener;
-
- /**
- * Register test listener in test context
- *
- * @param context
- * will be injected by TestNG
- */
- @BeforeTest
- protected void addTestListeners(ITestContext context) {
- TestRunner runner = (TestRunner) context;
+ /**
+ * Test listener used to logging to selenium's server.log via getEval()
+ * method (see {@link SeleniumLoggingTestListener})
+ *
+ * Don't forget to use SeleniumLoggingTestListener.setSelenium(Selenium) to
+ * initialize selenium-side logging properly
+ */
+ private static volatile SeleniumLoggingTestListener loggingTestListener;
+
+ @BeforeSuite
+ protected void registerSeleniumInListeners(ITestContext context) {
loggingTestListener = new SeleniumLoggingTestListener();
+
+ TestRunner runner = (TestRunner) context;
runner.addTestListener(loggingTestListener);
}
- @BeforeMethod
- protected void registerSeleniumInListeners() {
- loggingTestListener.setSelenium(selenium);
- }
-
/**
* Initializes context before each class run.
*
@@ -134,6 +124,7 @@
selenium.start();
allowInitialXpath();
loadCustomLocationStrategies();
+ loggingTestListener.setSelenium(selenium);
selenium.windowFocus();
selenium.windowMaximize();
@@ -168,6 +159,7 @@
*/
@AfterClass
public void finalizeContext() {
+ loggingTestListener.setSelenium(null);
selenium.close();
selenium.stop();
selenium = null;
Modified: branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/RichfacesSelenium.java
===================================================================
--- branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/RichfacesSelenium.java 2009-12-15 10:27:28 UTC (rev 16134)
+++ branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/RichfacesSelenium.java 2009-12-15 11:16:00 UTC (rev 16135)
@@ -44,14 +44,20 @@
final T start = null;
return Wait.timeout(Wait.DEFAULT_TIMEOUT).interval(1000).failWith(fail).waitForChangeAndReturn(start,
new Retrieve<T>() {
+ boolean exceptionLogged = false;
+
public T retrieve() {
try {
return command.command();
} catch (SeleniumException e) {
final String message = StringUtils.defaultString(e.getMessage());
-
if (ArrayUtils.contains(PERMISSION_DENIED, message)) {
- System.err.println(message);
+ if (!exceptionLogged) {
+ exceptionLogged = true;
+ e.printStackTrace();
+ } else {
+ System.err.println(message);
+ }
return null;
}
14 years, 5 months
JBoss Rich Faces SVN: r16134 - branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2009-12-15 05:27:28 -0500 (Tue, 15 Dec 2009)
New Revision: 16134
Modified:
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java
Log:
* GENERAL
- referencing selenium for logginTestListener in @BeforeMethod phase
Modified: branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java
===================================================================
--- branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java 2009-12-15 09:38:17 UTC (rev 16133)
+++ branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java 2009-12-15 10:27:28 UTC (rev 16134)
@@ -95,10 +95,14 @@
protected void addTestListeners(ITestContext context) {
TestRunner runner = (TestRunner) context;
loggingTestListener = new SeleniumLoggingTestListener();
- loggingTestListener.setSelenium(selenium);
runner.addTestListener(loggingTestListener);
}
+ @BeforeMethod
+ protected void registerSeleniumInListeners() {
+ loggingTestListener.setSelenium(selenium);
+ }
+
/**
* Initializes context before each class run.
*
14 years, 5 months
JBoss Rich Faces SVN: r16133 - in branches/sandbox/rf-demo-ftest-iexplore/src/test: resources/user-extensions and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2009-12-15 04:38:17 -0500 (Tue, 15 Dec 2009)
New Revision: 16133
Modified:
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java
branches/sandbox/rf-demo-ftest-iexplore/src/test/resources/user-extensions/rfqa-extensions.js
Log:
* GENERAL
- moved loggingSeleniumListener.setSelenium(selenium) from @BeforeClass to @BeforeTest
- overwritten getJQueryCount(String locator) to optimalize (uncommented JS extension)
- added selenium.windowMaximaze() and selenium.windowFocus()
Modified: branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java
===================================================================
--- branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java 2009-12-15 09:20:46 UTC (rev 16132)
+++ branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java 2009-12-15 09:38:17 UTC (rev 16133)
@@ -95,6 +95,7 @@
protected void addTestListeners(ITestContext context) {
TestRunner runner = (TestRunner) context;
loggingTestListener = new SeleniumLoggingTestListener();
+ loggingTestListener.setSelenium(selenium);
runner.addTestListener(loggingTestListener);
}
@@ -129,8 +130,9 @@
selenium.start();
allowInitialXpath();
loadCustomLocationStrategies();
- // adding selenium-side logging facility
- loggingTestListener.setSelenium(selenium);
+
+ selenium.windowFocus();
+ selenium.windowMaximize();
}
/**
@@ -354,4 +356,11 @@
private int getRunnedTestCount(ITestContext context) {
return context.getPassedTests().size() + context.getSkippedTests().size() + context.getFailedTests().size();
}
+
+ @Override
+ public int getJQueryCount(String locator) {
+ String evaluate = format("selenium.getJQueryCount(\"{0}\")", locator.replaceFirst("^jquery=", ""));
+ String result = selenium.getEval(evaluate);
+ return Integer.parseInt(result);
+ }
}
Modified: branches/sandbox/rf-demo-ftest-iexplore/src/test/resources/user-extensions/rfqa-extensions.js
===================================================================
--- branches/sandbox/rf-demo-ftest-iexplore/src/test/resources/user-extensions/rfqa-extensions.js 2009-12-15 09:20:46 UTC (rev 16132)
+++ branches/sandbox/rf-demo-ftest-iexplore/src/test/resources/user-extensions/rfqa-extensions.js 2009-12-15 09:38:17 UTC (rev 16133)
@@ -87,3 +87,9 @@
return jQuery.trim(elem.textContent || elem.innerText || "").endsWith(
match[3]);
}
+
+Selenium.prototype.getJQueryCount = function(jquery) {
+ var inDocument = this.browserbot.getDocument();
+ var found = $(inDocument).find(jquery);
+ return found.length;
+}
\ No newline at end of file
14 years, 5 months
JBoss Rich Faces SVN: r16132 - branches/sandbox/rf-demo-ftest-iexplore/src/test/resources/org/jboss/richfaces/integrationTest/tabPanel.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2009-12-15 04:20:46 -0500 (Tue, 15 Dec 2009)
New Revision: 16132
Modified:
branches/sandbox/rf-demo-ftest-iexplore/src/test/resources/org/jboss/richfaces/integrationTest/tabPanel/locators.properties
Log:
* TabPanel - removed some parenting relations (>) from jQueries to be compatible
Modified: branches/sandbox/rf-demo-ftest-iexplore/src/test/resources/org/jboss/richfaces/integrationTest/tabPanel/locators.properties
===================================================================
--- branches/sandbox/rf-demo-ftest-iexplore/src/test/resources/org/jboss/richfaces/integrationTest/tabPanel/locators.properties 2009-12-15 09:19:04 UTC (rev 16131)
+++ branches/sandbox/rf-demo-ftest-iexplore/src/test/resources/org/jboss/richfaces/integrationTest/tabPanel/locators.properties 2009-12-15 09:20:46 UTC (rev 16132)
@@ -6,12 +6,12 @@
# second tab
CUST_EXAMPLE_HEADER=jquery=div#itme > p
-CUST_TABS_ALIGN=jquery=div#itme > table.rich-tabpanel td.rich-tab-bottom-line@align
-CUST_PANEL_TEXT_PREFORMATTED=jquery=div#itme > table.rich-tabpanel > tbody > tr:eq(1) > td:eq({0})
-CUST_PANEL_TAB_PREFORMATTED=jquery=div#itme > table.rich-tabpanel > tbody form td[id$=cell]:eq({0}) > table
+CUST_TABS_ALIGN=jquery\=div\#itme table.rich-tabpanel td.rich-tab-bottom-line@align
+CUST_PANEL_TEXT_PREFORMATTED=jquery\=div\#itme table.rich-tabpanel tbody > tr\:eq(1) > td\:eq({0})
+CUST_PANEL_TAB_PREFORMATTED=jquery\=div\#itme table.rich-tabpanel form td[id$\=cell]\:eq({0}) > table
# third tab
DELET_EXAMPLE_HEADER=jquery=td.content_tab
DELET_PANEL_TABS=jquery=table[id$=RemoveAbleTabPanel] td[id$=cell]
-DELET_PANEL_TAB_CLOSE_PREFORMATTED=jquery=img[id=tabs_form\:hidelink{0}]
+DELET_PANEL_TAB_CLOSE_PREFORMATTED=jquery\=img[id\=tabs_form\:hidelink{0}]
DELET_RESET_BUTTON=jquery=input[value=Reset Tabs]
\ No newline at end of file
14 years, 5 months