Skip to content

Commit

Permalink
Merge pull request #4922 from eclipse-ee4j/mojarra-revert-4808
Browse files Browse the repository at this point in the history
Revert #4808 due to being possible cause of failing TCK
  • Loading branch information
arjantijms committed May 3, 2021
2 parents f2e671e + e6eb5c1 commit 91a4d03
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 151 deletions.
178 changes: 69 additions & 109 deletions impl/src/main/java/com/sun/faces/facelets/tag/jsf/ComponentSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@

package com.sun.faces.facelets.tag.jsf;

import com.sun.faces.RIConstants;
import com.sun.faces.context.StateContext;
import com.sun.faces.facelets.tag.jsf.core.FacetHandler;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.PartialStateSaving;
import com.sun.faces.util.Util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.component.UIPanel;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import javax.faces.view.facelets.ComponentConfig;
import javax.faces.view.facelets.ComponentHandler;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.Tag;
import javax.faces.view.facelets.TagAttribute;
import javax.faces.view.facelets.TagAttributeException;
import javax.faces.view.facelets.Tag;
import javax.faces.event.PhaseId;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.sun.faces.RIConstants;
import com.sun.faces.context.StateContext;
import com.sun.faces.facelets.tag.jsf.core.FacetHandler;
import com.sun.faces.util.Util;

/**
*
Expand All @@ -55,7 +55,6 @@ public final class ComponentSupport {

private final static String MARK_DELETED = "com.sun.faces.facelets.MARK_DELETED";
public final static String MARK_CREATED = "com.sun.faces.facelets.MARK_ID";
private final static String MARK_ID_CACHE = "com.sun.faces.facelets.MARK_ID_CACHE";

// Expando boolean attribute used to identify parent components that have had
// a dynamic child addition or removal.
Expand Down Expand Up @@ -238,104 +237,65 @@ public static UIComponent findUIInstructionChildByTagId(FacesContext context, UI
* @return the UI component
*/
public static UIComponent findChildByTagId(FacesContext context, UIComponent parent, String id) {
// fast path - get the child from the descendant mark id cache
return getDescendantMarkIdCache(parent).get(id);
}

@SuppressWarnings("unchecked")
private static Map<String, UIComponent> getDescendantMarkIdCache(UIComponent component) {
Map<String, UIComponent> descendantMarkIdCache = (Map<String, UIComponent>) component.getTransientStateHelper().getTransient(MARK_ID_CACHE);

if (descendantMarkIdCache == null) {
descendantMarkIdCache = new HashMap<String, UIComponent>();
component.getTransientStateHelper().putTransient(MARK_ID_CACHE, descendantMarkIdCache);
}

return descendantMarkIdCache;
}

/**
* Adds the mark id of the specified {@link UIComponent} <code>otherComponent</code> to the mark id cache of this component,
* including all its descendant mark ids. Changes are propagated up the component tree.
*/
public static void addToDescendantMarkIdCache(UIComponent component, UIComponent otherComponent) {
String markId = (String) otherComponent.getAttributes().get(MARK_CREATED);
if (markId != null) {
addSingleDescendantMarkId(component, markId, otherComponent);
}
Map<String, UIComponent> otherMarkIds = getDescendantMarkIdCache(otherComponent);
if (!otherMarkIds.isEmpty()) {
addAllDescendantMarkIds(component, otherMarkIds);
}
}

/**
* Adds the specified <code>markId</code> and its corresponding {@link UIComponent} <code>otherComponent</code>
* to the mark id cache of this component. Changes are propagated up the component tree.
*/
private static void addSingleDescendantMarkId(UIComponent component, String markId, UIComponent otherComponent) {
getDescendantMarkIdCache(component).put(markId, otherComponent);
UIComponent parent = component.getParent();
if (parent != null) {
addSingleDescendantMarkId(parent, markId, otherComponent);
}
}

/**
* Adds all specified <code>otherMarkIds</code> to the mark id cache of this component.
* Changes are propagated up the component tree.
*/
private static void addAllDescendantMarkIds(UIComponent component, Map<String, UIComponent> otherMarkIds) {
getDescendantMarkIdCache(component).putAll(otherMarkIds);
UIComponent parent = component.getParent();
if (parent != null) {
addAllDescendantMarkIds(parent, otherMarkIds);
}
}

