Author: Alex.Kolonitsky
Date: 2010-12-02 14:07:45 -0500 (Thu, 02 Dec 2010)
New Revision: 20319
Added:
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/PanelMenuTagHandler.java
Modified:
trunk/examples/output-demo/src/main/java/org/richfaces/ModalPanel.java
trunk/examples/output-demo/src/main/webapp/qunit/panelMenu.xhtml
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenu.java
trunk/ui/output/ui/src/main/java/org/richfaces/component/UIPanelMenu.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java
trunk/ui/output/ui/src/main/resources/META-INF/pn.faces-config.xml
trunk/ui/output/ui/src/main/resources/META-INF/pn.taglib.xml
Log:
RF-9317 panelMenu components
fix itemChangeListener and add action)
Modified: trunk/examples/output-demo/src/main/java/org/richfaces/ModalPanel.java
===================================================================
--- trunk/examples/output-demo/src/main/java/org/richfaces/ModalPanel.java 2010-12-02
18:53:41 UTC (rev 20318)
+++ trunk/examples/output-demo/src/main/java/org/richfaces/ModalPanel.java 2010-12-02
19:07:45 UTC (rev 20319)
@@ -1,196 +1,203 @@
package org.richfaces;
-import javax.faces.context.FacesContext;
-import javax.faces.event.ActionEvent;
+import org.richfaces.event.ItemChangeEvent;
+
import javax.faces.bean.ManagedBean;
-import javax.faces.bean.RequestScoped;
+import javax.faces.bean.SessionScoped;
+
@ManagedBean
-@RequestScoped
+@SessionScoped
public class ModalPanel {
- private boolean autosized;
- private boolean keepVisualState;
- private String left;
- private String top;
- private boolean rendered;
- private String shadowDepth;
- private String shadowOpacity;
- private boolean show;
- private int zindex;
- private int minHeight;
- private int minWidth;
- private int maxHeight;
- private int maxWidth;
- private int height;
- private int width;
- private boolean moveable;
- private boolean resizeable;
- private String inputTextTest;
- private String domElementAttachment;
-
+ private boolean autosized;
+ private boolean keepVisualState;
+ private String left;
+ private String top;
+ private boolean rendered;
+ private String shadowDepth;
+ private String shadowOpacity;
+ private boolean show;
+ private int zindex;
+ private int minHeight;
+ private int minWidth;
+ private int maxHeight;
+ private int maxWidth;
+ private int height;
+ private int width;
+ private boolean moveable;
+ private boolean resizeable;
+ private String inputTextTest;
+ private String domElementAttachment;
- public String getInputTextTest() {
- return inputTextTest;
- }
+ public String getInputTextTest() {
+ return inputTextTest;
+ }
- public void setInputTextTest(String inputTextTest) {
- this.inputTextTest = inputTextTest;
- }
+ public void setInputTextTest(String inputTextTest) {
+ this.inputTextTest = inputTextTest;
+ }
- public ModalPanel() {
- this.inputTextTest = "text";
- this.minHeight = 100;
- this.minWidth = 100;
- this.height = 300;
- this.width = 300;
- this.maxWidth = -1;
- this.maxHeight = -1;
- this.moveable=true;
- this.resizeable=true;
- this.autosized = false;
- this.keepVisualState = false;
- this.left = "auto";
- this.top = "auto";
- this.rendered = true;
- this.shadowDepth = "3";
- this.shadowOpacity = "3";
- this.show = false;
- this.domElementAttachment = "body";
- }
-
- public int getHeight() {
- return height;
- }
+ public ModalPanel() {
+ this.inputTextTest = "text";
+ this.minHeight = 100;
+ this.minWidth = 100;
+ this.height = 300;
+ this.width = 300;
+ this.maxWidth = -1;
+ this.maxHeight = -1;
+ this.moveable = true;
+ this.resizeable = true;
+ this.autosized = false;
+ this.keepVisualState = false;
+ this.left = "auto";
+ this.top = "auto";
+ this.rendered = true;
+ this.shadowDepth = "3";
+ this.shadowOpacity = "3";
+ this.show = false;
+ this.domElementAttachment = "body";
+ }
- public void setHeight(int height) {
- this.height = height;
- }
+ public int getHeight() {
+ return height;
+ }
- public int getMinHeight() {
- return minHeight;
- }
+ public void setHeight(int height) {
+ this.height = height;
+ }
- public void setMinHeight(int minHeight) {
- this.minHeight = minHeight;
- }
+ public int getMinHeight() {
+ return minHeight;
+ }
- public int getMaxWidth() {
- return maxWidth;
- }
+ public void setMinHeight(int minHeight) {
+ this.minHeight = minHeight;
+ }
- public void setMaxWidth(int maxWidth) {
- this.maxWidth = minWidth;
- }
-
- public int getMaxHeight() {
- return maxHeight;
- }
+ public int getMaxWidth() {
+ return maxWidth;
+ }
- public void setMaxHeight(int maxHeight) {
- this.maxHeight = maxHeight;
- }
+ public void setMaxWidth(int maxWidth) {
+ this.maxWidth = minWidth;
+ }
- public int getMinWidth() {
- return minWidth;
- }
+ public int getMaxHeight() {
+ return maxHeight;
+ }
- public void setMinWidth(int minWidth) {
- this.minWidth = minWidth;
- }
+ public void setMaxHeight(int maxHeight) {
+ this.maxHeight = maxHeight;
+ }
- public boolean isMoveable() {
- return moveable;
- }
+ public int getMinWidth() {
+ return minWidth;
+ }
- public void setMoveable(boolean moveable) {
- this.moveable = moveable;
- }
+ public void setMinWidth(int minWidth) {
+ this.minWidth = minWidth;
+ }
- public boolean isResizeable() {
- return resizeable;
- }
+ public boolean isMoveable() {
+ return moveable;
+ }
- public void setResizeable(boolean resizeable) {
- this.resizeable = resizeable;
- }
-
- public void setAutosized(boolean autosized) {
- this.autosized = autosized;
- }
+ public void setMoveable(boolean moveable) {
+ this.moveable = moveable;
+ }
+ public boolean isResizeable() {
+ return resizeable;
+ }
- public int getWidth() {
- return width;
- }
+ public void setResizeable(boolean resizeable) {
+ this.resizeable = resizeable;
+ }
- public void setWidth(int width) {
- this.width = width;
- }
+ public void setAutosized(boolean autosized) {
+ this.autosized = autosized;
+ }
- public boolean isAutosized() {
- return autosized;
- }
+ public int getWidth() {
+ return width;
+ }
- public boolean isKeepVisualState() {
- return keepVisualState;
- }
+ public void setWidth(int width) {
+ this.width = width;
+ }
- public void setKeepVisualState(boolean keepVisualState) {
- this.keepVisualState = keepVisualState;
- }
+ public boolean isAutosized() {
+ return autosized;
+ }
- public String getLeft() {
- return left;
- }
+ public boolean isKeepVisualState() {
+ return keepVisualState;
+ }
- public void setLeft(String left) {
- this.left = left;
- }
+ public void setKeepVisualState(boolean keepVisualState) {
+ this.keepVisualState = keepVisualState;
+ }
- public String getTop() {
- return top;
- }
+ public String getLeft() {
+ return left;
+ }
- public void setTop(String top) {
- this.top = top;
- }
+ public void setLeft(String left) {
+ this.left = left;
+ }
- public boolean getRendered() {
- return rendered;
- }
+ public String getTop() {
+ return top;
+ }
- public void setRendered(boolean rendered) {
- this.rendered = rendered;
- }
+ public void setTop(String top) {
+ this.top = top;
+ }
- public String getShadowDepth() {
- return shadowDepth;
- }
+ public boolean getRendered() {
+ return rendered;
+ }
- public void setShadowDepth(String shadowDepth) {
- this.shadowDepth = shadowDepth;
- }
+ public void setRendered(boolean rendered) {
+ this.rendered = rendered;
+ }
- public String getShadowOpacity() {
- return shadowOpacity;
- }
+ public String getShadowDepth() {
+ return shadowDepth;
+ }
- public void setShadowOpacity(String shadowOpacity) {
- this.shadowOpacity = shadowOpacity;
- }
+ public void setShadowDepth(String shadowDepth) {
+ this.shadowDepth = shadowDepth;
+ }
- public boolean isShow() {
- return show;
- }
+ public String getShadowOpacity() {
+ return shadowOpacity;
+ }
- public void setShow(boolean show) {
- this.show = show;
- }
+ public void setShadowOpacity(String shadowOpacity) {
+ this.shadowOpacity = shadowOpacity;
+ }
- public String getDomElementAttachment() {
- return domElementAttachment;
- }
+ public boolean isShow() {
+ return show;
+ }
- public void setDomElementAttachment(String domElementAttachment) {
- this.domElementAttachment = domElementAttachment;
- }
+ public void setShow(boolean show) {
+ this.show = show;
+ }
+
+ public String getDomElementAttachment() {
+ return domElementAttachment;
+ }
+
+ public void setDomElementAttachment(String domElementAttachment) {
+ this.domElementAttachment = domElementAttachment;
+ }
+
+ public void itemChangeEventListener(ItemChangeEvent event) {
+ System.out.println("item was changed from '" + event.getOldItem() +
"' to '" + event.getNewItem() + "'");
+ }
+
+ public void action() {
+ System.out.println("ModalPanel.action");
+ }
}
\ No newline at end of file
Modified: trunk/examples/output-demo/src/main/webapp/qunit/panelMenu.xhtml
===================================================================
--- trunk/examples/output-demo/src/main/webapp/qunit/panelMenu.xhtml 2010-12-02 18:53:41
UTC (rev 20318)
+++ trunk/examples/output-demo/src/main/webapp/qunit/panelMenu.xhtml 2010-12-02 19:07:45
UTC (rev 20319)
@@ -60,7 +60,10 @@
groupDisableIconLeft="disc"
topItemDisableIconLeft="disc"
topGroupDisableIconLeft="disc"
+ itemChangeListener="#{modalPanel.itemChangeEventListener}"
+ action="#{modalPanel.action}"
+
<pn:panelMenuGroup label="Group 1">
<pn:panelMenuItem label="Item 1.1" />
<pn:panelMenuItem label="Item 1.2" />
Modified: trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenu.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenu.java 2010-12-02
18:53:41 UTC (rev 20318)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/component/AbstractPanelMenu.java 2010-12-02
19:07:45 UTC (rev 20319)
@@ -25,11 +25,13 @@
import org.richfaces.PanelMenuMode;
import org.richfaces.event.ItemChangeEvent;
+import org.richfaces.event.ItemChangeListener;
+import org.richfaces.event.ItemChangeSource;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
-import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
import javax.faces.event.PhaseId;
@@ -37,7 +39,7 @@
* @author akolonitsky
* @since 2010-10-25
*/
-public abstract class AbstractPanelMenu extends UIOutput {
+public abstract class AbstractPanelMenu extends AbstractActionComponent implements
ItemChangeSource {
public static final String COMPONENT_TYPE = "org.richfaces.PanelMenu";
@@ -113,8 +115,18 @@
}
}
+ @Override
+ public void broadcast(FacesEvent event) throws AbortProcessingException {
+ super.broadcast(event);
+ if (event instanceof ItemChangeEvent
+ && (isBypassUpdates() || isImmediate())) {
+ FacesContext.getCurrentInstance().renderResponse();
+ }
+ }
+
+
public String getSubmittedActiveItem() {
return this.submittedActiveItem;
}
@@ -212,4 +224,18 @@
return null;
}
+
+ // ------------------------------------------------ Event Processing Methods
+
+ public void addItemChangeListener(ItemChangeListener listener) {
+ addFacesListener(listener);
+ }
+
+ public ItemChangeListener[] getItemChangeListeners() {
+ return (ItemChangeListener[]) getFacesListeners(ItemChangeListener.class);
+ }
+
+ public void removeItemChangeListener(ItemChangeListener listener) {
+ removeFacesListener(listener);
+ }
}
Modified: trunk/ui/output/ui/src/main/java/org/richfaces/component/UIPanelMenu.java
===================================================================
--- trunk/ui/output/ui/src/main/java/org/richfaces/component/UIPanelMenu.java 2010-12-02
18:53:41 UTC (rev 20318)
+++ trunk/ui/output/ui/src/main/java/org/richfaces/component/UIPanelMenu.java 2010-12-02
19:07:45 UTC (rev 20319)
@@ -105,14 +105,6 @@
getStateHelper().put(PropertyKeys.bubbleSelection, bubbleSelection);
}
- public String getActiveItem() {
- return (String) getStateHelper().eval(PropertyKeys.activeItem);
- }
-
- public void setActiveItem(String activeItem) {
- getStateHelper().put(PropertyKeys.activeItem, activeItem);
- }
-
public String getItemChangeListener() {
return (String) getStateHelper().eval(PropertyKeys.itemChangeListener);
}
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java 2010-12-02
18:53:41 UTC (rev 20318)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java 2010-12-02
19:07:45 UTC (rev 20319)
@@ -35,6 +35,7 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import javax.faces.event.ActionEvent;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -75,6 +76,8 @@
String compClientId = component.getClientId(context);
String clientId = requestMap.get(compClientId);
if (clientId != null && clientId.equals(compClientId)) {
+ new ActionEvent(component).queue();
+
AbstractPanelMenuItem panelItem = panelMenu.getItem(newValue);
if (panelItem != null) {
context.getPartialViewContext().getRenderIds().add(panelItem.getClientId(context));
Added:
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/PanelMenuTagHandler.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/PanelMenuTagHandler.java
(rev 0)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/view/facelets/html/PanelMenuTagHandler.java 2010-12-02
19:07:45 UTC (rev 20319)
@@ -0,0 +1,87 @@
+/**
+ * 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.view.facelets.html;
+
+import org.richfaces.event.ItemChangeEvent;
+import org.richfaces.event.ItemChangeSource;
+import org.richfaces.event.MethodExpressionItemChangeListener;
+
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.MetaRule;
+import javax.faces.view.facelets.MetaRuleset;
+import javax.faces.view.facelets.Metadata;
+import javax.faces.view.facelets.MetadataTarget;
+import javax.faces.view.facelets.TagAttribute;
+
+/**
+ * @author akolonitsky
+ * @since Dec 2, 2010
+ */
+public class PanelMenuTagHandler extends ComponentHandler {
+
+ private static final MetaRule META_RULE = new PanelMenuMetaRule();
+
+
+ public PanelMenuTagHandler(ComponentConfig config) {
+ super(config);
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type) {
+ MetaRuleset metaRuleset = super.createMetaRuleset(type);
+ metaRuleset.addRule(META_RULE);
+ return metaRuleset;
+ }
+
+ private static class PanelMenuMetaRule extends MetaRule{
+
+ @Override
+ public Metadata applyRule(String name, TagAttribute attribute, MetadataTarget
meta) {
+ if (meta.isTargetInstanceOf(ItemChangeSource.class)) {
+ if ("itemChangeListener".equals(name)) {
+ return new ItemChangeExpressionMetadata(attribute);
+ }
+
+ }
+
+ return null;
+ }
+ }
+
+ private static final class ItemChangeExpressionMetadata extends Metadata {
+ private static final Class<?>[] ITEM_CHANGE_SIG = new Class[]
{ItemChangeEvent.class };
+
+ private final TagAttribute attr;
+
+ ItemChangeExpressionMetadata(TagAttribute attr) {
+ this.attr = attr;
+ }
+
+ @Override
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ ((ItemChangeSource) instance).addItemChangeListener(new
MethodExpressionItemChangeListener(
+ this.attr.getMethodExpression(ctx, null, ITEM_CHANGE_SIG)));
+ }
+ }
+}
Modified: trunk/ui/output/ui/src/main/resources/META-INF/pn.faces-config.xml
===================================================================
--- trunk/ui/output/ui/src/main/resources/META-INF/pn.faces-config.xml 2010-12-02 18:53:41
UTC (rev 20318)
+++ trunk/ui/output/ui/src/main/resources/META-INF/pn.faces-config.xml 2010-12-02 19:07:45
UTC (rev 20319)
@@ -1638,7 +1638,20 @@
<component>
<component-type>org.richfaces.PanelMenu</component-type>
<component-class>org.richfaces.component.html.HtmlPanelMenu</component-class>
+
<property>
+ <property-name>action</property-name>
+ <property-class>javax.faces.el.MethodBinding</property-class>
+ </property>
+ <property>
+ <property-name>actionExpression</property-name>
+ <property-class>javax.el.MethodExpression</property-class>
+ </property>
+ <property>
+ <property-name>actionListener</property-name>
+ <property-class>javax.faces.el.MethodBinding</property-class>
+ </property>
+ <property>
<description></description>
<property-name>disabled</property-name>
<property-class>boolean</property-class>
Modified: trunk/ui/output/ui/src/main/resources/META-INF/pn.taglib.xml
===================================================================
--- trunk/ui/output/ui/src/main/resources/META-INF/pn.taglib.xml 2010-12-02 18:53:41 UTC
(rev 20318)
+++ trunk/ui/output/ui/src/main/resources/META-INF/pn.taglib.xml 2010-12-02 19:07:45 UTC
(rev 20319)
@@ -211,7 +211,6 @@
<component>
<component-type>org.richfaces.PanelMenuItem</component-type>
<renderer-type>org.richfaces.PanelMenuItem</renderer-type>
-
</component>
<attribute>
<description></description>
@@ -549,9 +548,30 @@
<component>
<component-type>org.richfaces.PanelMenu</component-type>
<renderer-type>org.richfaces.PanelMenu</renderer-type>
-
+
<handler-class>org.richfaces.view.facelets.html.PanelMenuTagHandler</handler-class>
</component>
<attribute>
+ <description>MethodExpression representing the application action to
invoke when this component is activated by the user. The expression must evaluate to a
public method that takes no parameters, and returns an Object (the toString() of which is
called to derive the logical outcome) which is passed to the NavigationHandler for this
application.</description>
+ <display-name>Application Action</display-name>
+ <icon/>
+ <name>action</name>
+ <type>javax.faces.el.MethodBinding</type>
+ </attribute>
+ <attribute>
+ <description>MethodExpression representing the application action to
invoke when this component is activated by the user. The expression must evaluate to a
public method that takes no parameters, and returns an Object (the toString() of which is
called to derive the logical outcome) which is passed to the NavigationHandler for this
application.</description>
+ <display-name>Application Action</display-name>
+ <icon/>
+ <name>actionExpression</name>
+ <type>javax.el.MethodExpression</type>
+ </attribute>
+ <attribute>
+ <description><p> MethodExpression representing an action
listener method that will be notified when this component is activated by the user. The
expression must evaluate to a public method that takes an ActionEvent parameter, with a
return type of void, <span class="changed_added_2_0">or to a
public method that takes no arguments with a return type of void. In the latter case, the
method has no way of easily knowing where the event came from, but this can be useful in
cases where a notification is needed that "some action
happened".</span> </p></description>
+ <display-name>Action Listener</display-name>
+ <icon/>
+ <name>actionListener</name>
+ <type>javax.faces.el.MethodBinding</type>
+ </attribute>
+ <attribute>
<description></description>
<name>disabled</name>
<type>boolean</type>