You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2005/10/19 16:03:19 UTC
svn commit: r326564 - in
/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/collapsiblepanel:
HtmlCollapsiblePanel.java HtmlCollapsiblePanelRenderer.java
Author: mmarinschek
Date: Wed Oct 19 07:03:14 2005
New Revision: 326564
URL: http://svn.apache.org/viewcvs?rev=326564&view=rev
Log:
improved Collapsible Panel
Modified:
myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanel.java
myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanelRenderer.java
Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanel.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanel.java?rev=326564&r1=326563&r2=326564&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanel.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanel.java Wed Oct 19 07:03:14 2005
@@ -16,8 +16,10 @@
package org.apache.myfaces.custom.collapsiblepanel;
import javax.faces.component.html.HtmlPanelGroup;
+import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
+import java.util.Iterator;
/**
* @author Kalle Korhonen (latest modification by $Author$)
@@ -27,8 +29,43 @@
*/
public class HtmlCollapsiblePanel extends HtmlPanelGroup
{
- //private static final Log log = LogFactory.getLog(HtmlCollapsiblePanel.class);
-
+ //private static final Log log = LogFactory.getLog(HtmlCollapsiblePanel.class);
+
+ public void processDecodes(FacesContext context)
+ {
+ if (context == null) throw new NullPointerException("context");
+
+ if (!isRendered()) return;
+
+ try
+ {
+ decode(context);
+ }
+ catch (RuntimeException e)
+ {
+ context.renderResponse();
+ throw e;
+ }
+
+ if(isCollapsed())
+ {
+ for (Iterator it = getChildren().iterator(); it.hasNext(); )
+ {
+ UIComponent child = (UIComponent)it.next();
+ child.processDecodes(context);
+ }
+ }
+ else
+ {
+ UIComponent component = getFacet("closedContent");
+
+ if(component != null)
+ {
+ component.processDecodes(context);
+ }
+ }
+ }
+
//------------------ GENERATED CODE BEGIN (do not modify!) --------------------
private static final boolean DEFAULT_COLLAPSED = true;
@@ -38,7 +75,7 @@
private Boolean _collapsed = null;
private String _value = null;
-
+
public HtmlCollapsiblePanel()
{
setRendererType(DEFAULT_RENDERER_TYPE);
@@ -61,7 +98,7 @@
Boolean v = vb != null ? (Boolean)vb.getValue(getFacesContext()) : null;
return v != null ? v.booleanValue() : DEFAULT_COLLAPSED;
}
-
+
public void setValue(String value)
{
_value = value;
@@ -85,7 +122,7 @@
public void restoreState(FacesContext context, Object state)
{
- Object values[] = (Object[])state;
+ Object values[] = (Object[])state;
super.restoreState(context, values[0]);
_collapsed = (Boolean)values[1];
_value = (String)values[2];
Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanelRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanelRenderer.java?rev=326564&r1=326563&r2=326564&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanelRenderer.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanelRenderer.java Wed Oct 19 07:03:14 2005
@@ -35,9 +35,10 @@
* @author Kalle Korhonen (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class HtmlCollapsiblePanelRenderer extends HtmlRenderer {
+public class HtmlCollapsiblePanelRenderer extends HtmlRenderer
+{
//private static final Log log = LogFactory.getLog(HtmlCollapsiblePanel.class);
- private static final String LINK_ID = "ToggleCollapsed".intern();
+ private static final String LINK_ID = "ToggleCollapsed".intern();
public boolean getRendersChildren()
{
@@ -46,96 +47,109 @@
public void encodeChildren(FacesContext facesContext, UIComponent uiComponent) throws IOException
{
- // RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlCollapsiblePanel.class);
- ResponseWriter writer = facesContext.getResponseWriter();
- HtmlCollapsiblePanel collapsiblePanel = (HtmlCollapsiblePanel)uiComponent;
-
- HtmlCommandLink link = getLink(facesContext, collapsiblePanel);
- collapsiblePanel.getChildren().add(link);
-
- // Always render the link to toggle the collapsed state
- RendererUtils.renderChild(facesContext, link);
- link.setRendered(false);
+ // RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlCollapsiblePanel.class);
+ ResponseWriter writer = facesContext.getResponseWriter();
+ HtmlCollapsiblePanel collapsiblePanel = (HtmlCollapsiblePanel) uiComponent;
+
+ HtmlCommandLink link = getLink(facesContext, collapsiblePanel);
+ collapsiblePanel.getChildren().add(link);
+
+ // Always render the link to toggle the collapsed state
+ RendererUtils.renderChild(facesContext, link);
+ link.setRendered(false);
+
+ // conditionally render the rest of the children
+ if (!collapsiblePanel.isCollapsed())
+ {
+ HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+ // TODO apply styles from the parent element to this DIV
+ writer.startElement(HTML.DIV_ELEM, uiComponent);
+ RendererUtils.renderChildren(facesContext, uiComponent);
+ writer.endElement(HTML.DIV_ELEM);
+ HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+ }
+ else
+ {
+ UIComponent component = collapsiblePanel.getFacet("closedContent");
+ if (component != null)
+ {
+ writer.startElement(HTML.DIV_ELEM, uiComponent);
+ RendererUtils.renderChild(facesContext, component);
+ writer.endElement(HTML.DIV_ELEM);
+ HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+ }
+ }
- // conditionally render the rest of the children
- if (!collapsiblePanel.isCollapsed()) {
- HtmlRendererUtils.writePrettyLineSeparator(facesContext);
- // TODO apply styles from the parent element to this DIV
- writer.startElement(HTML.DIV_ELEM, uiComponent);
- RendererUtils.renderChildren(facesContext, uiComponent);
- writer.endElement(HTML.DIV_ELEM );
- HtmlRendererUtils.writePrettyLineSeparator(facesContext);
- }
-
- link.setRendered(true);
+ link.setRendered(true);
}
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException
{
- RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlCollapsiblePanel.class);
- ResponseWriter writer = facesContext.getResponseWriter();
+ RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlCollapsiblePanel.class);
+ ResponseWriter writer = facesContext.getResponseWriter();
- HtmlRendererUtils.writePrettyLineSeparator(facesContext);
- writer.startElement(HTML.DIV_ELEM, uiComponent);
+ HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+ writer.startElement(HTML.DIV_ELEM, uiComponent);
- ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
- String viewId = facesContext.getViewRoot().getViewId();
- viewHandler.getActionURL(facesContext, viewId);
+ ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
+ String viewId = facesContext.getViewRoot().getViewId();
+ viewHandler.getActionURL(facesContext, viewId);
- facesContext.getApplication();
+ facesContext.getApplication();
}
public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException
{
- //RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlCollapsiblePanel.class);
- ResponseWriter writer = facesContext.getResponseWriter();
- writer.endElement(HTML.DIV_ELEM );
- HtmlRendererUtils.writePrettyLineSeparator(facesContext);
+ //RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlCollapsiblePanel.class);
+ ResponseWriter writer = facesContext.getResponseWriter();
+ writer.endElement(HTML.DIV_ELEM);
+ HtmlRendererUtils.writePrettyLineSeparator(facesContext);
}
public void decode(FacesContext facesContext, UIComponent uiComponent)
{
- RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlCollapsiblePanel.class);
- HtmlCollapsiblePanel collapsiblePanel = (HtmlCollapsiblePanel)uiComponent;
- String reqValue = (String)facesContext.getExternalContext().getRequestParameterMap().get(HtmlRendererUtils.getHiddenCommandLinkFieldName(HtmlRendererUtils.getFormName(collapsiblePanel, facesContext)));
- //log.debug("new component's id is " + collapsiblePanel.getClientId(facesContext) + ", req id is " + reqValue);
- if ((collapsiblePanel.getClientId(facesContext) + LINK_ID).equals(reqValue)) collapsiblePanel.setCollapsed(!collapsiblePanel.isCollapsed() );
+ RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlCollapsiblePanel.class);
+ HtmlCollapsiblePanel collapsiblePanel = (HtmlCollapsiblePanel) uiComponent;
+ String reqValue = (String) facesContext.getExternalContext().getRequestParameterMap().get(HtmlRendererUtils.getHiddenCommandLinkFieldName(HtmlRendererUtils.getFormName(collapsiblePanel, facesContext)));
+ //log.debug("new component's id is " + collapsiblePanel.getClientId(facesContext) + ", req id is " + reqValue);
+ if ((collapsiblePanel.getClientId(facesContext) + LINK_ID).equals(reqValue))
+ collapsiblePanel.setCollapsed(!collapsiblePanel.isCollapsed());
}
protected HtmlCommandLink getLink(FacesContext facesContext, HtmlCollapsiblePanel collapsiblePanel)
- throws IOException
+ throws IOException
{
Application application = facesContext.getApplication();
- HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
- link.setId(collapsiblePanel.getId() + LINK_ID );
+ HtmlCommandLink link = (HtmlCommandLink) application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
+ link.setId(collapsiblePanel.getId() + LINK_ID);
link.setTransient(true);
link.setImmediate(true);
//link.addActionListener(new ChangeCollapsedHandler());
List children = link.getChildren();
- // Create the indicator. You could later make this conditional and render optional images instead
- HtmlOutputText uiText = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
- uiText.setTransient(true);
- uiText.setValue(collapsiblePanel.isCollapsed() ? ">" : "ν");
- uiText.setEscape(false);
- uiText.setStyleClass(collapsiblePanel.getStyleClass());
- uiText.setStyle(collapsiblePanel.getStyle());
- children.add(uiText);
+ // Create the indicator. You could later make this conditional and render optional images instead
+ HtmlOutputText uiText = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
+ uiText.setTransient(true);
+ uiText.setValue(collapsiblePanel.isCollapsed() ? ">" : "ν");
+ uiText.setEscape(false);
+ uiText.setStyleClass(collapsiblePanel.getStyleClass());
+ uiText.setStyle(collapsiblePanel.getStyle());
+ children.add(uiText);
- // Create the optional label
+ // Create the optional label
String label = collapsiblePanel.getValue();
- if (label != null) {
- uiText = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
- uiText.setTransient(true);
- uiText.setValue(" " + label);
- uiText.setStyleClass(collapsiblePanel.getStyleClass());
- uiText.setStyle(collapsiblePanel.getStyle());
- children.add(uiText);
- }
- return link;
+ if (label != null)
+ {
+ uiText = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
+ uiText.setTransient(true);
+ uiText.setValue(" " + label);
+ uiText.setStyleClass(collapsiblePanel.getStyleClass());
+ uiText.setStyle(collapsiblePanel.getStyle());
+ children.add(uiText);
+ }
+ return link;
}
-
// Couldn't get an ActionListner for a link to work properly. With each page submit, one more
// event was fired. I assume it is because the link component was set to transparent, and I didn't