/**
* Removes the mark id of the specified {@link UIComponent} <code>otherComponent</code> from the mark id cache of this component,
* including all its descendant mark ids. Changes are propagated up the component tree.
*/
public static void removeFromDescendantMarkIdCache(UIComponent component, UIComponent otherComponent) {
String markId = (String) otherComponent.getAttributes().get(MARK_CREATED);
if (markId != null) {
removeSingleDescendantMarkId(component, markId);
UIComponent c = null;
UIViewRoot root = context.getViewRoot();
boolean hasDynamicComponents = (null != root &&
root.getAttributes().containsKey(RIConstants.TREE_HAS_DYNAMIC_COMPONENTS));
String cid = null;
List<UIComponent> components;
String facetName = getFacetName(parent);
if (null != facetName) {
c = parent.getFacet(facetName);
// We will have a facet name, but no corresponding facet in the
// case of facets with composite components. In this case,
// we must do the brute force search.
if (null != c) {
cid = (String) c.getAttributes().get(MARK_CREATED);
if (id.equals(cid)) {
return c;
}
}
}
Map<String, UIComponent> otherMarkIds = getDescendantMarkIdCache(otherComponent);
if (!otherMarkIds.isEmpty()) {
removeAllDescendantMarkIds(component, otherMarkIds);
if (0 < parent.getFacetCount()) {
components = new ArrayList<>();
components.addAll(parent.getFacets().values());
components.addAll(parent.getChildren());
} else {
components = parent.getChildren();
}
}

/**
* Removes the specified <code>markId</code> from the mark id cache of this component.
* Changes are propagated up the component tree.
*/
private static void removeSingleDescendantMarkId(UIComponent component, String markId) {
getDescendantMarkIdCache(component).remove(markId);
UIComponent parent = component.getParent();
if (parent != null) {
removeSingleDescendantMarkId(parent, markId);
int len = components.size();
for (int i = 0; i < len; i++) {
c = components.get(i);
cid = (String) c.getAttributes().get(MARK_CREATED);
if (id.equals(cid)) {
return c;
}
if (c instanceof UIPanel && c.getAttributes().containsKey(IMPLICIT_PANEL)) {
for (UIComponent c2 : c.getChildren()) {
cid = (String) c2.getAttributes().get(MARK_CREATED);
if (id.equals(cid)) {
return c2;
}
}
}
if (hasDynamicComponents) {
/*
* Make sure we look for the child recursively it might have moved
* into a different parent in the parent hierarchy. Note currently
* we are only looking down the tree. Maybe it would be better
* to use the VisitTree API instead.
*/
UIComponent foundChild = findChildByTagId(context, c, id);
if (foundChild != null) {
return foundChild;
}
}
}
}

/**
* Removes all specified <code>otherMarkIds</code> from the mark id cache of this component.
* Changes are propagated up the component tree.
*/
private static void removeAllDescendantMarkIds(UIComponent component, Map<String, UIComponent> otherMarkIds) {
Map<String, UIComponent> descendantMarkIdCache = getDescendantMarkIdCache(component);
Iterator<String> iterator = otherMarkIds.keySet().iterator();
while (iterator.hasNext()) {
descendantMarkIdCache.remove(iterator.next());
}
UIComponent parent = component.getParent();
if (parent != null) {
removeAllDescendantMarkIds(parent, otherMarkIds);
}
return null;
}

/**
* According to JSF 1.2 tag specs, this helper method will use the
* TagAttribute passed in determining the Locale intended.
Expand Down
15 changes: 0 additions & 15 deletions impl/src/main/java/javax/faces/component/ComponentStateHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@

package javax.faces.component;

import static com.sun.faces.facelets.tag.jsf.ComponentSupport.MARK_CREATED;
import static com.sun.faces.facelets.tag.jsf.ComponentSupport.addToDescendantMarkIdCache;
import static com.sun.faces.util.Util.coalesce;
import static com.sun.faces.util.Util.isEmpty;
import static javax.faces.component.UIComponent.PropertyKeys;
import static javax.faces.component.UIComponentBase.restoreAttachedState;
import static javax.faces.component.UIComponentBase.saveAttachedState;

Expand All @@ -34,8 +31,6 @@
import javax.el.ValueExpression;
import javax.faces.context.FacesContext;

import com.sun.faces.facelets.tag.jsf.ComponentSupport;

/**
* A base implementation for maps which implement the PartialStateHolder and TransientStateHolder
* interfaces.
Expand Down Expand Up @@ -119,16 +114,6 @@ public Object remove(Serializable key) {
public Object put(Serializable key, String mapKey, Object value) {
initMap(key);

if (MARK_CREATED.equals(mapKey)) {
if (PropertyKeys.attributes.equals(key)) {
UIComponent parent = component.getParent();
if (parent != null) {
// remember this component by its mark id
addToDescendantMarkIdCache(parent, component);
}
}
}

Object ret = null;
if (component.initialStateMarked()) {
Map<String, Object> dMap = (Map<String, Object>) deltaMap.get(key);
Expand Down
1 change: 0 additions & 1 deletion impl/src/main/java/javax/faces/component/UIComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package javax.faces.component;

import static com.sun.faces.facelets.tag.jsf.ComponentSupport.MARK_CREATED;
import static com.sun.faces.util.Util.isAnyNull;
import static com.sun.faces.util.Util.isOneOf;
import static java.util.Collections.emptyMap;
Expand Down
27 changes: 1 addition & 26 deletions impl/src/main/java/javax/faces/component/UIComponentBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package javax.faces.component;

import static com.sun.faces.facelets.tag.jsf.ComponentSupport.addToDescendantMarkIdCache;
import static com.sun.faces.facelets.tag.jsf.ComponentSupport.removeFromDescendantMarkIdCache;
import static com.sun.faces.util.Util.isAllNull;
import static com.sun.faces.util.Util.isAnyNull;
import static com.sun.faces.util.Util.isEmpty;
Expand Down Expand Up @@ -73,7 +71,6 @@
import javax.faces.event.ComponentSystemEventListener;
import javax.faces.event.FacesEvent;
import javax.faces.event.FacesListener;
import javax.faces.event.PhaseId;
import javax.faces.event.PostAddToViewEvent;
import javax.faces.event.PostValidateEvent;
import javax.faces.event.PreRemoveFromViewEvent;
Expand All @@ -85,7 +82,6 @@

import com.sun.faces.application.ValueBindingValueExpressionAdapter;
import com.sun.faces.application.ValueExpressionValueBindingAdapter;
import com.sun.faces.facelets.tag.jsf.ComponentSupport;

/**
* <p>
Expand Down Expand Up @@ -2256,12 +2252,10 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
private static class ChildrenList extends ArrayList<UIComponent> {

private UIComponent component;
private FacesContext context;

public ChildrenList(UIComponent component) {
super(6);
this.component = component;
this.context = component.getFacesContext();
}

@Override
Expand All @@ -2271,7 +2265,6 @@ public void add(int index, UIComponent element) {
} else if ((index < 0) || (index > size())) {
throw new IndexOutOfBoundsException();
} else {
addToDescendantMarkIdCache(component, element);
eraseParent(element);
super.add(index, element);
element.setParent(component);
Expand All @@ -2284,7 +2277,6 @@ public boolean add(UIComponent element) {
if (element == null) {
throw new NullPointerException();
} else {
addToDescendantMarkIdCache(component, element);
eraseParent(element);
boolean result = super.add(element);
element.setParent(component);
Expand Down Expand Up @@ -2332,9 +2324,6 @@ public void clear() {
}
for (int i = 0; i < n; i++) {
UIComponent child = get(i);
if (!context.isReleased() && !context.getCurrentPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
removeFromDescendantMarkIdCache(component, child);
}
child.setParent(null);
}
super.clear();
Expand All @@ -2358,9 +2347,6 @@ public ListIterator<UIComponent> listIterator(int index) {
@Override
public UIComponent remove(int index) {
UIComponent child = get(index);
if (!context.isReleased() && !context.getCurrentPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
removeFromDescendantMarkIdCache(component, child);
}
child.setParent(null);
super.remove(index);
return (child);
Expand All @@ -2372,9 +2358,7 @@ public boolean remove(Object elementObj) {
if (element == null) {
throw new NullPointerException();
}
if (!context.isReleased() && !context.getCurrentPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
removeFromDescendantMarkIdCache(component, element);
}

if (super.indexOf(element) != -1) {
element.setParent(null);
}
Expand Down Expand Up @@ -2416,10 +2400,8 @@ public UIComponent set(int index, UIComponent element) {
} else if ((index < 0) || (index >= size())) {
throw new IndexOutOfBoundsException();
} else {
addToDescendantMarkIdCache(component, element);
eraseParent(element);
UIComponent previous = get(index);
removeFromDescendantMarkIdCache(component, previous);
super.set(index, element);
previous.setParent(null);
element.setParent(component);
Expand Down Expand Up @@ -2580,12 +2562,10 @@ public void remove() {
private static class FacetsMap extends HashMap<String, UIComponent> {

private UIComponent component;
private FacesContext context;

public FacetsMap(UIComponent component) {
super(3, 1.0f);
this.component = component;
context = component.getFacesContext();
}

@Override
Expand Down Expand Up @@ -2618,10 +2598,8 @@ public UIComponent put(String key, UIComponent value) {
}
UIComponent previous = super.get(key);
if (previous != null) {
removeFromDescendantMarkIdCache(component, previous);
previous.setParent(null);
}
addToDescendantMarkIdCache(component, value);
eraseParent(value);
UIComponent result = super.put(key, value);
value.setParent(component);
Expand All @@ -2643,9 +2621,6 @@ public void putAll(Map<? extends String, ? extends UIComponent> map) {
public UIComponent remove(Object key) {
UIComponent previous = get(key);
if (previous != null) {
if (!context.isReleased() && !context.getCurrentPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
removeFromDescendantMarkIdCache(component, previous);
}
previous.setParent(null);
}
super.remove(key);
Expand Down

0 comments on commit 91a4d03

Please sign in to comment.