You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2012/03/08 18:45:11 UTC
svn commit: r1298481 -
/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
Author: lu4242
Date: Thu Mar 8 17:45:11 2012
New Revision: 1298481
URL: http://svn.apache.org/viewvc?rev=1298481&view=rev
Log:
MYFACES-3494 [perf] improvements on DefaultFaceletsStateManagementStrategy
Modified:
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java?rev=1298481&r1=1298480&r2=1298481&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java Thu Mar 8 17:45:11 2012
@@ -288,12 +288,43 @@ public class DefaultFaceletsStateManagem
states = (Map<String, Object>) state[1];
// Visit the children and restore their state.
-
- //view.visitTree (VisitContext.createVisitContext (context), new RestoreStateVisitor (states));
-
+ boolean emptyState = false;
+ boolean containsFaceletState = states.containsKey(
+ ComponentSupport.FACELET_STATE_INSTANCE);
+ if (states.isEmpty())
+ {
+ emptyState = true;
+ }
+ else if (states.size() == 1 &&
+ containsFaceletState)
+ {
+ emptyState = true;
+ }
//Restore state of current components
- restoreStateFromMap(context, states, view);
-
+ if (!emptyState)
+ {
+ // Check if there is only one component state
+ // and that state is UIViewRoot instance (for example
+ // when using ViewScope)
+ if ((states.size() == 1 && !containsFaceletState) ||
+ (states.size() == 2 && containsFaceletState))
+ {
+ Object viewState = states.get(view.getClientId(context));
+ if (viewState != null)
+ {
+ restoreViewRootOnlyFromMap(context,viewState, view);
+ }
+ else
+ {
+ //The component is not viewRoot, restore as usual.
+ restoreStateFromMap(context, states, view);
+ }
+ }
+ else
+ {
+ restoreStateFromMap(context, states, view);
+ }
+ }
if (faceletViewState != null)
{
view.getAttributes().put(ComponentSupport.FACELET_STATE_INSTANCE, faceletViewState);
@@ -567,6 +598,39 @@ public class DefaultFaceletsStateManagem
return serializedView;
}
+ private void restoreViewRootOnlyFromMap(
+ final FacesContext context, final Object viewState,
+ final UIComponent view)
+ {
+ // Only viewState found, process it but skip tree
+ // traversal, saving some time.
+ try
+ {
+ //Restore view
+ view.pushComponentToEL(context, view);
+ if (viewState != null)
+ {
+ if (!(viewState instanceof AttachedFullStateWrapper))
+ {
+ try
+ {
+ view.restoreState(context, viewState);
+ }
+ catch(Exception e)
+ {
+ throw new IllegalStateException(
+ "Error restoring component: "+
+ view.getClientId(context), e);
+ }
+ }
+ }
+ }
+ finally
+ {
+ view.popComponentFromEL(context);
+ }
+ }
+
private void restoreStateFromMap(final FacesContext context, final Map<String,Object> states,
final UIComponent component)
{
@@ -834,8 +898,6 @@ public class DefaultFaceletsStateManagem
//Scan children
if (component.getChildCount() > 0)
{
- String currentClientId = component.getClientId(context);
-
List<UIComponent> children = component.getChildren();
for (int i = 0; i < children.size(); i++)
{
@@ -865,7 +927,7 @@ public class DefaultFaceletsStateManagem
//This includes position, structure and state of subtree
states.put(child.getClientId(context), new AttachedFullStateWrapper(
new Object[]{
- currentClientId,
+ component.getClientId(context),
null,
i,
internalBuildTreeStructureToSave(child),
@@ -884,7 +946,6 @@ public class DefaultFaceletsStateManagem
if (component.getFacetCount() > 0)
{
Map<String, UIComponent> facetMap = component.getFacets();
- String currentClientId = component.getClientId(context);
for (Map.Entry<String, UIComponent> entry : facetMap.entrySet())
{
@@ -914,7 +975,7 @@ public class DefaultFaceletsStateManagem
//This includes position, structure and state of subtree
ensureClearInitialState(child);
states.put(child.getClientId(context),new AttachedFullStateWrapper(new Object[]{
- currentClientId,
+ component.getClientId(context),
facetName,
null,
internalBuildTreeStructureToSave(child),