myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject cvs commit: incubator-myfaces/conf faces-config.xml
Date Mon, 10 Jan 2005 08:22:17 GMT
matzew      2005/01/10 00:22:17

  Modified:    tlds     myfaces_ext.tld
               conf     faces-config.xml
  Added:       src/components/org/apache/myfaces/custom/collapsiblepanel
                        HtmlCollapsiblePanelTag.java
                        HtmlCollapsiblePanel.xml HtmlCollapsiblePanel.java
                        HtmlCollapsiblePanelRenderer.java
  Log:
  added new component CollapsiblePanel (contributed by Kalle Korhonen) (MYFACES-68)
  
  Revision  Changes    Path
  1.1                  incubator-myfaces/src/components/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanelTag.java
  
  Index: HtmlCollapsiblePanelTag.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.myfaces.custom.collapsiblepanel;
  
  import org.apache.myfaces.taglib.html.ext.HtmlPanelGroupTag;
  
  import javax.faces.component.UIComponent;
  
  /**
   * @author Kalle Korhonen (latest modification by $Author: matzew $)
   * @version $Revision: 1.1 $ $Date: 2005/01/10 08:22:17 $
   */
  public class HtmlCollapsiblePanelTag
          extends HtmlPanelGroupTag
  {
      //private static final Log log = LogFactory.getLog(HtmlCollapsiblePanelTag.class);
  
      public String getComponentType()
      {
          return HtmlCollapsiblePanel.COMPONENT_TYPE;
      }
  
      public String getRendererType()
      {
          return "org.apache.myfaces.CollapsiblePanel";
      }
  
      private String _collapsed;
      private String _value;
      // User Role support --> already handled by HtmlPanelGroupTag
  
  
      protected void setProperties(UIComponent component)
      {
          super.setProperties(component);
  
          setBooleanProperty(component, "collapsed", _collapsed);
          setStringProperty(component, "value", _value);
  
      }
  
  
      public void setCollapsed(String collapsed)
      {
          _collapsed = collapsed;
      }
      
      public void setValue(String value)
      {
          _value = value;
      }
  }
  
  
  
  1.1                  incubator-myfaces/src/components/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanel.xml
  
  Index: HtmlCollapsiblePanel.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1" ?>
  <!DOCTYPE component PUBLIC
    "-//MyFaces//DTD MyFaces component def 1.0//EN"
    "http://myfaces.apache.org/dtd/Component.dtd">
  <component>
      <component-class>org.apache.myfaces.custom.collapsiblepanel.HtmlCollapsiblePanel</component-class>
      <base-class>javax.faces.component.html.HtmlPanelGroup</base-class>
      <component-type>org.apache.myfaces.HtmlCollapsiblePanel</component-type>
      <component-family>javax.faces.Panel</component-family>
      <renderer-type>org.apache.myfaces.CollapsiblePanel</renderer-type>
      <field generateProperty="false" >
          <name>collapsedStateChangeListener</name>
          <type>javax.faces.el.MethodBinding</type>
      </field>
      <field>
          <name>collapsed</name>
          <type>java.lang.Boolean</type>
      </field>
      <field>
          <name>value</name>
          <type>java.lang.String</type>
      </field>
  </component>
  
  
  
  1.1                  incubator-myfaces/src/components/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanel.java
  
  Index: HtmlCollapsiblePanel.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.myfaces.custom.collapsiblepanel;
  
  import javax.faces.component.html.HtmlPanelGroup;
  import javax.faces.context.FacesContext;
  import javax.faces.el.ValueBinding;
  
  /**
   * @author Kalle Korhonen (latest modification by $Author: matzew $)
   * 
   * @version $Revision: 1.1 $ $Date: 2005/01/10 08:22:17 $
   *
   */
  public class HtmlCollapsiblePanel extends HtmlPanelGroup
  {
    	//private static final Log log = LogFactory.getLog(HtmlCollapsiblePanel.class);
  	
      //------------------ GENERATED CODE BEGIN (do not modify!) --------------------
      private static final boolean DEFAULT_COLLAPSED = true;
  
      public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlCollapsiblePanel";
      public static final String COMPONENT_FAMILY = "javax.faces.Panel";
      private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.CollapsiblePanel";
  
      private Boolean _collapsed = null;
      private String _value = null;
      
      public HtmlCollapsiblePanel()
      {
          setRendererType(DEFAULT_RENDERER_TYPE);
      }
  
      public String getFamily()
      {
          return COMPONENT_FAMILY;
      }
  
      public void setCollapsed(boolean collapsed)
      {
          _collapsed = new Boolean(collapsed);
      }
  
      public boolean isCollapsed()
      {
          if (_collapsed != null) return _collapsed.booleanValue();
          ValueBinding vb = getValueBinding("collapsed");
          Boolean v = vb != null ? (Boolean)vb.getValue(getFacesContext()) : null;
          return v != null ? v.booleanValue() : DEFAULT_COLLAPSED;
      }
      
      public void setValue(String value)
      {
          _value = value;
      }
  
      public String getValue()
      {
          if (_value != null) return _value;
          ValueBinding vb = getValueBinding("value");
          return vb != null ? (String)vb.getValue(getFacesContext()) : null;
      }
  
      public Object saveState(FacesContext context)
      {
          Object values[] = new Object[3];
          values[0] = super.saveState(context);
          values[1] = _collapsed;
          values[2] = _value;
          return ((Object) (values));
      }
  
      public void restoreState(FacesContext context, Object state)
      {
      	  Object values[] = (Object[])state;
          super.restoreState(context, values[0]);
          _collapsed = (Boolean)values[1];
          _value = (String)values[2];
      }
      //------------------ GENERATED CODE END ---------------------------------------
  }
  
  
  
  1.1                  incubator-myfaces/src/components/org/apache/myfaces/custom/collapsiblepanel/HtmlCollapsiblePanelRenderer.java
  
  Index: HtmlCollapsiblePanelRenderer.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.myfaces.custom.collapsiblepanel;
  
  import org.apache.myfaces.renderkit.RendererUtils;
  import org.apache.myfaces.renderkit.html.HTML;
  import org.apache.myfaces.renderkit.html.HtmlRenderer;
  import org.apache.myfaces.renderkit.html.HtmlRendererUtils;
  
  import javax.faces.application.Application;
  import javax.faces.application.ViewHandler;
  import javax.faces.component.UIComponent;
  import javax.faces.component.html.HtmlCommandLink;
  import javax.faces.component.html.HtmlOutputText;
  import javax.faces.context.FacesContext;
  import javax.faces.context.ResponseWriter;
  
  import java.io.IOException;
  import java.util.List;
  
  /**
   * @author Kalle Korhonen (latest modification by $Author: matzew $)
   * @version $Revision: 1.1 $ $Date: 2005/01/10 08:22:17 $
   * $Log: HtmlCollapsiblePanelRenderer.java,v $
   * Revision 1.1  2005/01/10 08:22:17  matzew
   * added new component CollapsiblePanel (contributed by Kalle Korhonen) (MYFACES-68)
   *
   * 
   */
  public class HtmlCollapsiblePanelRenderer extends HtmlRenderer {
      //private static final Log log = LogFactory.getLog(HtmlCollapsiblePanel.class);
      private static final String LINK_ID     = "ToggleCollapsed".intern();
  
      public boolean getRendersChildren()
      {
          return true;
      }
      
      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);
        
        // 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, null);
        	RendererUtils.renderChildren(facesContext, uiComponent);
          writer.endElement(HTML.DIV_ELEM );
          HtmlRendererUtils.writePrettyLineSeparator(facesContext);
        }
  
        link.setRendered(true);
      }
  
      public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException
      {
        RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlCollapsiblePanel.class);
        ResponseWriter writer = facesContext.getResponseWriter();
  
        HtmlRendererUtils.writePrettyLineSeparator(facesContext);
      	writer.startElement(HTML.DIV_ELEM, null);
      	
        HtmlCollapsiblePanel collapsiblePanel = (HtmlCollapsiblePanel)uiComponent;
        ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
        String viewId = facesContext.getViewRoot().getViewId();
        String actionURL = viewHandler.getActionURL(facesContext, viewId);
  
        Application application = 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);
      }
      
      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()
);
      }
      
      protected HtmlCommandLink getLink(FacesContext facesContext, HtmlCollapsiblePanel collapsiblePanel)
          throws IOException
      {
          Application application = facesContext.getApplication();
          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() ? "&gt;" : "&#957;");
  				uiText.setEscape(false);
  				uiText.setStyleClass(collapsiblePanel.getStyleClass());
  				uiText.setStyle(collapsiblePanel.getStyle());
  				children.add(uiText);
  				
  				// 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;
      }
     
      
      // 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
      // know how to get a reference to it back in a new encoding phase 
      /*
      public static class ChangeCollapsedHandler implements ActionListener {
      	// Can't make this class anonymous, because it won't work with state saving
      	// refer to http://forum.java.sun.com/thread.jspa?messageID=2885214&#2885214
      	
  		  /* (non-Javadoc)
  		  * @see javax.faces.event.ActionListener#processAction(javax.faces.event.ActionEvent)
  		  */
      /*
        public void processAction(ActionEvent actionEvent) throws AbortProcessingException
{
      		log.info("Got action event, processing " + actionEvent.getComponent().getId() + ",
phase id " + actionEvent.getPhaseId() );
      		if (!(actionEvent.getComponent().getParent() instanceof HtmlCollapsiblePanel) ) 
      			throw new AbortProcessingException("The parent of the action source was of unexpected
type, HtmlCollapsiblePanel was expected");
      		HtmlCollapsiblePanel collapsiblePanel = (HtmlCollapsiblePanel)actionEvent.getComponent().getParent();

      		collapsiblePanel.setCollapsed(!collapsiblePanel.isCollapsed() );
          // Note that we need to remove the listeners here, otherwise they will be fired
again for old components,
          // don't quite understand why
          ActionListener[] listeners = collapsiblePanel.getLink().getActionListeners();
          for (int i= 0; i< listeners.length; i++) collapsiblePanel.getLink().removeActionListener(listeners[i]);
      	}
  		}
      */
  }
  
  
  
  1.152     +29 -0     incubator-myfaces/tlds/myfaces_ext.tld
  
  Index: myfaces_ext.tld
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/tlds/myfaces_ext.tld,v
  retrieving revision 1.151
  retrieving revision 1.152
  diff -u -r1.151 -r1.152
  --- myfaces_ext.tld	9 Jan 2005 21:56:33 -0000	1.151
  +++ myfaces_ext.tld	10 Jan 2005 08:22:17 -0000	1.152
  @@ -1288,6 +1288,35 @@
       </tag>
   
   
  +    <!-- collapsiblePanel -->
  +    <tag>
  +        <name>collapsiblePanel</name>
  +        <tag-class>org.apache.myfaces.custom.collapsiblepanel.HtmlCollapsiblePanelTag</tag-class>
  +        <body-content>JSP</body-content>
  +        &ui_panel_attributes;
  +        &html_universal_attributes;
  +        &html_event_handler_attributes;
  +        &html_table_attributes;
  +        &user_role_attributes;
  +        <attribute>
  +            <name>collapsed</name>
  +            <required>false</required>
  +            <rtexprvalue>false</rtexprvalue>
  +            <description>
  +               Boolean value indicating whether the panel should be collapsed by default.
  +            </description>
  +        </attribute>
  +        <attribute>
  +            <name>value</name>
  +            <required>false</required>
  +            <rtexprvalue>false</rtexprvalue>
  +            <description>
  +                Label for collapsible panel.
  +            </description>
  +        </attribute>
  +    </tag>
  +
  +
   	<!-- stylesheet -->
   
   	<tag>
  
  
  
  1.106     +11 -1     incubator-myfaces/conf/faces-config.xml
  
  Index: faces-config.xml
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/conf/faces-config.xml,v
  retrieving revision 1.105
  retrieving revision 1.106
  diff -u -r1.105 -r1.106
  --- faces-config.xml	9 Jan 2005 12:36:58 -0000	1.105
  +++ faces-config.xml	10 Jan 2005 08:22:17 -0000	1.106
  @@ -191,6 +191,11 @@
     </component>
   
     <component>
  +    <component-type>org.apache.myfaces.HtmlCollapsiblePanel</component-type>
  +    <component-class>org.apache.myfaces.custom.collapsiblepanel.HtmlCollapsiblePanel</component-class>
  +  </component>
  +  
  +  <component>
       <component-type>org.apache.myfaces.HtmlRadio</component-type>
       <component-class>org.apache.myfaces.custom.radio.HtmlRadio</component-class>
     </component>
  @@ -461,6 +466,12 @@
               <renderer-class>org.apache.myfaces.custom.tabbedpane.HtmlTabbedPaneRenderer</renderer-class>
           </renderer>
   
  +	  <renderer>
  +			<component-family>javax.faces.Panel</component-family>
  +			<renderer-type>org.apache.myfaces.CollapsiblePanel</renderer-type>
  +			<renderer-class>org.apache.myfaces.custom.collapsiblepanel.HtmlCollapsiblePanelRenderer</renderer-class>
  +	  </renderer>
  +
         <renderer>
             <component-family>javax.faces.Data</component-family>
             <renderer-type>org.apache.myfaces.List</renderer-type>
  @@ -573,5 +584,4 @@
   		<validator-id>org.apache.myfaces.validator.RegExpr</validator-id>
   		<validator-class>org.apache.myfaces.custom.regexprvalidator.RegExprValidator</validator-class>
   	</validator>
  -
   </faces-config>
  
  
  

Mime
View raw message