Author: nbelaevski
Date: 2011-01-26 14:22:32 -0500 (Wed, 26 Jan 2011)
New Revision: 21245
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanelTitledItem.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/AccordionItemRenderer.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/CollapsiblePanelRenderer.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TabRenderer.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/collapsiblePanelItem.js
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/tab.js
Log:
https://issues.jboss.org/browse/RF-10211
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java 2011-01-26
19:04:15 UTC (rev 21244)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java 2011-01-26
19:22:32 UTC (rev 21245)
@@ -46,12 +46,19 @@
import org.richfaces.application.MessageFactory;
import org.richfaces.application.ServiceTracker;
import org.richfaces.appplication.FacesMessages;
-import org.richfaces.cdk.annotations.*;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
import org.richfaces.component.util.MessageUtil;
import org.richfaces.event.ItemChangeEvent;
import org.richfaces.event.ItemChangeListener;
import org.richfaces.event.ItemChangeSource;
+import com.google.common.base.Strings;
+
/**
* @author akolonitsky
* @version 1.0
@@ -146,7 +153,13 @@
@Override
public void encodeBegin(FacesContext context) throws IOException {
- AbstractTogglePanelItem item = this.getItem(getActiveItem());
+ AbstractTogglePanelItem item = null;
+ String activeItem = getActiveItem();
+
+ if (!Strings.isNullOrEmpty(activeItem)) {
+ item = this.getItem(activeItem);
+ }
+
if (item == null || !item.isRendered()) {
List<AbstractTogglePanelItem> renderedItems = this.getRenderedItems();
if (!renderedItems.isEmpty()) {
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-26
19:04:15 UTC (rev 21244)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java 2011-01-26
19:22:32 UTC (rev 21245)
@@ -22,16 +22,13 @@
package org.richfaces.component;
-import org.richfaces.cdk.annotations.*;
-import org.richfaces.renderkit.html.TogglePanelItemRenderer;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.cdk.annotations.TagType;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.event.PreRenderComponentEvent;
-import javax.faces.render.Renderer;
-import java.io.IOException;
-import java.util.Map;
-
/**
* @author akolonitsky
* @version 1.0
@@ -70,64 +67,6 @@
return getParentPanel().isActiveItem(this);
}
- @Override
- public Renderer getRenderer(FacesContext context) {
- return super.getRenderer(context);
- }
-
- @Override
- public void encodeAll(FacesContext context) throws IOException {
- if (isActive()) {
- super.encodeAll(context);
- } else {
- switch (getSwitchType()) {
- case client:
- hidePanelItem(this);
-
- super.encodeAll(context);
- break;
-
- case ajax:
- case server:
- this.encodePlaceHolderWithJs(context);
- break;
-
- default:
- throw new IllegalStateException("Unknown switch type : " +
getSwitchType());
- }
- }
- }
-
- public void encodePlaceHolderWithJs(FacesContext context) throws IOException {
- if (context == null) {
- throw new IllegalArgumentException();
- }
-
- if (!isRendered()) {
- return;
- }
-
- pushComponentToEL(context, null);
-
- context.getApplication().publishEvent(context, PreRenderComponentEvent.class,
this);
-
- if (this.getRendererType() != null) {
- TogglePanelItemRenderer renderer = (TogglePanelItemRenderer)
this.getRenderer(context);
- if (renderer != null) {
- renderer.encodePlaceHolderWithJs(context, this);
- }
- }
-
- popComponentFromEL(context);
- }
-
- protected static void hidePanelItem(UIComponent item) {
- // TODO move to renderer
- Map<String,Object> attrs = item.getAttributes();
- Object style = attrs.get("style");
- attrs.put("style", "display:none; " + style);
- }
-
// ------------------------------------------------ Component Attributes
@Attribute(defaultValue = "getId()", generate = false)
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanelTitledItem.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanelTitledItem.java 2011-01-26
19:04:15 UTC (rev 21244)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanelTitledItem.java 2011-01-26
19:22:32 UTC (rev 21245)
@@ -22,15 +22,13 @@
package org.richfaces.component;
-import org.richfaces.cdk.annotations.*;
-import org.richfaces.renderkit.html.DivPanelRenderer;
+import static org.richfaces.renderkit.html.DivPanelRenderer.capitalize;
import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import java.io.IOException;
-import java.util.Properties;
-import static org.richfaces.renderkit.html.DivPanelRenderer.capitalize;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.EventName;
+import org.richfaces.renderkit.html.DivPanelRenderer;
/**
* @author akolonitsky
@@ -67,26 +65,6 @@
return COMPONENT_FAMILY;
}
- @Override
- public void encodeAll(FacesContext context) throws IOException {
- if (!isRendered()) {
- return;
- }
-
- encodeBegin(context);
- if (!isDisabled()) {
- if (getRendersChildren()) {
- encodeChildren(context);
- } else if (this.getChildCount() > 0) {
- for (UIComponent kid : getChildren()) {
- kid.encodeAll(context);
- }
- }
- }
-
- encodeEnd(context);
- }
-
public UIComponent getHeaderFacet(Enum<?> state) {
return getHeaderFacet(this, state);
}
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/AccordionItemRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/AccordionItemRenderer.java 2011-01-26
19:04:15 UTC (rev 21244)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/AccordionItemRenderer.java 2011-01-26
19:22:32 UTC (rev 21245)
@@ -71,25 +71,52 @@
private final TableIconsRendererHelper<AbstractAccordionItem> headerRenderer =
new AccordionItemHeaderRenderer();
+ public AccordionItemRenderer() {
+ super(false);
+ }
+
@Override
protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
- super.doEncodeBegin(writer, context, component);
+ doEncodeItemBegin(writer, context, component);
+ }
+ @Override
+ protected void doEncodeItemBegin(ResponseWriter writer, FacesContext context,
UIComponent component)
+ throws IOException {
+
+ super.doEncodeItemBegin(writer, context, component);
encodeHeader(context, (AbstractAccordionItem) component);
-
encodeContentBegin(context, component);
}
-
+
@Override
protected String getStyleClass(UIComponent component) {
return concatClasses("rf-ac-itm", attributeAsString(component,
"styleClass"));
}
@Override
+ protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component)
+ throws IOException {
+
+ AbstractAccordionItem item = (AbstractAccordionItem) component;
+
+ if (!item.isDisabled()) {
+ super.doEncodeChildren(writer, context, item);
+ }
+ }
+
+ @Override
protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ doEncodeItemEnd(writer, context, component);
+ }
+
+ @Override
+ protected void doEncodeItemEnd(ResponseWriter writer, FacesContext context,
UIComponent component)
+ throws IOException {
+
encodeContentEnd(writer, component);
- super.doEncodeEnd(writer, context, component);
+ super.doEncodeItemEnd(writer, context, component);
}
private void encodeContentBegin(FacesContext context, UIComponent component) throws
IOException {
@@ -141,5 +168,6 @@
protected Class<? extends UIComponent> getComponentClass() {
return AbstractTogglePanelTitledItem.class;
}
+
}
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/CollapsiblePanelRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/CollapsiblePanelRenderer.java 2011-01-26
19:04:15 UTC (rev 21244)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/CollapsiblePanelRenderer.java 2011-01-26
19:22:32 UTC (rev 21245)
@@ -101,10 +101,6 @@
}
};
- public TableIconsRendererHelper getHeaderRenderer() {
- return headerRenderer;
- }
-
@Override
protected void doDecode(FacesContext context, UIComponent component) {
AbstractTogglePanel panel = (AbstractTogglePanel) component;
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java 2011-01-26
19:04:15 UTC (rev 21244)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java 2011-01-26
19:22:32 UTC (rev 21245)
@@ -22,21 +22,22 @@
package org.richfaces.renderkit.html;
-import static org.richfaces.renderkit.HtmlConstants.*;
+import static org.richfaces.renderkit.HtmlConstants.CLASS_ATTRIBUTE;
+import static org.richfaces.renderkit.HtmlConstants.ID_ATTRIBUTE;
+import static org.richfaces.renderkit.RenderKitUtils.attributes;
+import static org.richfaces.renderkit.RenderKitUtils.renderPassThroughAttributes;
-import org.richfaces.component.AbstractDivPanel;
-import org.richfaces.renderkit.HtmlConstants;
-import org.richfaces.renderkit.RenderKitUtils;
-import org.richfaces.renderkit.RendererBase;
+import java.io.IOException;
+import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.util.Map;
-import static org.richfaces.renderkit.RenderKitUtils.attributes;
-import static org.richfaces.renderkit.RenderKitUtils.renderPassThroughAttributes;
+import org.richfaces.component.AbstractDivPanel;
+import org.richfaces.renderkit.HtmlConstants;
+import org.richfaces.renderkit.RenderKitUtils;
+import org.richfaces.renderkit.RendererBase;
/**
* @author akolonitsky
@@ -97,8 +98,10 @@
@Override
protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
- super.doEncodeBegin(writer, context, component);
-
+ doEncodeItemBegin(writer, context, component);
+ }
+
+ protected void doEncodeItemBegin(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
writer.startElement(HtmlConstants.DIV_ELEM, component);
writer.writeAttribute(ID_ATTRIBUTE, component.getClientId(context),
"clientId");
writer.writeAttribute(CLASS_ATTRIBUTE, getStyleClass(component), null);
@@ -124,8 +127,10 @@
@Override
protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
- super.doEncodeEnd(writer, context, component);
-
+ doEncodeItemEnd(writer, context, component);
+ }
+
+ protected void doEncodeItemEnd(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
writeJavaScript(writer, context, component);
writer.endElement(HtmlConstants.DIV_ELEM);
Modified: trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TabRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TabRenderer.java 2011-01-26
19:04:15 UTC (rev 21244)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TabRenderer.java 2011-01-26
19:22:32 UTC (rev 21245)
@@ -25,7 +25,6 @@
import static org.richfaces.renderkit.HtmlConstants.CLASS_ATTRIBUTE;
import static org.richfaces.renderkit.HtmlConstants.DIV_ELEM;
import static org.richfaces.renderkit.HtmlConstants.ID_ATTRIBUTE;
-import static org.richfaces.renderkit.HtmlConstants.STYLE_ATTRIBUTE;
import java.io.IOException;
import java.util.Map;
@@ -59,25 +58,38 @@
public class TabRenderer extends TogglePanelItemRenderer {
@Override
- protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
- super.doEncodeBegin(writer, context, component);
+ protected void doEncodeItemBegin(ResponseWriter writer, FacesContext context,
UIComponent component)
+ throws IOException {
+ super.doEncodeItemBegin(writer, context, component);
encodeContentBegin(context, component, writer);
}
-
+
@Override
protected String getStyleClass(UIComponent component) {
return concatClasses("rf-tb", attributeAsString(component,
"styleClass"));
}
@Override
- protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
- encodeContentEnd(component, writer);
+ protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component)
+ throws IOException {
- super.doEncodeEnd(writer, context, component);
+ AbstractTab tab = (AbstractTab) component;
+
+ if (!tab.isDisabled()) {
+ super.doEncodeChildren(writer, context, tab);
+ }
}
@Override
+ protected void doEncodeItemEnd(ResponseWriter writer, FacesContext context,
UIComponent component)
+ throws IOException {
+
+ encodeContentEnd(component, writer);
+ super.doEncodeItemEnd(writer, context, component);
+ }
+
+ @Override
protected void writeJavaScript(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
Object script = getScriptObject(context, component);
if (script == null) {
@@ -94,11 +106,6 @@
writer.startElement(DIV_ELEM, component);
writer.writeAttribute(CLASS_ATTRIBUTE, concatClasses("rf-tb-cnt",
attributeAsString(component, "contentClass")), null);
writer.writeAttribute(ID_ATTRIBUTE, component.getClientId(context) +
":content", null);
-
- AbstractTogglePanelTitledItem item = (AbstractTogglePanelTitledItem) component;
- if (!item.isActive() || item.isDisabled()) {
- writer.writeAttribute(STYLE_ATTRIBUTE, "display: none", null);
- }
}
private void encodeContentEnd(UIComponent component, ResponseWriter responseWriter)
throws IOException {
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-26
19:04:15 UTC (rev 21244)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java 2011-01-26
19:22:32 UTC (rev 21245)
@@ -36,6 +36,8 @@
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.AbstractTogglePanel;
import org.richfaces.component.AbstractTogglePanelItem;
+import org.richfaces.component.SwitchType;
+import org.richfaces.component.util.HtmlUtil;
/**
* @author akolonitsky
@@ -54,6 +56,16 @@
private static final String LEAVE = "leave";
private static final String ENTER = "enter";
+ private final boolean hideInactiveItems;
+
+ public TogglePanelItemRenderer() {
+ this(true);
+ }
+
+ protected TogglePanelItemRenderer(boolean hideInactiveItems) {
+ this.hideInactiveItems = hideInactiveItems;
+ }
+
@Override
protected String getStyleClass(UIComponent component) {
return concatClasses("rf-tgp-itm", attributeAsString(component,
"styleClass"));
@@ -89,7 +101,12 @@
return AbstractTogglePanelItem.class;
}
- public void encodePlaceHolderWithJs(FacesContext context, AbstractTogglePanelItem
item) throws IOException {
+ @Override
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ protected void encodePlaceHolderWithJs(FacesContext context, AbstractTogglePanelItem
item) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.startElement("div", null);
@@ -100,5 +117,50 @@
writer.endElement("div");
}
+
+ private boolean shouldEncodeItem(FacesContext context, AbstractTogglePanelItem item)
{
+ return item.isActive() || item.getSwitchType() == SwitchType.client;
+ }
+
+ @Override
+ protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ AbstractTogglePanelItem item = (AbstractTogglePanelItem) component;
+
+ if (shouldEncodeItem(context, item)) {
+ doEncodeItemBegin(writer, context, component);
+ }
+ }
+
+ @Override
+ protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component)
+ throws IOException {
+
+ AbstractTogglePanelItem item = (AbstractTogglePanelItem) component;
+
+ if (shouldEncodeItem(context, item)) {
+ renderChildren(context, component);
+ }
+ }
+
+ @Override
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ AbstractTogglePanelItem item = (AbstractTogglePanelItem) component;
+
+ if (shouldEncodeItem(context, item)) {
+ doEncodeItemEnd(writer, context, component);
+ } else {
+ encodePlaceHolderWithJs(context, item);
+ }
+ }
+
+ @Override
+ protected String getStyle(UIComponent component) {
+ String attributeStyle = super.getStyle(component);
+ if (hideInactiveItems && !((AbstractTogglePanelItem)
component).isActive()) {
+ return HtmlUtil.concatStyles(attributeStyle, "display: none");
+ } else {
+ return attributeStyle;
+ }
+ }
}
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/collapsiblePanelItem.js
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/collapsiblePanelItem.js 2011-01-26
19:04:15 UTC (rev 21244)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/collapsiblePanelItem.js 2011-01-26
19:22:32 UTC (rev 21245)
@@ -24,10 +24,12 @@
rf.ui = rf.ui || {};
+ var DEFAULT_OPTIONS = {switchMode: 'ajax'};
+
rf.ui.CollapsiblePanelItem = rf.ui.TogglePanelItem.extendClass({
init : function (componentId, options) {
- rf.ui.TogglePanelItem.call(this, componentId, options);
+ rf.ui.TogglePanelItem.call(this, componentId, $.extend({}, DEFAULT_OPTIONS,
options));
this.headerClass = "rf-cp-hdr-" + this.__state();
},
@@ -41,7 +43,10 @@
__leave : function () {
this.__content().hide();
- this.__header().removeClass(this.headerClass);
+
+ if (this.options.switchMode == 'client') {
+ this.__header().removeClass(this.headerClass);
+ }
return true;
},
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-26
19:04:15 UTC (rev 21244)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/tab.js 2011-01-26
19:22:32 UTC (rev 21245)
@@ -72,7 +72,7 @@
* */
__content : function () {
if (!this.__content_) {
- this.__content_ = $(rf.getDomElement(this.id + ":content"));
+ this.__content_ = $(rf.getDomElement(this.id));
}
return this.__content_;
},