Author: Alex.Kolonitsky
Date: 2010-07-23 12:43:22 -0400 (Fri, 23 Jul 2010)
New Revision: 18220
Added:
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-mixed.xhtml
root/ui/output/trunk/panels/api/src/main/java/org/richfaces/event/ItemChangeSource.java
root/ui/output/trunk/panels/ui/src/test/java/org/richfaces/component/
root/ui/output/trunk/panels/ui/src/test/java/org/richfaces/component/AbstractTogglePanelTest.java
Modified:
root/examples/output-demo/trunk/src/main/webapp/WEB-INF/faces-config.xml
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-ajax.xhtml
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-client.xhtml
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-server.xhtml
root/examples/output-demo/trunk/src/main/webapp/templates/template.xhtml
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/event/MethodExpressionItemChangeListener.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/view/facelets/html/ItemChangeListenerHandler.java
root/ui/output/trunk/panels/ui/src/main/resources/META-INF/resources/script/TogglePanel.js
Log:
Toggle Panel bug fixing and code review
Modified: root/examples/output-demo/trunk/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- root/examples/output-demo/trunk/src/main/webapp/WEB-INF/faces-config.xml 2010-07-23
16:17:45 UTC (rev 18219)
+++ root/examples/output-demo/trunk/src/main/webapp/WEB-INF/faces-config.xml 2010-07-23
16:43:22 UTC (rev 18220)
@@ -26,6 +26,10 @@
<from-outcome>togglePanel/client</from-outcome>
<to-view-id>/examples/togglePanel-client.xhtml</to-view-id>
</navigation-case>
+ <navigation-case>
+ <from-outcome>togglePanel/mixed</from-outcome>
+ <to-view-id>/examples/togglePanel-mixed.xhtml</to-view-id>
+ </navigation-case>
<!-- QUnit -->
<navigation-case>
Modified: root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-ajax.xhtml
===================================================================
---
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-ajax.xhtml 2010-07-23
16:17:45 UTC (rev 18219)
+++
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-ajax.xhtml 2010-07-23
16:43:22 UTC (rev 18220)
@@ -14,7 +14,7 @@
<ui:define name="body">
<f:view>
<h:form id="f">
- <pn:togglePanel id="my_id" activeItem="name1"
switchType="ajax"
+ <pn:togglePanel id="panel" activeItem="name1"
switchType="ajax"
itemChangeListener="#{togglePanelBean.itemChangeActionListener}" >
<pn:togglePanelItem name="name1">hello
name1</pn:togglePanelItem>
<pn:togglePanelItem name="name2">hello
name2</pn:togglePanelItem>
@@ -22,19 +22,40 @@
</pn:togglePanel>
<h:outputLink>
- <pn:toggleControl forPanel="my_id"
targetItem="name1" event="click" />
+ <pn:toggleControl forPanel="panel"
targetItem="name1" event="click" />
name1
</h:outputLink>
|
<h:outputLink>
- <pn:toggleControl forPanel="my_id"
targetItem="name2" event="click" />
+ <pn:toggleControl forPanel="panel"
targetItem="name2" event="click" />
name2
</h:outputLink>
|
<h:outputLink>
- <pn:toggleControl forPanel="my_id"
targetItem="name3" event="click" />
+ <pn:toggleControl forPanel="panel"
targetItem="name3" event="click" />
name3
</h:outputLink>
+
+ <br/>
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@first" event="click"/>
+ |< first
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@prev" event="click"/>
+ <- prev
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@next" event="click"/>
+ next ->
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@last" event="click"/>
+ last >|
+ </h:outputLink>
</h:form>
</f:view>
</ui:define>
Modified:
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-client.xhtml
===================================================================
---
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-client.xhtml 2010-07-23
16:17:45 UTC (rev 18219)
+++
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-client.xhtml 2010-07-23
16:43:22 UTC (rev 18220)
@@ -23,14 +23,37 @@
<pn:toggleControl forPanel="panel"
targetItem="name1" event="click" />
name1
</h:outputLink>
+ |
<h:outputLink>
<pn:toggleControl forPanel="panel"
targetItem="name2" event="click" />
name2
</h:outputLink>
+ |
<h:outputLink>
<pn:toggleControl forPanel="panel"
targetItem="name3" event="click" />
name3
</h:outputLink>
+
+ <br />
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@first" event="click" />
+ |< first
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@prev" event="click" />
+ <- prev
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@next" event="click" />
+ next ->
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@last" event="click" />
+ last >|
+ </h:outputLink>
</h:form>
</ui:define>
</ui:composition>
Added: root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-mixed.xhtml
===================================================================
--- root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-mixed.xhtml
(rev 0)
+++
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-mixed.xhtml 2010-07-23
16:43:22 UTC (rev 18220)
@@ -0,0 +1,61 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:pn="http://richfaces.org/output">
+
+<body>
+<ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="title">Toggle Panel Example</ui:define>
+ <ui:define name="body_head">Toggle Panel Example - Client &
Ajax SwitchType</ui:define>
+
+ <ui:define name="body">
+ <h:form id="f">
+ <pn:togglePanel id="panel" activeItem="name1"
switchType="client" lang="en">
+ <pn:togglePanelItem name="name1">hello name1
client</pn:togglePanelItem>
+ <pn:togglePanelItem name="name2"
switchType="ajax">hello name2 ajax</pn:togglePanelItem>
+ <pn:togglePanelItem name="name3"
switchType="server">hello name3 server</pn:togglePanelItem>
+ </pn:togglePanel>
+
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="name1" event="click" />
+ name1 client
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="name2" event="click" />
+ name2 ajax
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="name3" event="click" />
+ name3 server
+ </h:outputLink>
+
+ <br />
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@first" event="click" />
+ |< first
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@prev" event="click" />
+ <- prev
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@next" event="click" />
+ next ->
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@last" event="click" />
+ last >|
+ </h:outputLink>
+ </h:form>
+ </ui:define>
+</ui:composition>
+</body>
+</html>
Modified:
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-server.xhtml
===================================================================
---
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-server.xhtml 2010-07-23
16:17:45 UTC (rev 18219)
+++
root/examples/output-demo/trunk/src/main/webapp/examples/togglePanel-server.xhtml 2010-07-23
16:43:22 UTC (rev 18220)
@@ -14,24 +14,47 @@
<ui:define name="body">
<f:view>
<h:form id="f">
- <pn:togglePanel id="my_id" activeItem="name1"
switchType="server" lang="en">
+ <pn:togglePanel id="panel" activeItem="name1"
switchType="server" lang="en">
<pn:togglePanelItem name="name1">hello
name1</pn:togglePanelItem>
<pn:togglePanelItem name="name2">hello
name2</pn:togglePanelItem>
<pn:togglePanelItem name="name3">hello
name3</pn:togglePanelItem>
</pn:togglePanel>
<h:outputLink>
- <pn:toggleControl forPanel="my_id"
targetItem="name1" event="click" />
+ <pn:toggleControl forPanel="panel"
targetItem="name1" event="click" />
name1
</h:outputLink>
+ |
<h:outputLink>
- <pn:toggleControl forPanel="my_id"
targetItem="name2" event="click" />
+ <pn:toggleControl forPanel="panel"
targetItem="name2" event="click" />
name2
</h:outputLink>
+ |
<h:outputLink>
- <pn:toggleControl forPanel="my_id"
targetItem="name3" event="click" />
+ <pn:toggleControl forPanel="panel"
targetItem="name3" event="click" />
name3
</h:outputLink>
+
+ <br/>
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@first" event="click"/>
+ |< first
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@prev" event="click"/>
+ <- prev
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@next" event="click"/>
+ next ->
+ </h:outputLink>
+ |
+ <h:outputLink>
+ <pn:toggleControl forPanel="panel"
targetItem="@last" event="click"/>
+ last >|
+ </h:outputLink>
</h:form>
</f:view>
</ui:define>
Modified: root/examples/output-demo/trunk/src/main/webapp/templates/template.xhtml
===================================================================
--- root/examples/output-demo/trunk/src/main/webapp/templates/template.xhtml 2010-07-23
16:17:45 UTC (rev 18219)
+++ root/examples/output-demo/trunk/src/main/webapp/templates/template.xhtml 2010-07-23
16:43:22 UTC (rev 18220)
@@ -34,6 +34,7 @@
<li><h:commandLink value="togglePanel
Ajax" action="togglePanel/ajax" /></li>
<li><h:commandLink value="togglePanel
Client" action="togglePanel/client" /></li>
<li><h:commandLink value="togglePanel
Server" action="togglePanel/server" /></li>
+ <li><h:commandLink value="togglePanel
Mixed" action="togglePanel/mixed" /></li>
</ul>
<p>QUnit</p>
<ul>
Modified:
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
===================================================================
---
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-07-23
16:17:45 UTC (rev 18219)
+++
root/ui/core/trunk/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-07-23
16:43:22 UTC (rev 18220)
@@ -105,7 +105,7 @@
options.put("pushId", push.getListenerId(context));
options.put("clientId", component.getClientId(context));
- HandlersChain handlersChain = new HandlersChain(facesContext, push);
+ HandlersChain handlersChain = new HandlersChain(context, push);
handlersChain.addInlineHandlerFromAttribute(AbstractPush.ON_DATA_AVAILABLE);
handlersChain.addBehaviors(AbstractPush.DATA_AVAILABLE);
handlersChain.addAjaxSubmitFunction();
Added:
root/ui/output/trunk/panels/api/src/main/java/org/richfaces/event/ItemChangeSource.java
===================================================================
---
root/ui/output/trunk/panels/api/src/main/java/org/richfaces/event/ItemChangeSource.java
(rev 0)
+++
root/ui/output/trunk/panels/api/src/main/java/org/richfaces/event/ItemChangeSource.java 2010-07-23
16:43:22 UTC (rev 18220)
@@ -0,0 +1,36 @@
+package org.richfaces.event;
+
+/**
+ * @author akolonitsky
+ * @since Jul 20, 2010
+ */
+public interface ItemChangeSource {
+
+ /**
+ * <p>Add a new {@link org.richfaces.event.ItemChangeListener} to the set of
listeners
+ * interested in being notified when {@link org.richfaces.event.ItemChangeEvent}s
occur.</p>
+ *
+ * @param listener The {@link org.richfaces.event.ItemChangeListener} to be added
+ * @throws NullPointerException if <code>listener</code>
+ * is <code>null</code>
+ */
+ void addItemChangeListener(ItemChangeListener listener);
+
+ /**
+ * <p>Return the set of registered {@link
org.richfaces.event.ItemChangeListener}s for this instance.
+ * If there are no registered listeners, a zero-length array is returned.</p>
+ */
+ ItemChangeListener[] getItemChangeListeners();
+
+ /**
+ * <p>Remove an existing {@link org.richfaces.event.ItemChangeListener} (if
any) from the
+ * set of listeners interested in being notified when
+ * {@link org.richfaces.event.ItemChangeEvent}s occur.</p>
+ *
+ * @param listener The {@link org.richfaces.event.ItemChangeListener} to be removed
+ * @throws NullPointerException if <code>listener</code>
+ * is <code>null</code>
+ */
+ void removeItemChangeListener(ItemChangeListener listener);
+
+}
Modified:
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
===================================================================
---
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java 2010-07-23
16:17:45 UTC (rev 18219)
+++
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java 2010-07-23
16:43:22 UTC (rev 18220)
@@ -22,20 +22,19 @@
package org.richfaces.component;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import org.richfaces.component.util.MessageUtil;
+import org.richfaces.event.ItemChangeEvent;
+import org.richfaces.event.ItemChangeListener;
+import org.richfaces.event.ItemChangeSource;
import javax.el.ELException;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
-import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.component.UpdateModelException;
import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ExceptionQueuedEvent;
import javax.faces.event.ExceptionQueuedEventContext;
@@ -43,18 +42,15 @@
import javax.faces.event.PhaseId;
import javax.faces.event.PostValidateEvent;
import javax.faces.event.PreValidateEvent;
-import javax.faces.event.ValueChangeListener;
-import javax.faces.validator.Validator;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
-import org.richfaces.component.util.MessageUtil;
-import org.richfaces.event.ItemChangeEvent;
-import org.richfaces.event.ItemChangeListener;
-
/**
* @author akolonitsky
* @version 1.0
*/
-public abstract class AbstractTogglePanel extends AbstractDivPanel implements
EditableValueHolder {
+public abstract class AbstractTogglePanel extends AbstractDivPanel implements
ItemChangeSource {
public static final String COMPONENT_TYPE = "org.richfaces.TogglePanel";
@@ -94,18 +90,10 @@
this.submittedActiveItem = String.valueOf(submittedValue);
}
- /**
- * Return the "local value set" state for this component.
- * Calls to <code>setValue()</code> automatically reset
- * this property to <code>true</code>.
- */
public boolean isLocalValueSet() {
return (Boolean) getStateHelper().eval(PropertyKeys.localValueSet, false);
}
- /**
- * Sets the "local value set" state for this component.
- */
public void setLocalValueSet(boolean localValueSet) {
getStateHelper().put(PropertyKeys.localValueSet, localValueSet);
}
@@ -119,9 +107,6 @@
getStateHelper().put(PropertyKeys.valid, valid);
}
- /**
- * <p>Return the "required field" state for this
component.</p>
- */
public boolean isRequired() {
return (Boolean) getStateHelper().eval(PropertyKeys.required, false);
}
@@ -145,46 +130,6 @@
getStateHelper().put(PropertyKeys.immediate, immediate);
}
- public MethodBinding getValidator() {
- throw new UnsupportedOperationException();
- }
-
- public void setValidator(MethodBinding validatorBinding) {
- throw new UnsupportedOperationException();
- }
-
- public MethodBinding getValueChangeListener() {
- throw new UnsupportedOperationException();
- }
-
- public void setValueChangeListener(MethodBinding valueChangeMethod) {
- throw new UnsupportedOperationException();
- }
-
- public void addValidator(Validator validator) {
- throw new UnsupportedOperationException();
- }
-
- public Validator[] getValidators() {
- throw new UnsupportedOperationException();
- }
-
- public void removeValidator(Validator validator) {
- throw new UnsupportedOperationException();
- }
-
- public void addValueChangeListener(ValueChangeListener listener) {
- throw new UnsupportedOperationException();
- }
-
- public ValueChangeListener[] getValueChangeListeners() {
- throw new UnsupportedOperationException();
- }
-
- public void removeValueChangeListener(ValueChangeListener listener) {
- throw new UnsupportedOperationException();
- }
-
// ----------------------------------------------------- UIComponent Methods
/**
@@ -397,9 +342,6 @@
}
}
- /**
- * Executes validation logic.
- */
private void executeValidate(FacesContext context) {
try {
validate(context);
@@ -433,6 +375,7 @@
}
}
+ @Override
public void queueEvent(FacesEvent event) {
if ((event instanceof ItemChangeEvent) && (event.getComponent() == this))
{
if (isImmediate()) {
@@ -468,10 +411,6 @@
return true;
}
- private boolean isActiveItem(UIComponent kid) {
- return getChildName(kid).equals(getActiveItemValue());
- }
-
private String getActiveItemValue() {
String value = getActiveItem();
if (value == null) {
@@ -480,78 +419,103 @@
return value;
}
- private static boolean isActiveItem(UIComponent kid, String value) {
+ protected boolean isActiveItem(UIComponent kid) {
+ return isActiveItem(kid, getActiveItemValue());
+ }
+
+ protected static boolean isActiveItem(UIComponent kid, String value) {
+ if (kid == null || value == null) {
+ return false;
+ }
+
return getChildName(kid).equals(value);
}
- public String getFirstItem() {
- List<UIComponent> children = getRenderedChildren();
-// if (chi)
+ private static String getChildName(UIComponent item) {
+ if (item == null) {
+ return null;
+ }
- return getChildName(children.get(0));
+ if (!(item instanceof AbstractTogglePanelItem)) {
+ throw new IllegalArgumentException();
+ }
+
+ return ((AbstractTogglePanelItem) item).getName();
}
+
+ public AbstractTogglePanelItem getItemByIndex(final int index) {
+ List<AbstractTogglePanelItem> children = getRenderedChildren();
+ if (index < 0 || index >= children.size()) {
+ return null;
+ }
-// public UIComponent getItemByIndex
+ return children.get(index);
+ }
- private List<UIComponent> getRenderedChildren() {
- List<UIComponent> res = new ArrayList<UIComponent>(getChildCount());
+ private List<AbstractTogglePanelItem> getRenderedChildren() {
+ List<AbstractTogglePanelItem> res = new
ArrayList<AbstractTogglePanelItem>(getChildCount());
for (UIComponent child : getChildren()) {
- res.add(child);
+ if (child.isRendered() && child instanceof AbstractTogglePanelItem)
{
+ res.add((AbstractTogglePanelItem) child);
+ }
}
return res;
}
public AbstractTogglePanelItem getItem(String name) {
- if (name == null) {
- throw new IllegalArgumentException("Name is required parameter.");
+ if ("(a)first".equals(name)) {
+ return getFirstItem();
+ } else if ("(a)prev".equals(name)) {
+ return getPrevItem();
+ } else if ("(a)next".equals(name)) {
+ return getNextItem();
+ } else if ("(a)last".equals(name)) {
+ return getLastItem();
+ } else {
+ return getItemByIndex(getChildIndex(name));
}
+ }
- List<UIComponent> children = getChildren();
- int index = getChildIndex(name, children);
- if (index == -1) {
- return null;
- }
- return (AbstractTogglePanelItem) children.get(index);
+ public AbstractTogglePanelItem getFirstItem() {
+ return getItemByIndex(0);
}
- public String getNext(String name) {
- if (name == null) {
- throw new IllegalArgumentException("Name is required parameter.");
- }
+ public AbstractTogglePanelItem getPrevItem() {
+ return getPrevItem(getActiveItem());
+ }
- List<UIComponent> children = getChildren();
+ public AbstractTogglePanelItem getPrevItem(String name) {
+ return getItemByIndex(getChildIndex(name) - 1);
+ }
- int nextItem = getChildIndex(name, children) + 1;
- if (nextItem < children.size()) {
- return getFirstItem();
- } else {
- return getChildName(children.get(nextItem));
- }
+ public AbstractTogglePanelItem getNextItem() {
+ return getNextItem(getActiveItem());
}
- private static int getChildIndex(String name, List<UIComponent> children) {
- int ind = 0;
- while (ind < children.size()) {
- UIComponent child = children.get(ind);
- if (name.equals(getChildName(child))) {
+ public AbstractTogglePanelItem getNextItem(String name) {
+ return getItemByIndex(getChildIndex(name) + 1);
+ }
+
+ public AbstractTogglePanelItem getLastItem() {
+ return getItemByIndex(getRenderedChildren().size() - 1);
+ }
+
+ private int getChildIndex(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("Name is required parameter.");
+ }
+
+ List<AbstractTogglePanelItem> items = getRenderedChildren();
+ for (int ind = 0; ind < items.size(); ind++) {
+ if (name.equals(items.get(ind).getName())) {
return ind;
}
- ind++;
}
- return -1;
+ return Integer.MIN_VALUE;
}
- private static String getChildName(UIComponent item) {
- // TODO nick - panel can include UIParam children - remove this exception
- if (!(item instanceof AbstractTogglePanelItem)) {
- throw new IllegalStateException("TogglePanel can contain only
TogglePanelItem as child.");
- }
-
- return ((AbstractTogglePanelItem) item).getName();
- }
-
// ------------------------------------------------
public String getSubmittedActiveItem() {
@@ -593,35 +557,14 @@
// ------------------------------------------------ Event Processing Methods
- /**
- * <p>Add a new {@link org.richfaces.event.ItemChangeListener} to the set of
listeners
- * interested in being notified when {@link org.richfaces.event.ItemChangeEvent}s
occur.</p>
- *
- * @param listener The {@link org.richfaces.event.ItemChangeListener} to be added
- * @throws NullPointerException if <code>listener</code>
- * is <code>null</code>
- */
public void addItemChangeListener(ItemChangeListener listener) {
addFacesListener(listener);
}
- /**
- * <p>Return the set of registered {@link
org.richfaces.event.ItemChangeListener}s for this instance.
- * If there are no registered listeners, a zero-length array is returned.</p>
- */
public ItemChangeListener[] getItemChangeListeners() {
return (ItemChangeListener[]) getFacesListeners(ItemChangeListener.class);
}
- /**
- * <p>Remove an existing {@link org.richfaces.event.ItemChangeListener} (if
any) from the
- * set of listeners interested in being notified when
- * {@link org.richfaces.event.ItemChangeEvent}s occur.</p>
- *
- * @param listener The {@link org.richfaces.event.ItemChangeListener} to be removed
- * @throws NullPointerException if <code>listener</code>
- * is <code>null</code>
- */
public void removeItemChangeListener(ItemChangeListener listener) {
removeFacesListener(listener);
}
Modified:
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java
===================================================================
---
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java 2010-07-23
16:17:45 UTC (rev 18219)
+++
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/component/AbstractTogglePanelItem.java 2010-07-23
16:43:22 UTC (rev 18220)
@@ -22,9 +22,12 @@
package org.richfaces.component;
+import org.ajax4jsf.renderkit.RendererUtils;
+
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.render.Renderer;
+import java.io.IOException;
/**
* @author akolonitsky
@@ -47,14 +50,6 @@
}
@Override
- public void setParent(UIComponent parent) {
- if (parent != null && !(parent instanceof AbstractTogglePanel)) {
- throw new IllegalArgumentException("Parent of TogglePanelItem can be
only TogglePanel.");
- }
- super.setParent(parent);
- }
-
- @Override
public AbstractTogglePanel getParent() {
return (AbstractTogglePanel) super.getParent();
}
@@ -64,6 +59,41 @@
return super.getRenderer(context);
}
+ @Override
+ public void encodeAll(FacesContext context) throws IOException {
+ if (getParent().isActiveItem(this)) {
+ super.encodeAll(context);
+ } else {
+ switch (getSwitchType()) {
+ case client:
+ hidePanelItem(this);
+
+ super.encodeAll(context);
+ break;
+
+ case ajax:
+ context.getResponseWriter().write(getPlaceHolder());
+ break;
+
+ case server:
+ // Do nothing.
+ break;
+
+ default:
+ throw new IllegalStateException("Unknown switch type : " +
getSwitchType());
+ }
+ }
+ }
+
+ private String getPlaceHolder() {
+ return "<div id=\"" + getClientId() + "\"
style=\"display: none\" ></div>";
+ }
+
+ private static void hidePanelItem(UIComponent item) {
+ //TODO nick - attributes shouldn't be overwritten
+ item.getAttributes().put(RendererUtils.HTML.STYLE_ATTRIBUTE,
"display:none");
+ }
+
public abstract String getName();
public abstract SwitchType getSwitchType();
@@ -72,3 +102,6 @@
return "TogglePanelItem {name: " + getName() + ", switchType:
" + getSwitchType() + '}';
}
}
+
+
+
Modified:
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/event/MethodExpressionItemChangeListener.java
===================================================================
---
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/event/MethodExpressionItemChangeListener.java 2010-07-23
16:17:45 UTC (rev 18219)
+++
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/event/MethodExpressionItemChangeListener.java 2010-07-23
16:43:22 UTC (rev 18220)
@@ -73,7 +73,7 @@
* <code>MethodExpression</code> whose expected param types match
* those of a zero argument method. The usage requirements for both
* of these <code>MethodExpression</code> instances are described in
- * {@link #processItemChange}.</span></p>
+ * {@link #processItemChange}.</p>
*
* @param methodExpressionOneArg a <code>MethodExpression</code>
* that points to a method that returns <code>void</code> and takes
@@ -87,8 +87,8 @@
ELContext elContext = context.getELContext();
this.methodExpressionZeroArg = context.getApplication().
getExpressionFactory().createMethodExpression(elContext,
- methodExpressionOneArg.getExpressionString(), Void.class,
- ITEM_CHANGE_LISTENER_ZERO_ARG_SIG);
+ methodExpressionOneArg.getExpressionString(), Void.class,
+ ITEM_CHANGE_LISTENER_ZERO_ARG_SIG);
}
/**
@@ -183,8 +183,10 @@
return;
}
- methodExpressionOneArg = (MethodExpression)
UIComponentBase.restoreAttachedState(context, ((Object[]) state)[0]);
- methodExpressionZeroArg = (MethodExpression)
UIComponentBase.restoreAttachedState(context, ((Object[]) state)[1]);
+ methodExpressionOneArg = (MethodExpression) UIComponentBase
+ .restoreAttachedState(context, ((Object[]) state)[0]);
+ methodExpressionZeroArg = (MethodExpression) UIComponentBase
+ .restoreAttachedState(context, ((Object[]) state)[1]);
}
Modified:
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
===================================================================
---
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java 2010-07-23
16:17:45 UTC (rev 18219)
+++
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java 2010-07-23
16:43:22 UTC (rev 18220)
@@ -30,6 +30,7 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.AbstractDivPanel;
@@ -61,19 +62,10 @@
writer.startElement(HTML.DIV_ELEM, component);
writer.writeAttribute("id", component.getClientId(context),
"clientId");
- writeAttributes(writer, component, ATTRIBUTES);
+ RendererUtils.getInstance()
+ .encodeAttributesFromArray(context, component, ATTRIBUTES);
}
- private void writeAttributes(ResponseWriter writer, UIComponent component, String[]
attributes) throws IOException {
- Map<String, Object> componentAttributes = component.getAttributes();
- for (String attrName : attributes) {
- Object attrValue = componentAttributes.get(attrName);
- if (!"null".equalsIgnoreCase(String.valueOf(attrValue))) {
- writer.writeAttribute(attrName, attrValue, attrName); // TODO Use
RendererUtils use writeAttribute
- }
- }
- }
-
@Override
protected void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent
component) throws IOException {
super.doEncodeEnd(writer, context, component);
@@ -86,8 +78,6 @@
protected void writeJavaScript(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
Object script = getScriptObject(context, component);
if (script != null) {
-
- // TODO nick - how does script relate to DIV?
writer.startElement(HTML.SCRIPT_ELEM, component);
writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript",
"type");
writer.writeText(script, null);
Modified:
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java
===================================================================
---
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java 2010-07-23
16:17:45 UTC (rev 18219)
+++
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelItemRenderer.java 2010-07-23
16:43:22 UTC (rev 18220)
@@ -46,26 +46,35 @@
@ResourceDependency(name = "richfaces-base-component.js"),
@ResourceDependency(name = "script/TogglePanelItem.js") })
public class TogglePanelItemRenderer extends DivPanelRenderer {
+
+ private static final String LEAVE = "leave";
+ private static final String ENTER = "enter";
@Override
- protected void writeJavaScript(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
- // All script must be written by TogglePanel using method getScriptObject
+ 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));
+ return new JSObject("RichFaces.ui.TogglePanelItem",
component.getClientId(),
+ getScriptObjectOptions(context, component));
}
@Override
protected Map<String, Object> getScriptObjectOptions(FacesContext context,
UIComponent component) {
AbstractTogglePanelItem panelItem = (AbstractTogglePanelItem) component;
- Map<String, Object> options = new HashMap<String, Object>(2);
+ Map<String, Object> options = new HashMap<String, Object>(5);
options.put("name", panelItem.getName());
options.put("togglePanelId", panelItem.getParent().getClientId());
options.put("switchMode", panelItem.getSwitchType());
+ TogglePanelRenderer.addEventOption(context, component, options, LEAVE);
+ TogglePanelRenderer.addEventOption(context, component, options, ENTER);
+
return options;
}
Modified:
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
===================================================================
---
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java 2010-07-23
16:17:45 UTC (rev 18219)
+++
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java 2010-07-23
16:43:22 UTC (rev 18220)
@@ -22,26 +22,28 @@
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.context.AjaxContext;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSObject;
+import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.renderkit.AjaxEventOptions;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.HandlersChain;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.AbstractTogglePanel;
import org.richfaces.component.AbstractTogglePanelItem;
+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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
/**
* @author akolonitsky
* @since -4712-01-01
@@ -57,39 +59,40 @@
private static final String VALUE_POSTFIX = "-value";
+ private static final String ON = "on";
+ private static final String ITEM_CHANGE = "itemchange";
+ private static final String BEFORE_ITEM_CHANGE = "beforeitemchange";
+
@Override
protected void doDecode(FacesContext context, UIComponent component) {
+ AbstractTogglePanel panel = (AbstractTogglePanel) component;
+
Map<String, String> requestMap =
context.getExternalContext().getRequestParameterMap();
// Don't overwrite the value unless you have to!
String newValue = requestMap.get(getActiveItemRequestParamName(context,
component));
if (newValue != null) {
- setSubmittedValue(component, newValue);
-
-// if (logger.isLoggable(Level.FINE)) {
-// logger.log(Level.FINE, "new value after decoding {0}",
newValue);
-// }
+ panel.setSubmittedActiveItem(newValue);
}
String compClientId = component.getClientId(context);
String clientId = requestMap.get(compClientId);
if (clientId != null && clientId.equals(compClientId)) {
- AbstractTogglePanel panel = (AbstractTogglePanel) component;
AbstractTogglePanelItem panelItem = panel.getItem(newValue);
if (panelItem != null) {
context.getPartialViewContext().getRenderIds().add(panelItem.getClientId(context));
//TODO nick - this should be done on encode, not on decode
- addOnCompleteParam(newValue, panel);
+ addOnCompleteParam(newValue, panel.getClientId());
}
}
}
- private void addOnCompleteParam(String newValue, AbstractTogglePanel panel) {
+ private static void addOnCompleteParam(String newValue, String panelId) {
StringBuilder onComplete = new StringBuilder();
-
onComplete.append("RichFaces.$('").append(panel.getClientId()).append("').onCompleteHandler('")
-
.append(panel.getActiveItem()).append("','").append(newValue).append("');");
+ onComplete.append("RichFaces.$('").append(panelId)
+
.append("').onCompleteHandler('").append(newValue).append("');");
AjaxContext.getCurrentInstance().appendOncomplete(onComplete.toString());
}
@@ -98,24 +101,6 @@
return component.getClientId(context) + VALUE_POSTFIX;
}
-// @Override
- public void setSubmittedValue(UIComponent component, Object value) {
- if (component instanceof AbstractTogglePanel) {
- ((AbstractTogglePanel) component).setSubmittedActiveItem((String) value);
-
-// if (logger.isLoggable(Level.FINE)) {
-// logger.fine("Set submitted value " + value + " on
component ");
-// }
- }
-
- }
-
-
-// @Override
-// public boolean getRendersChildren() {
-// return true;
-// }
-
@Override
protected void doEncodeBegin(ResponseWriter writer, FacesContext context, UIComponent
comp) throws IOException {
super.doEncodeBegin(writer, context, comp);
@@ -130,85 +115,48 @@
}
@Override
- protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
- if (component.getChildCount() <= 0) {
- return;
- }
-
- //TODO nick - non-rendered items shouldn't be processed
- for (UIComponent child : component.getChildren()) {
- if (!(child instanceof AbstractTogglePanelItem)) {
- throw new IllegalStateException("Child of TogglePanel can be only
TogglePanelItem");
- }
-
- doEncodeChild(context, (AbstractTogglePanel) component,
(AbstractTogglePanelItem) child);
- }
- }
-
- private void doEncodeChild(FacesContext facesContext, AbstractTogglePanel panel,
AbstractTogglePanelItem item)
+ protected void doEncodeChildren(ResponseWriter writer, FacesContext context,
UIComponent component)
throws IOException {
-
- boolean isSelected = panel.getActiveItem().equals(item.getName());
- if (isSelected) {
- item.encodeAll(facesContext);
-
- } else {
-
- switch (item.getSwitchType()) {
- case client:
- hidePanelItem(item);
-
- item.encodeAll(facesContext);
- break;
-
- case ajax:
- if (!item.isRendered()) {
- break;
- }
-
- hidePanelItem(item);
- item.encodeBegin(facesContext);
- item.encodeEnd(facesContext);
- break;
-
- case server:
- // Do nothing.
- break;
-
- default:
- throw new IllegalStateException("Unknown switch type : " +
item.getSwitchType());
- }
- }
-
-
+
+ renderChildren(context, component);
}
- // TODO why item don't know how it should be rendered
- private static void hidePanelItem(UIComponent item) {
- //TODO nick - attributes shouldn't be overwritten
-
- item.getAttributes().put(HTML.STYLE_ATTRIBUTE, "display:none");
- }
-
@Override
protected JSObject getScriptObject(FacesContext context, UIComponent component) {
- return new JSObject("RichFaces.ui.TogglePanel",
component.getClientId(), getScriptObjectOptions(context, component));
+ return new JSObject("RichFaces.ui.TogglePanel",
+ component.getClientId(), getScriptObjectOptions(context, component));
}
@Override
protected Map<String, Object> getScriptObjectOptions(FacesContext context,
UIComponent component) {
AbstractTogglePanel panel = (AbstractTogglePanel) component;
- Map<String, Object> options = new HashMap<String, Object>(3);
+ Map<String, Object> options = new HashMap<String, Object>(5);
options.put("activeItem", panel.getValue());
- options.put("switchMode", panel.getSwitchType());
options.put("items", getChildrenScriptObjects(context, panel));
-
options.put("ajax", getAjaxOptions(context, panel));
+ addEventOption(context, panel, options, ITEM_CHANGE);
+ addEventOption(context, panel, options, BEFORE_ITEM_CHANGE);
+
return options;
}
+ public static void addEventOption(FacesContext context, UIComponent component,
Map<String, Object> options,
+ String eventName) {
+
+ HandlersChain handlersChain = new HandlersChain(context, component);
+ handlersChain.addInlineHandlerFromAttribute(ON + eventName);
+ handlersChain.addBehaviors(eventName);
+ handlersChain.addAjaxSubmitFunction();
+
+ String handler = handlersChain.toScript();
+ if (handler != null) {
+ options.put(ON + eventName,
+ new JSFunctionDefinition(JSReference.EVENT).addToBody(handler));
+ }
+ }
+
private static AjaxEventOptions getAjaxOptions(FacesContext context, UIComponent
panel) {
return AjaxRendererUtils.buildEventOptions(context, panel);
}
Modified:
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/view/facelets/html/ItemChangeListenerHandler.java
===================================================================
---
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/view/facelets/html/ItemChangeListenerHandler.java 2010-07-23
16:17:45 UTC (rev 18219)
+++
root/ui/output/trunk/panels/ui/src/main/java/org/richfaces/view/facelets/html/ItemChangeListenerHandler.java 2010-07-23
16:43:22 UTC (rev 18220)
@@ -25,6 +25,7 @@
import org.richfaces.component.AbstractTogglePanel;
import org.richfaces.event.ItemChangeEvent;
import org.richfaces.event.ItemChangeListener;
+import org.richfaces.event.ItemChangeSource;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
@@ -38,7 +39,6 @@
import javax.faces.view.facelets.TagConfig;
import javax.faces.view.facelets.TagException;
import javax.faces.view.facelets.TagHandler;
-import java.io.IOException;
import java.io.Serializable;
/**
@@ -113,7 +113,7 @@
}
}
- public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
+ public void apply(FaceletContext ctx, UIComponent parent) {
// only process if it's been created
if (parent == null || !ComponentHandler.isNew(parent)) {
@@ -126,7 +126,7 @@
// Allow the composite component to know about the target component.
TagHandlerUtils.getOrCreateRetargetableHandlersList(parent).add(this);
} else {
- throw new TagException(this.tag, "Parent is not of type
EditableValueHolder, type is: " + parent);
+ throw new TagException(this.tag, "Parent is not of type
AbstractTogglePanel, type is: " + parent);
}
}
@@ -137,8 +137,7 @@
valueExpr = this.binding.getValueExpression(ctx, ItemChangeListener.class);
}
- AbstractTogglePanel evh = (AbstractTogglePanel) parent;
- //TODO nick - this should be done via API interface define interfaces
SelectedItemChangeSource
+ ItemChangeSource evh = (ItemChangeSource) parent;
evh.addItemChangeListener(new LazyItemChangeListener(this.listenerType,
valueExpr));
}
Modified:
root/ui/output/trunk/panels/ui/src/main/resources/META-INF/resources/script/TogglePanel.js
===================================================================
---
root/ui/output/trunk/panels/ui/src/main/resources/META-INF/resources/script/TogglePanel.js 2010-07-23
16:17:45 UTC (rev 18219)
+++
root/ui/output/trunk/panels/ui/src/main/resources/META-INF/resources/script/TogglePanel.js 2010-07-23
16:43:22 UTC (rev 18220)
@@ -38,11 +38,11 @@
* @return {void}
* */
exec : function (oldPanel, newPanel) {
- if (this.comp.switchMode == "server") {
+ if (newPanel.switchMode == "server") {
return this.execServer(oldPanel, newPanel);
- } else if (this.comp.switchMode == "ajax") {
+ } else if (newPanel.switchMode == "ajax") {
return this.execAjax(oldPanel, newPanel);
- } else if (this.comp.switchMode == "client") {
+ } else if (newPanel.switchMode == "client") {
return this.execClient(oldPanel, newPanel);
} else {
rf.log.error("SwitchItems.exec : unknown switchMode (" +
this.comp.switchMode + ")");
@@ -130,8 +130,17 @@
* */
__getValueInputId: function () {
return this.comp.id + "-value"
- }
+ },
+ /********************* Events *************************/
+
+ __fireItemChange : function (oldItem, newItem) {
+ return new rf.Event.fireById(this.comp.id, "itemchange", {
+ id: this.comp.id,
+ oldItem : oldItem,
+ newItem : newItem
+ });
+ }
};
/**
@@ -154,7 +163,6 @@
this.options = options;
this.activeItem = this.options.activeItem;
- this.switchMode = this.options.switchMode;
this.items = this.options.items;
},
@@ -220,9 +228,9 @@
* please, remove this method when client side ajax events will be added
*
* */
- onCompleteHandler : function (oldItemName, newItemName) {
- var oldItem = this.__getItemByName(this.items, oldItemName);
- var newItem = this.__getItemByName(this.items, newItemName);
+ onCompleteHandler : function (newItemName) {
+ var oldItem = this.__getItemByName(this.activeItem);
+ var newItem = this.__getItemByName(newItemName);
// Don't do like this and remove it ASAP
new SwitchItems(this).execClient(oldItem, newItem);
@@ -266,7 +274,7 @@
return null;
}
- return this.__getItemName(this.items, itemIndex + 1);
+ return this.__getItemName(itemIndex + 1);
},
/**
@@ -276,7 +284,7 @@
* @return {String} name of first panel item
*/
firstItem: function () {
- return this.__getItemName(this.items, 0);
+ return this.__getItemName(0);
},
/**
@@ -286,7 +294,7 @@
* @return {String} name of last panel item
*/
lastItem: function () {
- return this.__getItemName(this.items, this.items.length - 1);
+ return this.__getItemName(this.items.length - 1);
},
/**
@@ -303,34 +311,13 @@
return null;
}
- return this.__getItemName(this.items, itemIndex - 1);
+ return this.__getItemName(itemIndex - 1);
},
/////////////////////////////////////////////////////////////////////////////////
//// Private
/////////////////////////////////////////////////////////////////////////////////
- /********************* Events *************************/
-
- /**
- * Fire Concealable Event
- * */
- __fireBeforeItemChange : function (oldItem, newItem) {
- return rf.Event.fireById(this.id, "beforeitemchange", {
- id: this.id,
- oldItem : oldItem,
- newItem : newItem
- });
- },
-
- __fireItemChange : function (oldItem, newItem) {
- return new rf.Event.fireById(this.id, "itemchange", {
- id: this.id,
- oldItem : oldItem,
- newItem : newItem
- });
- },
-
/********************* Methods *************************/
__ITEMS_META_NAMES : {
@@ -382,8 +369,17 @@
return item.getName();
},
+ /**
+ * Fire Concealable Event
+ * */
+ __fireBeforeItemChange : function (oldItem, newItem) {
+ return rf.Event.fireById(this.id, "beforeitemchange", {
+ id: this.id,
+ oldItem : oldItem,
+ newItem : newItem
+ });
+ },
-
// class stuff
destroy: function () {
// rf.Event.unbindById(this.options.buttonId,
"."+this.namespace);
Added:
root/ui/output/trunk/panels/ui/src/test/java/org/richfaces/component/AbstractTogglePanelTest.java
===================================================================
---
root/ui/output/trunk/panels/ui/src/test/java/org/richfaces/component/AbstractTogglePanelTest.java
(rev 0)
+++
root/ui/output/trunk/panels/ui/src/test/java/org/richfaces/component/AbstractTogglePanelTest.java 2010-07-23
16:43:22 UTC (rev 18220)
@@ -0,0 +1,150 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.faces.component.UIComponent;
+import java.util.List;
+
+/**
+ * @author akolonitsky
+ * @since Jul 20, 2010
+ */
+public class AbstractTogglePanelTest {
+
+ private static final String ITEM1 = "item1";
+ private static final String ITEM2 = "item2";
+ private static final String ITEM3 = "item3";
+
+ private UITogglePanel panel;
+ private UITogglePanelItem item1;
+ private UITogglePanelItem item2;
+ private UITogglePanelItem item3;
+
+ @Before
+ public void setUp () {
+ panel = new UITogglePanel();
+ List<UIComponent> children = panel.getChildren();
+
+ item1 = createItem(ITEM1);
+ children.add(item1);
+
+ item2 = createItem(ITEM2);
+ children.add(item2);
+
+ item3 = createItem(ITEM3);
+ children.add(item3);
+ }
+
+ @Test
+ public void testGetItemByIndex() {
+ panel.setActiveItem(ITEM1);
+
+ Assert.assertEquals(item1, panel.getItemByIndex(0));
+ Assert.assertEquals(item2, panel.getItemByIndex(1));
+ Assert.assertEquals(item3, panel.getItemByIndex(2));
+ Assert.assertEquals(null, panel.getItemByIndex(3));
+
+ item1.setRendered(false);
+
+ Assert.assertEquals(item2, panel.getItemByIndex(0));
+ Assert.assertEquals(item3, panel.getItemByIndex(1));
+ Assert.assertEquals(null, panel.getItemByIndex(2));
+ Assert.assertEquals(null, panel.getItemByIndex(3));
+
+ item2.setRendered(false);
+ item3.setRendered(false);
+ Assert.assertEquals(null, panel.getItemByIndex(0));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetItem() {
+ Assert.assertEquals(item1, panel.getItem(ITEM1));
+ Assert.assertEquals(item2, panel.getItem(ITEM2));
+ Assert.assertEquals(item3, panel.getItem(ITEM3));
+ Assert.assertEquals(null, panel.getItem("123"));
+
+ panel.getItem(null);
+ }
+
+ @Test
+ public void testItemOrder() {
+ panel.setActiveItem(ITEM1);
+ Assert.assertEquals(item1, panel.getFirstItem());
+ Assert.assertEquals(null, panel.getPrevItem());
+ Assert.assertEquals(item2, panel.getNextItem());
+ Assert.assertEquals(item3, panel.getLastItem());
+
+ panel.setActiveItem(ITEM2);
+ Assert.assertEquals(item1, panel.getFirstItem());
+ Assert.assertEquals(item1, panel.getPrevItem());
+ Assert.assertEquals(item3, panel.getNextItem());
+ Assert.assertEquals(item3, panel.getLastItem());
+
+ panel.setActiveItem(ITEM3);
+ Assert.assertEquals(item1, panel.getFirstItem());
+ Assert.assertEquals(item2, panel.getPrevItem());
+ Assert.assertEquals(null, panel.getNextItem());
+ Assert.assertEquals(item3, panel.getLastItem());
+
+ item1.setRendered(false);
+
+ panel.setActiveItem(ITEM1);
+ Assert.assertEquals(item2, panel.getFirstItem());
+ Assert.assertEquals(null, panel.getPrevItem());
+ Assert.assertEquals(null, panel.getNextItem());
+ Assert.assertEquals(item3, panel.getLastItem());
+
+ panel.setActiveItem(ITEM2);
+ Assert.assertEquals(item2, panel.getFirstItem());
+ Assert.assertEquals(null, panel.getPrevItem());
+ Assert.assertEquals(item3, panel.getNextItem());
+ Assert.assertEquals(item3, panel.getLastItem());
+
+ panel.setActiveItem(ITEM3);
+ Assert.assertEquals(item2, panel.getFirstItem());
+ Assert.assertEquals(item2, panel.getPrevItem());
+ Assert.assertEquals(null, panel.getNextItem());
+ Assert.assertEquals(item3, panel.getLastItem());
+ }
+
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetChildName() {
+ panel.setActiveItem(ITEM1);
+ Assert.assertTrue(panel.isActiveItem(item1));
+ Assert.assertFalse(panel.isActiveItem(item2));
+ Assert.assertFalse(panel.isActiveItem(null));
+
+ panel.isActiveItem(panel);
+ }
+
+ private static UITogglePanelItem createItem(String name) {
+ UITogglePanelItem item = new UITogglePanelItem();
+ item.setName(name);
+
+ return item;
+ }
+}