Author: Alex.Kolonitsky
Date: 2011-01-19 09:58:13 -0500 (Wed, 19 Jan 2011)
New Revision: 21084
Modified:
trunk/core/api/src/main/java/org/richfaces/component/ComponentIterators.java
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuGroup.java
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/tab.js
Log:
RF-10112 tabPanel: destroy failed on ajax render
Modified: trunk/core/api/src/main/java/org/richfaces/component/ComponentIterators.java
===================================================================
---
trunk/core/api/src/main/java/org/richfaces/component/ComponentIterators.java 2011-01-19
14:50:10 UTC (rev 21083)
+++
trunk/core/api/src/main/java/org/richfaces/component/ComponentIterators.java 2011-01-19
14:58:13 UTC (rev 21084)
@@ -25,12 +25,13 @@
import javax.faces.component.UIComponent;
+import com.google.common.base.Predicate;
import com.google.common.collect.AbstractIterator;
import com.google.common.collect.Iterators;
/**
* @author Nick Belaevski
- *
+ *
*/
public final class ComponentIterators {
@@ -41,24 +42,24 @@
if (component == null) {
return Iterators.<UIComponent>emptyIterator();
}
-
+
return new AbstractIterator<UIComponent>() {
private UIComponent currentComponent = component;
-
+
@Override
protected UIComponent computeNext() {
currentComponent = currentComponent.getParent();
-
+
if (currentComponent == null) {
endOfData();
}
-
+
return currentComponent;
}
};
}
-
+
public static Iterator<UIComponent> parentsAndSelf(final UIComponent component)
{
if (component == null) {
return Iterators.<UIComponent>emptyIterator();
@@ -66,4 +67,40 @@
return Iterators.concat(Iterators.singletonIterator(component),
parents(component));
}
+
+ public static UIComponent getParent(UIComponent component,
Predicate<UIComponent> predicat) {
+ if (component == null || predicat == null) {
+ return null;
+ }
+
+ UIComponent parent = component.getParent();
+ while (parent != null) {
+ if (predicat.apply(parent)) {
+ return parent;
+ }
+ parent = parent.getParent();
+ }
+ return null;
+ }
+
+ /**
+ * Finds a parent of given UI <code>component</code>.
+ * @param component <code>UIComponent</code>
+ * @param parentClass <code>Class</code> of desired parent
+ * @return <code>UIComponent</code>
+ */
+ public static <T extends UIComponent> T getParent(UIComponent component,
Class<T> parentClass) {
+ if (component == null || parentClass == null) {
+ return null;
+ }
+
+ UIComponent parent = component.getParent();
+ while (parent != null) {
+ if (parentClass.isInstance(parent)) {
+ return (T) parent;
+ }
+ parent = parent.getParent();
+ }
+ return null;
+ }
}
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuGroup.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuGroup.java 2011-01-19
14:50:10 UTC (rev 21083)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenuGroup.java 2011-01-19
14:58:13 UTC (rev 21084)
@@ -200,7 +200,6 @@
enum Properties {
iconLeftDisabled, iconLeftExpanded, iconRightCollapsed, iconRightDisabled,
iconRightExpanded, disabledClass, styleClass, expandEvent, collapseEvent,
iconLeftCollapsed
-
}
@Attribute(generate = false)
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java 2011-01-19
14:50:10 UTC (rev 21083)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java 2011-01-19
14:58:13 UTC (rev 21084)
@@ -55,13 +55,19 @@
return COMPONENT_FAMILY;
}
+/*
@Override
public AbstractTogglePanel getParent() {
return (AbstractTogglePanel) super.getParent();
}
+*/
+ public AbstractTogglePanel getParentPanel() {
+ return ComponentIterators.getParent(this, AbstractTogglePanel.class);
+ }
+
public boolean isActive() {
- return getParent().isActiveItem(this);
+ return getParentPanel().isActiveItem(this);
}
@Override
@@ -71,7 +77,7 @@
@Override
public void encodeAll(FacesContext context) throws IOException {
- if (getParent().isActiveItem(this)) {
+ if (isActive()) {
super.encodeAll(context);
} else {
switch (getSwitchType()) {
@@ -133,7 +139,7 @@
getStateHelper().put(NAME, name);
}
- @Attribute(defaultValue = "getParent().getSwitchType()")
+ @Attribute(defaultValue = "getParentPanel().getSwitchType()")
public abstract SwitchType getSwitchType();
// ------------------------------------------------ Html Attributes
@@ -185,6 +191,3 @@
return "TogglePanelItem {name: " + getName() + ", switchType:
" + getSwitchType() + '}';
}
}
-
-
-
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java 2011-01-19
14:50:10 UTC (rev 21083)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java 2011-01-19
14:58:13 UTC (rev 21084)
@@ -75,7 +75,7 @@
options.put("switchMode", panelItem.getSwitchType());
AbstractTogglePanelItem item = (AbstractTogglePanelItem) component;
- AbstractTogglePanel panel = item.getParent();
+ AbstractTogglePanel panel = item.getParentPanel();
options.put("index", panel.getChildIndex(item.getName()));
TogglePanelRenderer.addEventOption(context, component, options, LEAVE);
Modified: trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/tab.js
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/tab.js 2011-01-19
14:50:10 UTC (rev 21083)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/tab.js 2011-01-19
14:58:13 UTC (rev 21084)
@@ -137,7 +137,9 @@
destroy: function () {
var parent = this.getTogglePanel();
- delete parent.getItems()[this.index];
+ if (parent && parent.getItems &&
parent.getItems()[this.index]) {
+ delete parent.getItems()[this.index];
+ }
rf.Event.unbindById(this.id);
Show replies by date