Author: Alex.Kolonitsky
Date: 2011-01-06 11:14:50 -0500 (Thu, 06 Jan 2011)
New Revision: 20911
Modified:
trunk/examples/output-demo/src/main/webapp/examples/accordion.xhtml
trunk/examples/output-demo/src/main/webapp/examples/togglePanel-mixed.xhtml
trunk/examples/output-demo/src/main/webapp/resources/tests/richfaces-accordion-headers-qunit.js
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.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/AccordionRenderer.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/TabPanelRenderer.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/accordionItem.js
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/collapsiblePanel.js
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/togglePanel.js
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/togglePanelItem.js
trunk/ui/output/ui/src/test/resources/org/richfaces/renderkit/html/collapsiblePanel.xmlunit.xml
Log:
RF-9895 Toggle panel item: attributes onenter and onleave ignored
RF-9821 Accordion item: attributes onenter and onleave do not work
Modified: trunk/examples/output-demo/src/main/webapp/examples/accordion.xhtml
===================================================================
--- trunk/examples/output-demo/src/main/webapp/examples/accordion.xhtml 2011-01-06
14:24:34 UTC (rev 20910)
+++ trunk/examples/output-demo/src/main/webapp/examples/accordion.xhtml 2011-01-06
16:14:50 UTC (rev 20911)
@@ -16,10 +16,12 @@
<h:form id="f" style="border:blue solid thin;">
<h:panelGroup>
- <pn:accordion width="500px" height="300px"
itemChangeListener="#{togglePanelBean.itemChangeActionListener}">
- <pn:accordionItem header="label 1">Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here.</pn:accordionItem>
- <pn:accordionItem header="label 2">content
2</pn:accordionItem>
- <pn:accordionItem header="label 3">content
3</pn:accordionItem>
+ <pn:accordion width="500px" height="300px"
itemChangeListener="#{togglePanelBean.itemChangeActionListener}"
switchType="ajax"
+ itemRightIconActive="triangleDown"
itemRightIconInactive="triangleUp" itemRightIconDisabled="disc"
itemLeftIconDisabled="disc" >
+ <pn:accordionItem header="label 1" >Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here. Content will be here. Content will be here. Content will be
here. Content will be here.</pn:accordionItem>
+ <pn:accordionItem header="label 2" >content
2</pn:accordionItem>
+ <pn:accordionItem header="label 3"
onenter="alert('hello, world!')" >content 3</pn:accordionItem>
+ <pn:accordionItem header="label 4"
disabled="true" >content 4</pn:accordionItem>
</pn:accordion>
</h:panelGroup>
</h:form>
Modified: trunk/examples/output-demo/src/main/webapp/examples/togglePanel-mixed.xhtml
===================================================================
--- trunk/examples/output-demo/src/main/webapp/examples/togglePanel-mixed.xhtml 2011-01-06
14:24:34 UTC (rev 20910)
+++ trunk/examples/output-demo/src/main/webapp/examples/togglePanel-mixed.xhtml 2011-01-06
16:14:50 UTC (rev 20911)
@@ -15,8 +15,8 @@
<ui:define name="body">
<h:form id="f">
<pn:togglePanel id="panel" activeItem="name1"
switchType="client" lang="en" cycledSwitching="true" >
- <pn:togglePanelItem name="name1">hello name1
client</pn:togglePanelItem>
- <pn:togglePanelItem name="name2"
switchType="ajax">hello name2 ajax</pn:togglePanelItem>
+ <pn:togglePanelItem name="name1" >hello name1
client</pn:togglePanelItem>
+ <pn:togglePanelItem name="name2"
onenter="alert('onenter ajax');" switchType="ajax">hello
name2 ajax</pn:togglePanelItem>
<pn:togglePanelItem name="name3"
switchType="server">hello name3 server</pn:togglePanelItem>
</pn:togglePanel>
Modified:
trunk/examples/output-demo/src/main/webapp/resources/tests/richfaces-accordion-headers-qunit.js
===================================================================
---
trunk/examples/output-demo/src/main/webapp/resources/tests/richfaces-accordion-headers-qunit.js 2011-01-06
14:24:34 UTC (rev 20910)
+++
trunk/examples/output-demo/src/main/webapp/resources/tests/richfaces-accordion-headers-qunit.js 2011-01-06
16:14:50 UTC (rev 20911)
@@ -25,32 +25,37 @@
var ACCORDION_ID = "f:panel";
+ function isLabelVisible(item, state) {
+ return item.__header().find(".rf-ac-itm-lbl-" +
state).is(":visible");
+ }
+
function testFirst(items) {
- ok(items[0].__header("act").is(":visible"), "1 item:
active visible");
- ok(!items[0].__header("inact").is(":visible"), "1 item:
inactive unvisible");
- ok(!items[0].__header("dis").is(":visible"), "1 item:
disabled unvisible");
- ok(!items[1].__header("act").is(":visible"), "2 item:
active visible");
- ok(!items[1].__header("inact").is(":visible"), "2 item:
inactive unvisible");
- ok(items[1].__header("dis").is(":visible"), "2 item:
disabled unvisible");
+ ok( isLabelVisible(items[0], "act"), "1 item: active
visible");
+ ok(!isLabelVisible(items[0], "inact"), "1 item: inactive
unvisible");
+ ok(!isLabelVisible(items[0],"dis"), "1 item: disabled
unvisible");
- ok(!items[2].__header("act").is(":visible"), "3 item:
active unvisible");
- ok(items[2].__header("inact").is(":visible"), "3 item:
inactive visible");
- ok(!items[2].__header("dis").is(":visible"), "3 item:
disabled unvisible");
+ ok(!isLabelVisible(items[1],"act"), "2 item: active
visible");
+ ok(!isLabelVisible(items[1],"inact"), "2 item: inactive
unvisible");
+ ok( isLabelVisible(items[1],"dis"), "2 item: disabled
unvisible");
+
+ ok(!isLabelVisible(items[2], "act"), "3 item: active
unvisible");
+ ok( isLabelVisible(items[2], "inact"), "3 item: inactive
visible");
+ ok(!isLabelVisible(items[2], "dis"), "3 item: disabled
unvisible");
}
-
+
function testLast(items) {
- ok(!items[0].__header("act").is(":visible"), "1 item:
active unvisible");
- ok(items[0].__header("inact").is(":visible"), "1 item:
inactive visible");
- ok(!items[0].__header("dis").is(":visible"), "1 item:
disabled unvisible");
+ ok(!isLabelVisible(items[0], "act"), "1 item: active
unvisible");
+ ok( isLabelVisible(items[0], "inact"), "1 item: inactive
visible");
+ ok(!isLabelVisible(items[0], "dis"), "1 item: disabled
unvisible");
- ok(!items[1].__header("act").is(":visible"), "2 item:
active visible");
- ok(!items[1].__header("inact").is(":visible"), "2 item:
inactive unvisible");
- ok(items[1].__header("dis").is(":visible"), "2 item:
disabled unvisible");
+ ok(!isLabelVisible(items[1], "act"), "2 item: active
visible");
+ ok(!isLabelVisible(items[1], "inact"), "2 item: inactive
unvisible");
+ ok( isLabelVisible(items[1], "dis"), "2 item: disabled
unvisible");
- ok(items[2].__header("act").is(":visible"), "3 item:
active visible");
- ok(!items[2].__header("inact").is(":visible"), "3 item:
inactive unvisible");
- ok(!items[2].__header("dis").is(":visible"), "3 item:
disabled unvisible");
+ ok( isLabelVisible(items[2], "act"), "3 item: active
visible");
+ ok(!isLabelVisible(items[2], "inact"), "3 item: inactive
unvisible");
+ ok(!isLabelVisible(items[2], "dis"), "3 item: disabled
unvisible");
}
test("RichFaces.ui.Accordion change headers", function () {
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-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java 2011-01-06
16:14:50 UTC (rev 20911)
@@ -22,15 +22,15 @@
package org.richfaces.component;
-import java.io.IOException;
-import java.util.Map;
+import org.richfaces.renderkit.html.TogglePanelItemRenderer;
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;
-import org.richfaces.renderkit.HtmlConstants;
-
/**
* @author akolonitsky
* @version 1.0
@@ -78,11 +78,8 @@
break;
case ajax:
- context.getResponseWriter().write(getPlaceHolder());
- break;
-
case server:
- // Do nothing.
+ this.encodePlaceHolderWithJs(context);
break;
default:
@@ -91,14 +88,34 @@
}
}
- private String getPlaceHolder() {
- return "<div id=\"" + getClientId() + "\"
style=\"display: none\" ></div>";
+ 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(HtmlConstants.STYLE_ATTRIBUTE);
- attrs.put(HtmlConstants.STYLE_ATTRIBUTE, "display:none; " + style);
+ Object style = attrs.get("style");
+ attrs.put("style", "display:none; " + style);
}
public abstract String getName();
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-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/AccordionItemRenderer.java 2011-01-06
16:14:50 UTC (rev 20911)
@@ -22,24 +22,22 @@
package org.richfaces.renderkit.html;
-import static org.richfaces.renderkit.HtmlConstants.*;
-import static org.richfaces.renderkit.RenderKitUtils.renderPassThroughAttributes;
+import org.ajax4jsf.javascript.JSObject;
+import org.richfaces.component.AbstractTogglePanelTitledItem;
+import org.richfaces.component.html.HtmlAccordionItem;
+import org.richfaces.component.html.HtmlAccordionItem.PropertyKeys;
+import org.richfaces.renderkit.RenderKitUtils;
-import java.io.IOException;
-import java.util.Map;
-
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.util.Map;
-import org.ajax4jsf.javascript.JSObject;
-import org.richfaces.component.AbstractTogglePanelTitledItem;
-import org.richfaces.component.html.HtmlAccordionItem;
-import org.richfaces.component.html.HtmlAccordionItem.PropertyKeys;
-import org.richfaces.renderkit.HtmlConstants;
-import org.richfaces.renderkit.RenderKitUtils;
+import static org.richfaces.renderkit.HtmlConstants.*;
+import static org.richfaces.renderkit.RenderKitUtils.renderPassThroughAttributes;
/**
*
@@ -88,19 +86,6 @@
super.doEncodeEnd(writer, context, component);
}
- @Override
- protected void writeJavaScript(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
- Object script = getScriptObject(context, component);
- if (script == null) {
- return;
- }
-
- writer.startElement(HtmlConstants.SCRIPT_ELEM, component);
- writer.writeAttribute(HtmlConstants.TYPE_ATTR, "text/javascript",
"type");
- writer.writeText(script, null);
- writer.endElement(HtmlConstants.SCRIPT_ELEM);
- }
-
private void encodeContentBegin(UIComponent component, ResponseWriter writer) throws
IOException {
writer.startElement(DIV_ELEM, component);
writer.writeAttribute(CLASS_ATTRIBUTE, concatClasses("rf-ac-itm-cnt",
attributeAsString(component, "contentClass")), null);
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/AccordionRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/AccordionRenderer.java 2011-01-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/AccordionRenderer.java 2011-01-06
16:14:50 UTC (rev 20911)
@@ -25,17 +25,15 @@
import org.ajax4jsf.javascript.JSObject;
import org.richfaces.component.AbstractAccordion;
import org.richfaces.component.util.HtmlUtil;
-import org.richfaces.renderkit.HtmlConstants;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
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.component.html.HtmlAccordion.PropertyKeys.*;
+import static org.richfaces.component.html.HtmlAccordion.PropertyKeys.height;
+import static org.richfaces.component.html.HtmlAccordion.PropertyKeys.width;
/**
* @author akolonitsky
@@ -52,19 +50,9 @@
public class AccordionRenderer extends TogglePanelRenderer {
@Override
- protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
- super.doEncodeBegin(writer, context, component);
-
- writeJavaScript(writer, context, component);
- }
-
- @Override
protected String getStyle(UIComponent component) {
- return HtmlUtil.concatStyles(
- attributeAsStyle(component, height),
- attributeAsStyle(component, width),
-
- super.getStyle(component));
+ return HtmlUtil.concatStyles(attributeAsStyle(component, height),
attributeAsStyle(component, width),
+ super.getStyle(component));
}
@Override
@@ -73,11 +61,6 @@
}
@Override
- protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
- writer.endElement(HtmlConstants.DIV_ELEM);
- }
-
- @Override
protected Class<? extends UIComponent> getComponentClass() {
return AbstractAccordion.class;
}
@@ -92,7 +75,6 @@
protected Map<String, Object> getScriptObjectOptions(FacesContext context,
UIComponent component) {
Map<String, Object> options = super.getScriptObjectOptions(context,
component);
options.put("isKeepHeight", attributeAsString(component,
height).length() > 0);
- options.remove("items");
return options;
}
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-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/CollapsiblePanelRenderer.java 2011-01-06
16:14:50 UTC (rev 20911)
@@ -34,7 +34,6 @@
import javax.faces.context.ResponseWriter;
import java.io.IOException;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import static org.richfaces.renderkit.HtmlConstants.*;
@@ -115,10 +114,10 @@
}
@Override
- protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
comp) throws IOException {
- super.doEncodeBegin(writer, context, comp);
+ protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ super.doEncodeBegin(writer, context, component);
- encodeHeader(writer, context, (HtmlCollapsiblePanel) comp);
+ encodeHeader(writer, context, (HtmlCollapsiblePanel) component);
}
@Override
@@ -240,11 +239,6 @@
}
@Override
- protected List<JSObject> getChildrenScriptObjects(FacesContext context,
UIComponent component) {
- return null;
- }
-
- @Override
protected Class<? extends UIComponent> getComponentClass() {
return AbstractCollapsiblePanel.class;
}
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-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java 2011-01-06
16:14:50 UTC (rev 20911)
@@ -130,12 +130,14 @@
protected void writeJavaScript(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
Object script = getScriptObject(context, component);
- if (script != null) {
- writer.startElement(HtmlConstants.SCRIPT_ELEM, component);
- writer.writeAttribute(HtmlConstants.TYPE_ATTR, "text/javascript",
"type");
- writer.writeText(script, null);
- writer.endElement(HtmlConstants.SCRIPT_ELEM);
+ if (script == null) {
+ return;
}
+
+ writer.startElement(HtmlConstants.SCRIPT_ELEM, component);
+ writer.writeAttribute(HtmlConstants.TYPE_ATTR, "text/javascript",
"type");
+ writer.writeText(script, null);
+ writer.endElement(HtmlConstants.SCRIPT_ELEM);
}
protected Object getScriptObject(FacesContext context, UIComponent component) {
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TabPanelRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TabPanelRenderer.java 2011-01-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TabPanelRenderer.java 2011-01-06
16:14:50 UTC (rev 20911)
@@ -76,11 +76,11 @@
private static final String CLASS = CLASS_ATTRIBUTE;
@Override
- protected void doEncodeBegin(ResponseWriter w, FacesContext context, UIComponent
comp) throws IOException {
- super.doEncodeBegin(w, context, comp);
- writeJavaScript(w, context, comp);
+ protected void doEncodeBegin(ResponseWriter w, FacesContext context, UIComponent
component) throws IOException {
+ super.doEncodeBegin(w, context, component);
+ writeJavaScript(w, context, component);
- writeTabsLine(w, context, comp);
+ writeTabsLine(w, context, component);
writeTabsLineSeparator(w);
}
@@ -212,7 +212,6 @@
protected Map<String, Object> getScriptObjectOptions(FacesContext context,
UIComponent component) {
Map<String, Object> options = super.getScriptObjectOptions(context,
component);
options.put("isKeepHeight", attributeAsString(component,
height).length() > 0);
- options.remove("items");
return options;
}
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-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java 2011-01-06
16:14:50 UTC (rev 20911)
@@ -25,7 +25,6 @@
import org.ajax4jsf.javascript.JSObject;
import org.richfaces.component.AbstractTogglePanel;
import org.richfaces.component.AbstractTogglePanelItem;
-import org.richfaces.component.util.HtmlUtil;
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
@@ -54,17 +53,10 @@
@Override
protected String getStyleClass(UIComponent component) {
- return HtmlUtil.concatClasses("rf-tgp-itm",
attributeAsString(component, "styleClass"));
+ return concatClasses("rf-tgp-itm", attributeAsString(component,
"styleClass"));
}
@Override
- protected void writeJavaScript(ResponseWriter writer, FacesContext context,
UIComponent component)
- throws IOException {
-
- // All script should be written by TogglePanel using method getScriptObject
- }
-
- @Override
protected JSObject getScriptObject(FacesContext context, UIComponent component) {
return new JSObject("RichFaces.ui.TogglePanelItem",
component.getClientId(),
getScriptObjectOptions(context, component));
@@ -74,7 +66,7 @@
protected Map<String, Object> getScriptObjectOptions(FacesContext context,
UIComponent component) {
AbstractTogglePanelItem panelItem = (AbstractTogglePanelItem) component;
- Map<String, Object> options = new HashMap<String, Object>(5);
+ Map<String, Object> options = new HashMap<String, Object>();
options.put("name", panelItem.getName());
options.put("togglePanelId", panelItem.getParent().getClientId());
options.put("switchMode", panelItem.getSwitchType());
@@ -93,5 +85,17 @@
protected Class<? extends UIComponent> getComponentClass() {
return AbstractTogglePanelItem.class;
}
+
+ public void encodePlaceHolderWithJs(FacesContext context, AbstractTogglePanelItem
item) throws IOException {
+ ResponseWriter writer = context.getResponseWriter();
+
+ writer.startElement("div", null);
+ writer.writeAttribute("id", item.getClientId(context), null);
+ writer.writeAttribute("style", "display:none;", null);
+
+ writeJavaScript(writer, context, item);
+
+ writer.endElement("div");
+ }
}
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java 2011-01-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java 2011-01-06
16:14:50 UTC (rev 20911)
@@ -22,18 +22,6 @@
package org.richfaces.renderkit.html;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.faces.application.ResourceDependencies;
-import javax.faces.application.ResourceDependency;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSObject;
import org.ajax4jsf.javascript.JSReference;
@@ -47,6 +35,15 @@
import org.richfaces.renderkit.util.FormUtil;
import org.richfaces.renderkit.util.HandlersChain;
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @author akolonitsky
* @since -4712-01-01
@@ -105,18 +102,20 @@
}
@Override
- protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
comp) throws IOException {
- FormUtil.throwEnclFormReqExceptionIfNeed(context, comp);
+ protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ FormUtil.throwEnclFormReqExceptionIfNeed(context, component);
- super.doEncodeBegin(writer, context, comp);
- AbstractTogglePanel panel = (AbstractTogglePanel) comp;
+ super.doEncodeBegin(writer, context, component);
+ AbstractTogglePanel panel = (AbstractTogglePanel) component;
- writer.startElement(HtmlConstants.INPUT_ELEM, comp);
+ writer.startElement(HtmlConstants.INPUT_ELEM, component);
writer.writeAttribute(HtmlConstants.TYPE_ATTR, HtmlConstants.INPUT_TYPE_HIDDEN,
null);
writer.writeAttribute(HtmlConstants.VALUE_ATTRIBUTE, panel.getActiveItem(),
"activeItem");
- writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
getValueRequestParamName(context, comp), null);
- writer.writeAttribute(HtmlConstants.NAME_ATTRIBUTE,
getValueRequestParamName(context, comp), null);
+ writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
getValueRequestParamName(context, component), null);
+ writer.writeAttribute(HtmlConstants.NAME_ATTRIBUTE,
getValueRequestParamName(context, component), null);
writer.endElement(HtmlConstants.INPUT_ELEM);
+
+ writeJavaScript(writer, context, component);
}
@Override
@@ -132,6 +131,11 @@
}
@Override
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
+ writer.endElement(HtmlConstants.DIV_ELEM);
+ }
+
+ @Override
protected JSObject getScriptObject(FacesContext context, UIComponent component) {
return new JSObject("RichFaces.ui.TogglePanel",
component.getClientId(), getScriptObjectOptions(context, component));
@@ -144,7 +148,6 @@
Map<String, Object> options = new HashMap<String, Object>();
options.put("activeItem", panel.getActiveItem());
options.put("cycledSwitching", panel.isCycledSwitching());
- options.put("items", getChildrenScriptObjects(context, panel));
options.put("ajax", getAjaxOptions(context, panel));
addEventOption(context, panel, options, ITEM_CHANGE);
@@ -172,19 +175,6 @@
return AjaxRendererUtils.buildEventOptions(context, panel);
}
- protected List<JSObject> getChildrenScriptObjects(FacesContext context,
UIComponent component) {
- List<JSObject> res = new
ArrayList<JSObject>(component.getChildCount());
- for (UIComponent child : component.getChildren()) {
- res.add(getChildScriptObject(context, (AbstractTogglePanelItem) child));
- }
- return res;
- }
-
- private JSObject getChildScriptObject(FacesContext context, AbstractTogglePanelItem
child) {
- return ((TogglePanelItemRenderer) child.getRenderer(context))
- .getScriptObject(context, child);
- }
-
@Override
protected Class<? extends UIComponent> getComponentClass() {
return AbstractTogglePanel.class;
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/accordionItem.js
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/accordionItem.js 2011-01-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/accordionItem.js 2011-01-06
16:14:50 UTC (rev 20911)
@@ -38,8 +38,6 @@
* */
init : function (componentId, options) {
$super.constructor.call(this, componentId, options);
- this.index = options["index"];
- this.getTogglePanel().getItems()[this.index] = this;
if (!this.disabled) {
rf.Event.bindById(this.id + ":header", "click",
this.__onHeaderClick, this);
@@ -60,12 +58,9 @@
},
/**
- * @param state {string} = inactive | active | disabled
- * in that case looking header by css class appropriate to this state
- *
* @return {jQuery Object}
* */
- __header : function (state) {
+ __header : function () {
return $(rf.getDomElement(this.id + ":header"));
},
@@ -131,18 +126,6 @@
this.__header().removeClass("rf-ac-itm-hdr-act").addClass("rf-ac-itm-hdr-inact");
return true;
- },
-
- /***************************** Private Methods
********************************************************/
-
-
- destroy: function () {
- var parent = this.getTogglePanel();
- delete parent.getItems()[this.index];
-
- rf.Event.unbindById(this.id, "."+this.namespace);
-
- $super.destroy.call(this);
}
});
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/collapsiblePanel.js
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/collapsiblePanel.js 2011-01-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/collapsiblePanel.js 2011-01-06
16:14:50 UTC (rev 20911)
@@ -43,16 +43,18 @@
this.__addUserEventHandler("beforeswitch");
this.__addUserEventHandler("switch");
- this.items = [
+ this.options.cycledSwitching = true;
+
+ var panel = this;
+ $(document.getElementById(this.id)).ready(function () { // TODO
+ rf.Event.bindById(panel.id + ":header", "click",
panel.__onHeaderClick, panel);
+
new RichFaces.ui.CollapsiblePanelItem(
- this.id + ":content", {"index":0,
"togglePanelId":this.id, "switchMode":this.switchMode,
"name":"true"}),
+ panel.id + ":content", {"index":0,
"togglePanelId":panel.id, "switchMode":panel.switchMode,
"name":"true"}),
new RichFaces.ui.CollapsiblePanelItem(
- this.id + ":empty", {"index":1,
"togglePanelId":this.id, "switchMode":this.switchMode,
"name":"false"})
- ];
- this.options.cycledSwitching = true;
-
- rf.Event.bindById(this.id + ":header", "click",
this.__onHeaderClick, this);
+ panel.id + ":empty", {"index":1,
"togglePanelId":panel.id, "switchMode":panel.switchMode,
"name":"false"})
+ })
},
switchPanel : function (to) {
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/togglePanel.js
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/togglePanel.js 2011-01-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/togglePanel.js 2011-01-06
16:14:50 UTC (rev 20911)
@@ -156,9 +156,10 @@
$super.constructor.call(this, componentId);
this.attachToDom();
+ this.items = [];
+
this.options = $.extend(this.options, options || {});
this.activeItem = this.options.activeItem;
- this.items = this.options.items;
this.__addUserEventHandler("itemchange");
this.__addUserEventHandler("beforeitemchange");
@@ -421,10 +422,6 @@
oldItem : oldItem,
newItem : newItem
});
- },
-
- destroy: function () {
- $super.destroy.call(this);
}
});
Modified:
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/togglePanelItem.js
===================================================================
---
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/togglePanelItem.js 2011-01-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/main/resources/META-INF/resources/org.richfaces/togglePanelItem.js 2011-01-06
16:14:50 UTC (rev 20911)
@@ -30,9 +30,8 @@
name:"TogglePanelItem",
init : function (componentId, options) {
- // call constructor of parent class
$super.constructor.call(this, componentId);
- this.attachToDom();
+ this.attachToDom(this.id);
this.options = $.extend(this.options, options || {});
this.name = this.options.name;
@@ -40,6 +39,9 @@
this.switchMode = this.options.switchMode;
this.disabled = this.options.disabled || false;
+ this.index = options["index"];
+ this.getTogglePanel().getItems()[this.index] = this;
+
this.__addUserEventHandler("enter");
this.__addUserEventHandler("leave");
},
@@ -84,7 +86,7 @@
__addUserEventHandler : function (name) {
var handler = this.options["on" + name];
if (handler) {
- rf.Event.bindById(this.togglePanelId, name, handler);
+ rf.Event.bindById(this.id, name, handler);
}
},
@@ -124,6 +126,9 @@
// class stuff
destroy: function () {
+ var parent = this.getTogglePanel();
+ delete parent.getItems()[this.index];
+
$super.destroy.call(this);
}
});
Modified:
trunk/ui/output/ui/src/test/resources/org/richfaces/renderkit/html/collapsiblePanel.xmlunit.xml
===================================================================
---
trunk/ui/output/ui/src/test/resources/org/richfaces/renderkit/html/collapsiblePanel.xmlunit.xml 2011-01-06
14:24:34 UTC (rev 20910)
+++
trunk/ui/output/ui/src/test/resources/org/richfaces/renderkit/html/collapsiblePanel.xmlunit.xml 2011-01-06
16:14:50 UTC (rev 20911)
@@ -1,5 +1,8 @@
<div class="rf-cp rf-tgp" id="f:panel">
<input type="hidden" name="f:panel-value"
id="f:panel-value" value="true"></input>
+ <script type="text/javascript">
+ Text
+ </script>
<div class="rf-cp-hdr rf-cp-hdr-exp" id="f:panel:header">
<table class="rf-cp-gr">
<tbody>
@@ -22,7 +25,4 @@
</div>
<div id="f:panel:content" class="rf-cp-b"
style="display:block"></div>
<div id="f:panel:empty" style="display:none"></div>
- <script type="text/javascript">
- Text
- </script>
</div>
\ No newline at end of file