Author: Alex.Kolonitsky
Date: 2010-07-09 11:15:39 -0400 (Fri, 09 Jul 2010)
New Revision: 17782
Added:
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/java/org/richfaces/TogglePanelBean.java
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/examples/
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/examples/divPanel.xhtml
Removed:
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/java/org/richfaces/RichBean.java
Modified:
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/faces-config.xml
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/index.xhtml
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/templates/template.xhtml
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UITogglePanel.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/behavior/ToggleControl.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/ToggleControlRenderer.java
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
root/ui-sandbox/panels/trunk/ui/src/main/resources/META-INF/resources/script/TogglePanel.js
Log:
RF-8745 TogglePanel component
Deleted:
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/java/org/richfaces/RichBean.java
===================================================================
---
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/java/org/richfaces/RichBean.java 2010-07-09
14:24:26 UTC (rev 17781)
+++
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/java/org/richfaces/RichBean.java 2010-07-09
15:15:39 UTC (rev 17782)
@@ -1,27 +0,0 @@
-package org.richfaces;
-
-import org.slf4j.LoggerFactory;
-import org.slf4j.Logger;
-
-import java.io.Serializable;
-
-public class RichBean implements Serializable {
-
- private static final long serialVersionUID = -2403138958014741653L;
- private Logger logger;
- private String name;
-
- public RichBean() {
- logger = LoggerFactory.getLogger(RichBean.class);
- logger.info("post construct: initialize");
- name = "John";
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-}
Copied:
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/java/org/richfaces/TogglePanelBean.java
(from rev 17626,
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/java/org/richfaces/RichBean.java)
===================================================================
---
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/java/org/richfaces/TogglePanelBean.java
(rev 0)
+++
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/java/org/richfaces/TogglePanelBean.java 2010-07-09
15:15:39 UTC (rev 17782)
@@ -0,0 +1,32 @@
+package org.richfaces;
+
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
+import java.io.Serializable;
+
+public class TogglePanelBean implements Serializable {
+
+ private static final long serialVersionUID = -2403138958014741653L;
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(TogglePanelBean.class);
+
+ private String name;
+
+ public TogglePanelBean() {
+ LOGGER.info("post construct: initialize");
+ name = "John";
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void itemChangeActionListener() {
+ LOGGER.info("TogglePanelBean.itemChangeActionListener");
+ }
+}
Modified:
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/faces-config.xml 2010-07-09
14:24:26 UTC (rev 17781)
+++
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/faces-config.xml 2010-07-09
15:15:39 UTC (rev 17782)
@@ -3,8 +3,38 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<managed-bean>
- <managed-bean-name>richBean</managed-bean-name>
- <managed-bean-class>org.richfaces.RichBean</managed-bean-class>
+ <managed-bean-name>togglePanelBean</managed-bean-name>
+
<managed-bean-class>org.richfaces.TogglePanelBean</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
+
+ <navigation-rule>
+ <!-- Examples -->
+ <navigation-case>
+ <from-outcome>togglePanel</from-outcome>
+ <to-view-id>/examples/togglePanel.xhtml</to-view-id>
+ </navigation-case>
+ <navigation-case>
+ <from-outcome>togglePanel/server</from-outcome>
+ <to-view-id>/examples/togglePanel-server.xhtml</to-view-id>
+ </navigation-case>
+ <navigation-case>
+ <from-outcome>togglePanel/ajax</from-outcome>
+ <to-view-id>/examples/togglePanel-ajax.xhtml</to-view-id>
+ </navigation-case>
+ <navigation-case>
+ <from-outcome>togglePanel/client</from-outcome>
+ <to-view-id>/examples/togglePanel-client.xhtml</to-view-id>
+ </navigation-case>
+
+ <!-- QUnit -->
+ <navigation-case>
+ <from-outcome>qunit/togglePanel</from-outcome>
+ <to-view-id>/qunit/togglePanel.xhtml</to-view-id>
+ </navigation-case>
+ <navigation-case>
+ <from-outcome>qunit/togglePanelItem</from-outcome>
+ <to-view-id>/qunit/togglePanelItem.xhtml</to-view-id>
+ </navigation-case>
+ </navigation-rule>
</faces-config>
Added:
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/examples/divPanel.xhtml
===================================================================
---
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/examples/divPanel.xhtml
(rev 0)
+++
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/examples/divPanel.xhtml 2010-07-09
15:15:39 UTC (rev 17782)
@@ -0,0 +1,21 @@
+<!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/panels">
+
+<body>
+<ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="title">Toggle Panel Example</ui:define>
+ <ui:define name="body_head">Toggle Panel Example</ui:define>
+
+ <ui:define name="body">
+ <pn:divPanel id="my_id" lang="en"
onclick="#{togglePanelBean.name}" hi="Hello" >
+ other html
+ </pn:divPanel>
+ </ui:define>
+</ui:composition>
+</body>
+</html>
Modified:
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/index.xhtml
===================================================================
---
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/index.xhtml 2010-07-09
14:24:26 UTC (rev 17781)
+++
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/index.xhtml 2010-07-09
15:15:39 UTC (rev 17782)
@@ -11,10 +11,10 @@
<ui:define name="title">RichFaces Sample</ui:define>
<ui:define name="body">
- <pa:divPanel id="my_id" lang="en"
onclick="#{richBean.name}">
- other html
- </pa:divPanel>
+ look at left
</ui:define>
+
+ <div style="top: auto;"></div>
</ui:composition>
</body>
</html>
Modified:
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/templates/template.xhtml
===================================================================
---
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/templates/template.xhtml 2010-07-09
14:24:26 UTC (rev 17781)
+++
root/archetypes/richfaces-archetype-simpleapp/trunk/src/main/resources/archetype-resources/src/main/webapp/templates/template.xhtml 2010-07-09
15:15:39 UTC (rev 17782)
@@ -5,11 +5,50 @@
xmlns:ui="http://java.sun.com/jsf/facelets" >
<h:head>
- <title><ui:define name="title">Application
Title</ui:define></title>
+ <title>
+ <ui:define name="title">Application Title</ui:define>
+ </title>
+
<meta http-equiv="content-type" content="text/xhtml;
charset=UTF-8" />
+
</h:head>
<h:body>
- <ui:insert name="body">Default content</ui:insert>
+ <ui:insert name="scripts" ></ui:insert>
+ <table width="100%">
+ <thead>
+ <tr>
+ <th width="20%"
align="left">Content</th>
+ <th width="80%" align="left">
+ <ui:insert
name="body_head">Example</ui:insert>
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr valign="top">
+ <td>
+ <h:form id="nav">
+ <p>Examples</p>
+ <ul>
+ <li><h:commandLink value="divPanel"
action="divPanel" /></li>
+ <li><h:commandLink value="togglePanel"
action="togglePanel" /></li>
+ <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>
+ </ul>
+ <p>QUnit</p>
+ <ul>
+ <li><h:commandLink value="togglePanel"
action="qunit/togglePanel" /></li>
+ <li><h:commandLink value="togglePanelItem"
action="qunit/togglePanelItem" /></li>
+ </ul>
+ </h:form>
+ </td>
+ <td>
+ <ui:insert name="body">Default
content</ui:insert>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+
</h:body>
</html>
Modified: root/core/trunk/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2010-07-09
14:24:26 UTC (rev 17781)
+++
root/core/trunk/impl/src/main/java/org/ajax4jsf/context/AjaxContextImpl.java 2010-07-09
15:15:39 UTC (rev 17782)
@@ -581,9 +581,11 @@
res.append(this.oncomplete);
res.append(';');
}
+
+ if (onComplete != null) {
+ res.append(onComplete).append(';');
+ }
- res.append(onComplete).append(';');
-
this.oncomplete = res.toString();
}
Modified:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java 2010-07-09
14:24:26 UTC (rev 17781)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/AbstractTogglePanel.java 2010-07-09
15:15:39 UTC (rev 17782)
@@ -31,13 +31,14 @@
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.EditableValueHolder;
-//import javax.faces.component.MessageFactory;
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;
+import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PostValidateEvent;
import javax.faces.event.PreValidateEvent;
@@ -49,7 +50,6 @@
/**
* @author akolonitsky
* @version 1.0
- * @since -4712-01-01
*/
public abstract class AbstractTogglePanel extends AbstractDivPanel implements
EditableValueHolder {
@@ -57,9 +57,6 @@
public static final String COMPONENT_FAMILY =
"org.richfaces.panels.TogglePanel";
- public static final String UPDATE_MESSAGE_ID =
- "javax.faces.component.UIInput.UPDATE";
-
private String submittedSelectedItem = null;
private enum PropertyKeys {
@@ -227,9 +224,7 @@
popComponentFromEL(context);
}
- if (isImmediate()) {
- executeValidate(context);
- }
+ executeValidate(context);
}
/**
@@ -271,10 +266,6 @@
}
app.publishEvent(context, PostValidateEvent.class, this);
popComponentFromEL(context);
-
- if (!isImmediate()) {
- executeValidate(context);
- }
}
/**
@@ -342,50 +333,6 @@
super.decode(context);
}
- /**
- * <p><span class="changed_modified_2_0">Perform</span>
- * the following algorithm to update the model data
- * associated with this {@link javax.faces.component.UIInput}, if any, as
appropriate.</p>
- * <ul>
- * <li>If the <code>valid</code> property of this component is
- * <code>false</code>, take no further action.</li>
- * <li>If the <code>localValueSet</code> property of this component
is
- * <code>false</code>, take no further action.</li>
- * <li>If no {@link javax.el.ValueExpression} for
<code>value</code> exists,
- * take no further action.</li>
- * <li>Call <code>setValue()</code> method of the {@link
javax.el.ValueExpression}
- * to update the value that the {@link javax.el.ValueExpression} points
at.</li>
- * <li>If the <code>setValue()</code> method returns successfully:
- * <ul>
- * <li>Clear the local value of this {@link
javax.faces.component.UIInput}.</li>
- * <li>Set the <code>localValueSet</code> property of this
- * {@link javax.faces.component.UIInput} to false.</li>
- * </ul></li>
- * <li>If the <code>setValue()</code> method throws an Exception:
- * <ul>
- * <li class="changed_modified_2_0">Enqueue an error message. Create
a
- * {@link javax.faces.application.FacesMessage} with the id {@link
#UPDATE_MESSAGE_ID}. Create a
- * {@link javax.faces.component.UpdateModelException}, passing the
<code>FacesMessage</code> and
- * the caught exception to the constructor. Create an
- * {@link javax.faces.event.ExceptionQueuedEventContext}, passing the
<code>FacesContext</code>,
- * the <code>UpdateModelException</code>, this component instance, and
- * {@link javax.faces.event.PhaseId#UPDATE_MODEL_VALUES} to its constructor. Call
- * {@link FacesContext#getExceptionHandler} and then call
- * {@link javax.faces.context.ExceptionHandler#processEvent}, passing the
- * <code>ExceptionQueuedEventContext</code>.
- * </li>
- * <li>Set the <code>valid</code> property of this {@link
javax.faces.component.UIInput}
- * to <code>false</code>.</li>
- * </ul></li>
- * The exception must not be re-thrown. This enables tree traversal
- * to continue for this lifecycle phase, as in all the other lifecycle
- * phases.
- * </ul>
- *
- * @param context {@link FacesContext} for the request we are processing
- * @throws NullPointerException if <code>context</code>
- * is <code>null</code>
- */
public void updateModel(FacesContext context) {
if (context == null) {
@@ -442,7 +389,7 @@
}
}
- /**
+ /**
* Executes validation logic.
*/
private void executeValidate(FacesContext context) {
@@ -478,8 +425,29 @@
}
}
-
+ public void queueEvent(FacesEvent event) {
+ if ((event instanceof SelectedItemChangeEvent) && (event.getComponent()
== this)) {
+ if (isImmediate()) {
+ event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
+ } else if (isBypassUpdates()) {
+ event.setPhaseId(PhaseId.PROCESS_VALIDATIONS);
+ } else {
+ event.setPhaseId(PhaseId.INVOKE_APPLICATION);
+ }
+ }
+ super.queueEvent(event);
+ }
+
+ @Override
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ super.broadcast(event);
+
+ if (event instanceof SelectedItemChangeEvent && isBypassUpdates()) {
+ FacesContext.getCurrentInstance().renderResponse();
+ }
+ }
+
// -------------------------------------------------- Panel Items Managing
@Override
public String getFamily() {
@@ -587,9 +555,9 @@
public abstract Method getSwitchType();
- public abstract boolean getBypassUpdates();
+ public abstract boolean isBypassUpdates();
- public abstract boolean getLimitToList();
+ public abstract boolean isLimitToList();
public abstract Object getData();
Modified:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UITogglePanel.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UITogglePanel.java 2010-07-09
14:24:26 UTC (rev 17781)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/UITogglePanel.java 2010-07-09
15:15:39 UTC (rev 17782)
@@ -59,7 +59,7 @@
getStateHelper().put(PropertyKeys.switchType, switchType);
}
- public boolean getBypassUpdates() {
+ public boolean isBypassUpdates() {
return
Boolean.valueOf(String.valueOf(getStateHelper().eval(PropertyKeys.bypassUpdates)));
}
@@ -67,7 +67,7 @@
getStateHelper().put(PropertyKeys.bypassUpdates, bypassUpdates);
}
- public boolean getLimitToList() {
+ public boolean isLimitToList() {
return
Boolean.valueOf(String.valueOf(getStateHelper().eval(PropertyKeys.limitToList)));
}
Modified:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/behavior/ToggleControl.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/behavior/ToggleControl.java 2010-07-09
14:24:26 UTC (rev 17781)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/component/behavior/ToggleControl.java 2010-07-09
15:15:39 UTC (rev 17782)
@@ -28,6 +28,7 @@
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
+import javax.faces.component.behavior.ClientBehaviorContext;
/**
* @author akolonitsky
@@ -41,6 +42,7 @@
event,
targetItem,
forPanel,
+ disableDefault
}
public String getEvent() {
@@ -67,6 +69,18 @@
getStateHelper().put(PropertyKeys.forPanel, selector);
}
+ public void setDisableDefault(String disableDefault) {
+ getStateHelper().put(PropertyKeys.disableDefault, disableDefault);
+ }
+
+ public Boolean getDisableDefault() {
+ return
Boolean.valueOf(String.valueOf(getStateHelper().eval(PropertyKeys.disableDefault,
true)));
+ }
+
+ public String getPanelId(ClientBehaviorContext behaviorContext) throws FacesException
{
+ return getPanel(behaviorContext.getComponent()).getClientId();
+ }
+
public AbstractTogglePanel getPanel(UIComponent comp) throws FacesException {
String target = this.getForPanel();
Modified:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java 2010-07-09
14:24:26 UTC (rev 17781)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/DivPanelRenderer.java 2010-07-09
15:15:39 UTC (rev 17782)
@@ -34,7 +34,7 @@
/**
* @author akolonitsky
- * @since -4712-01-01
+ *
*/
public class DivPanelRenderer extends RendererBase {
Modified:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/ToggleControlRenderer.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/ToggleControlRenderer.java 2010-07-09
14:24:26 UTC (rev 17781)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/ToggleControlRenderer.java 2010-07-09
15:15:39 UTC (rev 17782)
@@ -22,7 +22,6 @@
package org.richfaces.renderkit.html;
-import org.richfaces.component.AbstractTogglePanel;
import org.richfaces.component.behavior.ToggleControl;
import javax.faces.application.ResourceDependencies;
@@ -34,13 +33,13 @@
import javax.faces.render.RenderKitFactory;
/**
- * @author Anton Belevich
+ * @author akolonitsky
*
*/
@FacesBehaviorRenderer(
rendererType = "org.richfaces.component.behavior.ToggleControl",
renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT)
-@ResourceDependencies({
+@ResourceDependencies({ // TODO review
@ResourceDependency(library = "javax.faces", name = "jsf.js"),
@ResourceDependency(name = "jquery.js"),
@ResourceDependency(name = "richfaces.js") })
@@ -50,7 +49,10 @@
public String getScript(ClientBehaviorContext behaviorContext, ClientBehavior
behavior) {
ToggleControl control = (ToggleControl) behavior;
- AbstractTogglePanel panel = control.getPanel(behaviorContext.getComponent());
- return "RichFaces.$('" + panel.getClientId() +
"').switchToItem('" + control.getTargetItem() + "'); return
false;";
+ StringBuilder builder = new StringBuilder();
+
builder.append("RichFaces.$('").append(control.getPanelId(behaviorContext)).append("').switchToItem('")
+ .append(control.getTargetItem()).append("'); return
").append(!control.getDisableDefault()).append(';');
+
+ return builder.toString();
}
}
\ No newline at end of file
Modified:
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java 2010-07-09
14:24:26 UTC (rev 17781)
+++
root/ui-sandbox/panels/trunk/ui/src/main/java/org/richfaces/renderkit/html/TogglePanelRenderer.java 2010-07-09
15:15:39 UTC (rev 17782)
@@ -88,7 +88,7 @@
private void addOnCompleteParam(String newValue, AbstractTogglePanel panel) {
StringBuilder onComplete = new StringBuilder();
onComplete.append("RichFaces.$('").append(panel.getClientId()).append("').onCompleteHandler('")
-
.append(panel.getSelectedItem()).append("','").append(newValue).append("');
return false;");
+
.append(panel.getSelectedItem()).append("','").append(newValue).append("');");
AjaxContext.getCurrentInstance().appendOncomplete(onComplete.toString());
}
Modified:
root/ui-sandbox/panels/trunk/ui/src/main/resources/META-INF/resources/script/TogglePanel.js
===================================================================
---
root/ui-sandbox/panels/trunk/ui/src/main/resources/META-INF/resources/script/TogglePanel.js 2010-07-09
14:24:26 UTC (rev 17781)
+++
root/ui-sandbox/panels/trunk/ui/src/main/resources/META-INF/resources/script/TogglePanel.js 2010-07-09
15:15:39 UTC (rev 17782)
@@ -22,7 +22,6 @@
(function ($, rf) {
- /***************************** Stuff
******************************************************************************/
rf.ui = rf.ui || {};
/***************************** Constructor definition
*************************************************************/
@@ -37,7 +36,7 @@
* @param {String} componentId - component id
* @param {Hash} options - params
* */
- rf.ui.TogglePanel = function(componentId, options) {
+ rf.ui.TogglePanel = function (componentId, options) {
// call constructor of parent class
$super.constructor.call(this, componentId);
$p.attachToDom.call(this, componentId);
@@ -55,8 +54,121 @@
var $super = rf.ui.TogglePanel.$super;
- /***************************** Private Static Methods
*************************************************************/
+ /***************************** Private Static Area
****************************************************************/
+
+ /* SIMPLE INNER CLASS for handle switch operation*/
+ function SwitchItems (comp) {
+ this.comp = comp;
+ }
+
+ SwitchItems.prototype = {
+
+ /**
+ * @param {TogglePanel} comp
+ * @param {TogglePanelItem} oldPanel
+ * @param {TogglePanelItem} newPanel
+ *
+ * @return {void}
+ * */
+ exec : function (oldPanel, newPanel) {
+ if (this.comp.switchMode == "server") {
+ return this.execServer(oldPanel, newPanel);
+ } else if (this.comp.switchMode == "ajax") {
+ return this.execAjax(oldPanel, newPanel);
+ } else if (this.comp.switchMode == "client") {
+ return this.execClient(oldPanel, newPanel);
+ } else {
+ rf.log.error("SwitchItems.exec : unknown switchMode (" +
this.comp.switchMode + ")");
+ }
+ },
+
+ /**
+ * @protected
+ * @param {TogglePanelItem} oldPanel
+ * @param {TogglePanelItem} newPanel
+ *
+ * @return {Boolean} false
+ * */
+ execServer : function (oldPanel, newPanel) {
+ var continueProcess = oldPanel.leave();
+ if (!continueProcess) {
+ return false;
+ }
+
+ this.setSelectedItem(newPanel.getName());
+
+ rf.submitForm(this.getParentForm(), null, {});
+
+ return false;
+ },
+
+ /**
+ * @protected
+ * @param {TogglePanelItem} oldPanel
+ * @param {TogglePanelItem} newPanel
+ *
+ * @return {Boolean} false
+ * */
+ execAjax : function (oldPanel, newPanel) {
+ var options = $.extend({}, this.comp.options["ajax"],
{}/*this.getParameters(newPanel)*/);
+
+ this.setSelectedItem(newPanel.getName());
+ rf.ajax(this.comp.id, null, options);
+ this.setSelectedItem(oldPanel.getName());
+
+ return false;
+ },
+
+ /**
+ * @protected
+ * @param {TogglePanelItem} oldPanel
+ * @param {TogglePanelItem} newPanel
+ *
+ * @return {undefined}
+ * - false - if process has been terminated
+ * - true - in other cases
+ * */
+ execClient : function (oldPanel, newPanel) {
+ var continueProcess = oldPanel.leave();
+ if (!continueProcess) {
+ return false;
+ }
+
+ this.setSelectedItem(newPanel.getName());
+
+ newPanel.enter();
+ fireItemChange(this.comp, oldPanel, newPanel);
+
+ return true;
+ },
+
+ /**
+ * @private
+ * */
+ getParentForm : function () {
+ return $(RichFaces.getDomElement(this.comp.id)).parent('form');
+ },
+
+ /**
+ * @private
+ * */
+ setSelectedItem : function (name) {
+ rf.getDomElement(this.getValueInputId()).value = name;
+ this.comp.selectedItem = name;
+ },
+
+ /**
+ * @private
+ * */
+ getValueInputId: function () {
+ return this.comp.id + "-value"
+ }
+
+ };
+
+ /********************* Events *************************/
+
/**
* Fire Concealable Event
* */
@@ -76,16 +188,54 @@
});
}
+ /********************* Methods *************************/
- function getEventHandler() {}
+ function getItemIndex (items, itemName) {
+ for (var i = 0; i < items.length; i++) {
+ if (items[i].getName() === itemName) {
+ return i;
+ }
+ }
+ rf.log.info("TogglePanel.getItemIndex: item with name '" + itemName
+ "' not found");
+ return -1;
+ }
+
+ /**
+ * @param {TogglePanelItem[]} items
+ * @param {Number} index - array index
+ *
+ * @return {TogglePanelItem}
+ * null - if item not found
+ * */
+ function getItem (items, index) {
+ if (index >= 0 && index < items.length) {
+ return items[index]
+ }
+
+ return null;
+ }
+
+ function getItemByName (items, name) {
+ return getItem(items, getItemIndex(items, name));
+ }
+
+ function getItemName (items, index) {
+ var item = getItem(items, index);
+ if (item == null) {
+ return null;
+ }
+
+ return item.getName();
+ }
+
+
/***************************** Public Methods
********************************************************************/
$.extend(rf.ui.TogglePanel.prototype, (function () {
return {
// class name
name:"TogglePanel",
- // public api
/**
* @methodOf
* @name TogglePanel#getSelectItem
@@ -96,10 +246,6 @@
return this.selectedItem;
},
- getValueInputId: function () {
- return this.id + "-value"
- },
-
/**
* @methodOf
* @name TogglePanel#switchToItem
@@ -108,125 +254,32 @@
* @return {Boolean} - always false
*/
switchToItem: function (name) {
- var oldPanel = this.getItemByName(this.getSelectItem());
- var newPanel = name ? this.getItemByName(name)
- : this.getItem(this.nextItem());
+ var oldPanel = getItemByName(this.items, this.getSelectItem());
+ var newPanel = getItemByName(this.items, name || this.nextItem());
var continueProcess = fireBeforeItemChange(this, oldPanel, newPanel);
if (!continueProcess) {
return false
}
- this.switchItems(oldPanel, newPanel);
+ new SwitchItems(this).exec(oldPanel, newPanel);
return false;
},
- setSelectedItem : function (name) {
- rf.getDomElement(this.getValueInputId()).value = name;
- this.selectedItem = name;
- },
-
/**
- * @param {TogglePanelItem} oldPanel
- * @param {TogglePanelItem} newPanel
- *
- * @return {void}
- * */
- switchItems : function (oldPanel, newPanel) {
- if (this.switchMode == "server") {
- return this.switchItems_server(oldPanel, newPanel);
- } else if (this.switchMode == "ajax") {
- return this.switchItems_ajax(oldPanel, newPanel);
- } else if (this.switchMode == "client") {
- return this.switchItems_client(oldPanel, newPanel);
- } else {
- rf.log.error("TogglePanel.switchItems : unknown switchMode
(" + this.switchMode + ")");
- }
- },
-
- /**
- * @param {TogglePanelItem} oldPanel
- * @param {TogglePanelItem} newPanel
- *
- * @return {void}
- * */
- switchItems_server : function (oldPanel, newPanel) {
- var continueProcess = oldPanel.leave();
- if (!continueProcess) {
- return false;
- }
-
- this.setSelectedItem(newPanel.getName());
-
- rf.submitForm(this.getParentForm(), null, this.getParameters(newPanel));
-
- return false;
- },
-
- getParentForm : function () {
- return $(RichFaces.getDomElement(this.id)).parent('form');
- },
-
- getParameters : function (newPanel) {
- return {"parameters" : this.getServerParams(newPanel)};
- },
-
- getServerParams : function (newPanel) {
- var params = {};
-// params[this.getValueInputId()] = newPanel.getName();
-
- return params;
- },
-
- /**
- * @param {TogglePanelItem} oldPanel
- * @param {TogglePanelItem} newPanel
- *
- * @return {undefined}
- * */
- switchItems_ajax : function (oldPanel, newPanel) {
- var options = $.extend({}, this.options["ajax"],
{}/*this.getParameters(newPanel)*/);
-
- this.setSelectedItem(newPanel.getName());
- rf.ajax(this.id, null, options);
- this.setSelectedItem(oldPanel.getName());
-
- return false;
- },
-
- /**
* please, remove this method when client side ajax events will be added
*
* */
onCompleteHandler : function (oldItemName, newItemName) {
- var oldItem = this.getItemByName(oldItemName);
- var newItem = this.getItemByName(newItemName);
+ var oldItem = getItemByName(this.items, oldItemName);
+ var newItem = getItemByName(this.items, newItemName);
- this.switchItems_client(oldItem, newItem);
+ // Don't do like this and remove it ASAP
+ new SwitchItems(this).execClient(oldItem, newItem);
},
/**
- * @param {TogglePanelItem} oldPanel
- * @param {TogglePanelItem} newPanel
- *
- * @return {undefined} false - if process has been terminated
- * */
- switchItems_client : function (oldPanel, newPanel) {
- var continueProcess = oldPanel.leave();
- if (!continueProcess) {
- return false;
- }
-
- this.setSelectedItem(newPanel.getName());
-
- newPanel.enter();
- fireItemChange(this, oldPanel, newPanel);
- },
-
-
-
- /**
* @methodOf
* @name TogglePanel#getItems
*
@@ -259,7 +312,12 @@
* @return {String} name of next panel item
*/
nextItem: function (itemName) {
- return this.getItemName(this.getItemIndex(itemName) + 1);
+ var itemIndex = getItemIndex(this.items, itemName || this.selectedItem);
+ if (itemIndex == -1) {
+ return null;
+ }
+
+ return getItemName(this.items, itemIndex + 1);
},
/**
@@ -269,7 +327,7 @@
* @return {String} name of first panel item
*/
firstItem: function () {
- return this.getItemName(0);
+ return getItemName(this.items, 0);
},
/**
@@ -279,93 +337,26 @@
* @return {String} name of last panel item
*/
lastItem: function () {
- return this.getItemName(this.items.length - 1);
+ return getItemName(this.items, this.items.length - 1);
},
/**
* @methodOf
* @name TogglePanel#prevItem
*
- * @param {String} [itemName = selectedItem]
+ * @param {String} itemName
* @return {String} name of prev panel item
+ * null if it is first item
*/
prevItem: function (itemName) {
- var itemIndex = this.getItemIndex(itemName);
- if (itemIndex == -1) {
- return this.firstItem();
+ var itemIndex = getItemIndex(this.items, itemName || this.selectedItem);
+ if (itemIndex < 1) {
+ return null;
}
- return this.getItemName((this.items.length + itemIndex - 1) %
this.items.length);
+
+ return getItemName(this.items, itemIndex - 1);
},
-
-
- // event handlers
- /**
- * @methodOf
- * @name TogglePanel#oncomplete
- */
- oncomplete: function () {
- // TODO implement
- },
-
- /**
- * @methodOf
- * @name TogglePanel#onbeforedomupdate
- */
- onbeforedomupdate: function () {
- // TODO implement
- },
-
- /**
- * @methodOf
- * @name TogglePanel#onitemchange
- */
- onitemchange: function () {
- // TODO implement
- },
-
- /**
- * @methodOf
- * @name TogglePanel#onitemchanged
- */
- onitemchanged: function () {
- // TODO implement
- },
-
- // private methods
- getItemName : function (index) {
- return this.getItem(index).getName();
- },
-
- getItemByName : function (name) {
- return this.getItem(this.getItemIndex(name));
- },
-
- getItemIndex : function (itemName) {
- var name = itemName || this.selectedItem;
- for (var i = 0; i < this.items.length; i++) {
- if (this.items[i].getName() === name) {
- return i;
- }
- }
-
- rf.log.warn("TogglePanel.getItemIndex: item with name '" +
itemName + "' not found");
- return -1;
- },
-
- /**
- * @param {Number} index - array index
- *
- * @return {TogglePanelItem}
- * */
- getItem : function (index) {
- if (index >= this.items.length || index < 0) {
- return this.items[0];
- } else {
- return this.items[index]
- }
- },
-
// class stuff
destroy: function () {
// rf.Event.unbindById(this.options.buttonId,
"."+this.namespace);