myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svieu...@apache.org
Subject cvs commit: incubator-myfaces/webapps/examples/web buffer.jsp
Date Tue, 04 Jan 2005 15:41:06 GMT
svieujot    2005/01/04 07:41:06

  Modified:    src/components/org/apache/myfaces/custom/aliasbean
                        AliasBean.xml AliasBean.java
               webapps/examples/src/org/apache/myfaces/examples/resource
                        example_messages.properties
               src/myfaces/org/apache/myfaces/renderkit/html
                        HtmlResponseWriterImpl.java
               webapps/examples/web/inc page_header.jsp navigation.jsp
               conf     faces-config.xml
               doc      release-notes.txt
               tlds     myfaces_ext.tld
               webapps/examples/web/WEB-INF examples-config.xml
  Added:       src/components/org/apache/myfaces/custom/buffer
                        HTMLEncoder.java Buffer.java BufferRenderer.java
                        BufferTag.java HtmlResponseWriterImpl.java
               webapps/examples/web buffer.jsp
  Log:
  new x:buffer component.
  
  Revision  Changes    Path
  1.2       +1 -1      incubator-myfaces/src/components/org/apache/myfaces/custom/aliasbean/AliasBean.xml
  
  Index: AliasBean.xml
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/aliasbean/AliasBean.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AliasBean.xml	8 Nov 2004 20:43:15 -0000	1.1
  +++ AliasBean.xml	4 Jan 2005 15:41:06 -0000	1.2
  @@ -6,5 +6,5 @@
       <component-class>org.apache.myfaces.custom.aliasbean.AliasBean</component-class>
       <base-class>javax.faces.component.UIInput</base-class>
       <component-type>org.apache.myfaces.AliasBean</component-type>
  -    <component-family>javax.faces.Input</component-family>
  +    <component-family>javax.faces.Data</component-family>
   </component>
  
  
  
  1.5       +7 -4      incubator-myfaces/src/components/org/apache/myfaces/custom/aliasbean/AliasBean.java
  
  Index: AliasBean.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/aliasbean/AliasBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AliasBean.java	23 Nov 2004 11:03:35 -0000	1.4
  +++ AliasBean.java	4 Jan 2005 15:41:06 -0000	1.5
  @@ -22,7 +22,7 @@
   import java.util.Map;
   
   import javax.faces.component.UIComponent;
  -import javax.faces.component.UIInput;
  +import javax.faces.component.UIComponentBase;
   import javax.faces.context.FacesContext;
   import javax.faces.el.ValueBinding;
   import javax.faces.event.AbortProcessingException;
  @@ -45,9 +45,12 @@
    * 
    * @author Sylvain Vieujot (latest modification by $Author$)
    * @version $Revision$ $Date$ $Log$
  - * @version $Revision: 1.3 $ $Date: 2004/11/23 04:46:40 $ Revision 1.4  2004/11/23 11:03:35  svieujot
  - * @version $Revision: 1.3 $ $Date: 2004/11/23 04:46:40 $ Get ride of the x:aliasBean "permanent" attribute.
  - * @version $Revision: 1.3 $ $Date: 2004/11/23 04:46:40 $
  + * @version $Revision: 1.4 $ $Date: 2004/11/23 11:03:35 $ Revision 1.5  2005/01/04 15:41:06  svieujot
  + * @version $Revision: 1.4 $ $Date: 2004/11/23 11:03:35 $ new x:buffer component.
  + * @version $Revision: 1.4 $ $Date: 2004/11/23 11:03:35 $
  + * @version $Revision$ $Date$ Revision 1.4  2004/11/23 11:03:35  svieujot
  + * @version $Revision$ $Date$ Get ride of the x:aliasBean "permanent" attribute.
  + * @version $Revision$ $Date$
    *          Revision 1.3 2004/11/23 04:46:40 svieujot Add an ugly "permanent"
    *          tag to x:aliasBean to handle children events.
    * 
  @@ -57,11 +60,11 @@
    * Revision 1.1 2004/11/08 20:43:15 svieujot Add an x:aliasBean component
    * 
    */
  -public class AliasBean extends UIInput {
  +public class AliasBean extends UIComponentBase {
       private static final Log log = LogFactory.getLog(AliasBean.class);
   
       public static final String COMPONENT_TYPE = "org.apache.myfaces.AliasBean";
  -
  +    public static final String COMPONENT_FAMILY = "javax.faces.Data";
       private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.AliasBean";
   
       private String _sourceBeanExpression = null;
  
  
  
  1.14      +1 -0      incubator-myfaces/webapps/examples/src/org/apache/myfaces/examples/resource/example_messages.properties
  
  Index: example_messages.properties
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/webapps/examples/src/org/apache/myfaces/examples/resource/example_messages.properties,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- example_messages.properties	4 Jan 2005 00:28:06 -0000	1.13
  +++ example_messages.properties	4 Jan 2005 15:41:06 -0000	1.14
  @@ -7,6 +7,7 @@
   nav_Sample_1        = Sample 1
   nav_Sample_2        = Sample 2
   nav_aliasBean       = Alias Bean
  +nav_buffer          = Buffer
   nav_dataTable       = Master/Detail Example
   nav_sortTable       = Sortable Table
   nav_Documentation   = Documentation
  
  
  
  1.32      +10 -2     incubator-myfaces/src/myfaces/org/apache/myfaces/renderkit/html/HtmlResponseWriterImpl.java
  
  Index: HtmlResponseWriterImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/renderkit/html/HtmlResponseWriterImpl.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- HtmlResponseWriterImpl.java	27 Dec 2004 04:11:11 -0000	1.31
  +++ HtmlResponseWriterImpl.java	4 Jan 2005 15:41:06 -0000	1.32
  @@ -36,6 +36,9 @@
    * @author Anton Koinov
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.32  2005/01/04 15:41:06  svieujot
  + * new x:buffer component.
  + *
    * Revision 1.31  2004/12/27 04:11:11  mmarinschek
    * Data Table stores the state of facets of children; script tag is rendered with type attribute instead of language attribute, popup works better as a column in a data table
    *
  @@ -513,5 +516,10 @@
               _dummyFormParams = new HashSet();
           }
           _dummyFormParams.add(paramName);
  +    }
  +    
  +    public Set getDummyFormParams()
  +    {
  +        return _dummyFormParams;
       }
   }
  
  
  
  1.45      +1 -0      incubator-myfaces/webapps/examples/web/inc/page_header.jsp
  
  Index: page_header.jsp
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/webapps/examples/web/inc/page_header.jsp,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- page_header.jsp	28 Dec 2004 21:45:06 -0000	1.44
  +++ page_header.jsp	4 Jan 2005 15:41:06 -0000	1.45
  @@ -24,6 +24,7 @@
               <x:navigationMenuItem id="nav_2_3" itemLabel="#{example_messages['nav_Validate']}" action="go_validate" icon="images/myfaces.gif" />
               <x:navigationMenuItem id="nav_2_4" itemLabel="#{example_messages['nav_Components']}" icon="images/component.gif" split="true" >
   	            <x:navigationMenuItem id="nav_2_4_1" itemLabel="#{example_messages['nav_aliasBean']}" action="go_aliasBean" icon="images/myfaces.gif" />
  +  	            <x:navigationMenuItem id="nav_2_4_1_2" itemLabel="#{example_messages['nav_buffer']}" action="go_buffer" icon="images/myfaces.gif" />
                   <x:navigationMenuItem id="nav_2_4_2" itemLabel="#{example_messages['nav_dataTable']}" action="go_dataTable" icon="images/myfaces.gif" />
                   <x:navigationMenuItem id="nav_2_4_3" itemLabel="#{example_messages['nav_sortTable']}" action="go_sortTable" icon="images/myfaces.gif" />
                   <x:navigationMenuItem id="nav_2_4_4" itemLabel="#{example_messages['nav_Selectbox']}" action="go_selectbox" icon="images/myfaces.gif" />
  
  
  
  1.46      +1 -0      incubator-myfaces/webapps/examples/web/inc/navigation.jsp
  
  Index: navigation.jsp
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/webapps/examples/web/inc/navigation.jsp,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- navigation.jsp	17 Dec 2004 13:19:11 -0000	1.45
  +++ navigation.jsp	4 Jan 2005 15:41:06 -0000	1.46
  @@ -14,6 +14,7 @@
           <x:commandNavigation id="nav_2_3" value="#{example_messages['nav_Validate']}" action="go_validate" />
           <x:commandNavigation id="nav_2_4" value="#{example_messages['nav_Components']}" >
               <x:commandNavigation id="nav_2_4_1" value="#{example_messages['nav_aliasBean']}" action="go_aliasBean" />
  +            <x:commandNavigation id="nav_2_4_1_2" value="#{example_messages['nav_buffer']}" action="go_buffer" />
               <x:commandNavigation id="nav_2_4_2" value="#{example_messages['nav_dataTable']}" action="go_dataTable" />
               <x:commandNavigation id="nav_2_4_3" value="#{example_messages['nav_sortTable']}" action="go_sortTable" />
               <x:commandNavigation id="nav_2_4_4" value="#{example_messages['nav_Selectbox']}" action="go_selectbox" />
  
  
  
  1.103     +12 -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.102
  retrieving revision 1.103
  diff -u -r1.102 -r1.103
  --- faces-config.xml	22 Dec 2004 17:52:54 -0000	1.102
  +++ faces-config.xml	4 Jan 2005 15:41:06 -0000	1.103
  @@ -99,6 +99,11 @@
       <component-type>org.apache.myfaces.AliasBean</component-type>
       <component-class>org.apache.myfaces.custom.aliasbean.AliasBean</component-class>
     </component>
  +  
  +  <component>
  +    <component-type>org.apache.myfaces.Buffer</component-type>
  +    <component-class>org.apache.myfaces.custom.buffer.Buffer</component-class>
  +  </component>
   
     <component>
       <component-type>org.apache.myfaces.HtmlCheckbox</component-type>
  @@ -355,9 +360,15 @@
           <!-- custom component renderers -->
   
           <renderer>
  -            <component-family>javax.faces.Input</component-family>
  +            <component-family>javax.faces.Data</component-family>
               <renderer-type>org.apache.myfaces.AliasBean</renderer-type>
               <renderer-class>org.apache.myfaces.custom.aliasbean.AliasBeanRenderer</renderer-class>
  +        </renderer>
  +        
  +        <renderer>
  +            <component-family>javax.faces.Data</component-family>
  +            <renderer-type>org.apache.myfaces.Buffer</renderer-type>
  +            <renderer-class>org.apache.myfaces.custom.buffer.BufferRenderer</renderer-class>
           </renderer>
   
   		<renderer>
  
  
  
  1.157     +1 -0      incubator-myfaces/doc/release-notes.txt
  
  Index: release-notes.txt
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/doc/release-notes.txt,v
  retrieving revision 1.156
  retrieving revision 1.157
  diff -u -r1.156 -r1.157
  --- release-notes.txt	30 Dec 2004 16:43:42 -0000	1.156
  +++ release-notes.txt	4 Jan 2005 15:41:06 -0000	1.157
  @@ -1,6 +1,7 @@
   MyFaces Release Notes
   =====================
   
  +* new x:buffer component
   ----------------------------------------------------------------------
   Changes in Release 1.0.8 beta_RC2
   * added a new RenderKit, that renders WML. Thanks to Jiri Zaloudek for his contribution
  
  
  
  1.1                  incubator-myfaces/src/components/org/apache/myfaces/custom/buffer/HTMLEncoder.java
  
  Index: HTMLEncoder.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.buffer;
  
  /**
   * This is the exact same class as the one from org.apache.myfaces.renderkit.html package.
   * 
   * Converts Strings so that they can be used within HTML-Code.
   */
  public abstract class HTMLEncoder
  {
  	/**
  	 * Variant of {@link #encode} where encodeNewline is false and encodeNbsp is true.
  	 */
  	public static String encode (String string)
  	{
  		return encode(string, false, true);
  	}
  
  	/**
  	 * Variant of {@link #encode} where encodeNbsp is true.
  	 */
  	public static String encode (String string, boolean encodeNewline)
  	{
  		return encode(string, encodeNewline, true);
  	}
  
  	/**
  	 * Encodes the given string, so that it can be used within a html page.
  	 * @param string the string to convert
  	 * @param encodeNewline if true newline characters are converted to &lt;br&gt;'s
  	 * @param encodeSubsequentBlanksToNbsp if true subsequent blanks are converted to &amp;nbsp;'s
  	 */
  	public static String encode (String string,
  								 boolean encodeNewline,
  								 boolean encodeSubsequentBlanksToNbsp)
  	{
  		if (string == null)
  		{
  			return "";
  		}
  
  		StringBuffer sb = null;	//create later on demand
  		String app;
  		char c;
  		for (int i = 0; i < string.length (); ++i)
  		{
  			app = null;
  			c = string.charAt(i);
  			switch (c)
  			{
                  case '"': app = "&quot;"; break;    //"
                  case '&': app = "&amp;"; break;     //&
                  case '<': app = "&lt;"; break;      //<
                  case '>': app = "&gt;"; break;      //>
                  case ' ':
                      if (encodeSubsequentBlanksToNbsp &&
                          (i == 0 || (i - 1 >= 0 && string.charAt(i - 1) == ' ')))
                      {
                          //Space at beginning or after another space
                          app = "&nbsp;";
                      }
                      break;
                  case '\n':
                      if (encodeNewline)
                      {
                          app = "<br/>";
                      }
                      break;
  
                  //german umlauts
  			    case '\u00E4' : app = "&auml;";  break;
  			    case '\u00C4' : app = "&Auml;";  break;
  			    case '\u00F6' : app = "&ouml;";  break;
  			    case '\u00D6' : app = "&Ouml;";  break;
  			    case '\u00FC' : app = "&uuml;";  break;
  			    case '\u00DC' : app = "&Uuml;";  break;
  			    case '\u00DF' : app = "&szlig;"; break;
  
                  //misc
                  //case 0x80: app = "&euro;"; break;  sometimes euro symbol is ascii 128, should we suport it?
                  case '\u20AC': app = "&euro;";  break;
                  case '\u00AB': app = "&laquo;"; break;
                  case '\u00BB': app = "&raquo;"; break;
                  case '\u00A0': app = "&nbsp;"; break;
  
                  default:
                      if (((int)c) >= 0x80)
                      {
                          //encode all non basic latin characters
                          app = "&#" + ((int)c) + ";";
                      }
                      break;
  			}
  			if (app != null)
  			{
  				if (sb == null)
  				{
  					sb = new StringBuffer(string.substring(0, i));
  				}
  				sb.append(app);
  			} else {
  				if (sb != null)
  				{
  					sb.append(c);
  				}
  			}
  		}
  
  		if (sb == null)
  		{
  			return string;
  		}
  		else
  		{
  			return sb.toString();
  		}
  	}
  
  
  }
  
  
  
  1.1                  incubator-myfaces/src/components/org/apache/myfaces/custom/buffer/Buffer.java
  
  Index: Buffer.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.buffer;
  
  import javax.faces.component.UIComponentBase;
  import javax.faces.context.FacesContext;
  import javax.faces.el.ValueBinding;
  
  /**
   * @author Sylvain Vieujot (latest modification by $Author: svieujot $)
   * @version $Revision: 1.1 $ $Date: 2005/01/04 15:41:06 $
   * $Log: Buffer.java,v $
   * Revision 1.1  2005/01/04 15:41:06  svieujot
   * new x:buffer component.
   *
   */
  public class Buffer extends UIComponentBase{
  
      public static final String COMPONENT_TYPE = "org.apache.myfaces.Buffer";
      public static final String COMPONENT_FAMILY = "javax.faces.Data";
      private static final String DEFAULT_RENDERER_TYPE = BufferRenderer.RENDERER_TYPE;
  
      private String _intoExpression = null;
  
      public Buffer(){
          setRendererType(DEFAULT_RENDERER_TYPE);
      }
  
      public String getFamily(){
          return COMPONENT_FAMILY;
      }
  
      public void setInto(String intoExpression){
          _intoExpression = intoExpression;
      }
  
      public Object saveState(FacesContext context){
          Object values[] = new Object[2];
          values[0] = super.saveState(context);
          values[1] = _intoExpression;
          return values;
      }
  
      public void restoreState(FacesContext context, Object state){
          Object values[] = (Object[]) state;
          super.restoreState(context, values[0]);
          _intoExpression = (String) values[1];
      }
      
      void fill(Object content, FacesContext facesContext){
          ValueBinding intoVB;
          
          if (_intoExpression == null) {
              intoVB = getValueBinding("into");
              _intoExpression = intoVB.getExpressionString();
          } else {
              intoVB = facesContext.getApplication().createValueBinding( _intoExpression );
          }
  
          intoVB.setValue(facesContext, content.toString());
      }
  }
  
  
  1.1                  incubator-myfaces/src/components/org/apache/myfaces/custom/buffer/BufferRenderer.java
  
  Index: BufferRenderer.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.buffer;
  
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.io.UnsupportedEncodingException;
  import java.lang.reflect.Method;
  import java.util.Iterator;
  
  import javax.faces.component.UIComponent;
  import javax.faces.context.FacesContext;
  import javax.faces.context.ResponseWriter;
  import javax.faces.render.Renderer;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.myfaces.renderkit.RendererUtils;
  
  /**
   * @author Sylvain Vieujot (latest modification by $Author: svieujot $)
   * @version $Revision: 1.1 $ $Date: 2005/01/04 15:41:06 $
   * $Log: BufferRenderer.java,v $
   * Revision 1.1  2005/01/04 15:41:06  svieujot
   * new x:buffer component.
   *
   */
  public class BufferRenderer extends Renderer {
      private static final Log log = LogFactory.getLog(BufferRenderer.class);
      
      public static final String RENDERER_TYPE = "org.apache.myfaces.Buffer";
  
      private ResponseWriter initialWriter;
      private HtmlBufferResponseWriterWrapper bufferWriter;
      
      public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) {
          RendererUtils.checkParamValidity(facesContext, uiComponent, Buffer.class);
  
          initialWriter = facesContext.getResponseWriter();
          bufferWriter = HtmlBufferResponseWriterWrapper.getInstance( initialWriter );
          facesContext.setResponseWriter( bufferWriter );
      }
      
      public void encodeChildren(FacesContext facesContext, UIComponent component) throws IOException{
          RendererUtils.checkParamValidity(facesContext, component, Buffer.class);
          RendererUtils.renderChildren(facesContext, component);
      }
  
      public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) {
          Buffer buffer = (Buffer)uiComponent;
          buffer.fill(bufferWriter, facesContext);
          
          if( bufferWriter.getDummyFormParams() != null ){
              // Attempt to add the dummy form params (will not work with Sun RI) using reflexion.
              try {
                  Method add = initialWriter.getClass().getDeclaredMethod("addDummyFormParameter", new Class[] {String.class});
                  for(Iterator i = bufferWriter.getDummyFormParams().iterator() ; i.hasNext() ;){
                      add.invoke(initialWriter, new Object[] {i.next()});
                  }
              } catch (Exception e) {
                  log.warn("Dummy form parameters are not supported by this JSF implementation.");
              }
          }
          
          facesContext.setResponseWriter( initialWriter );
      }
      
      private static class HtmlBufferResponseWriterWrapper extends HtmlResponseWriterImpl {
          
          private ResponseWriter initialWriter;
          private ByteArrayOutputStream stream;
          private PrintWriter writer;
          
          static public HtmlBufferResponseWriterWrapper getInstance(ResponseWriter initialWriter){
              ByteArrayOutputStream instanceStream = new ByteArrayOutputStream();
              PrintWriter instanceWriter = new PrintWriter(instanceStream, true);
              
              return new HtmlBufferResponseWriterWrapper(initialWriter, instanceStream, instanceWriter);
          }
          
          private HtmlBufferResponseWriterWrapper(ResponseWriter initialWriter, ByteArrayOutputStream stream, PrintWriter writer){
              super(writer, initialWriter.getContentType(), initialWriter.getCharacterEncoding());
              this.initialWriter = initialWriter;
              this.stream = stream;
              this.writer = writer;
          }
          
          public String toString(){
              try{
                  stream.flush();
                  writer.close();
                  
                  return stream.toString( getCharacterEncoding() );
              }catch(UnsupportedEncodingException e){
                  // an attempt to set an invalid character encoding would have caused this exception before
                  throw new RuntimeException("ResponseWriter accepted invalid character encoding " + getCharacterEncoding());
              } catch (IOException e) {
                  throw new RuntimeException( e );
              }
          }
      }
  }
  
  
  1.1                  incubator-myfaces/src/components/org/apache/myfaces/custom/buffer/BufferTag.java
  
  Index: BufferTag.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.buffer;
  
  import javax.faces.component.UIComponent;
  
  import org.apache.myfaces.taglib.html.HtmlComponentTagBase;
  /**
   * @author Sylvain Vieujot (latest modification by $Author: svieujot $) 
   * @version $Revision: 1.1 $ $Date: 2005/01/04 15:41:06 $ 
   * $Log: BufferTag.java,v $
   * Revision 1.1  2005/01/04 15:41:06  svieujot
   * new x:buffer component.
   *
   */
  public class BufferTag extends HtmlComponentTagBase {
    private String _into = null;
  
    public String getComponentType() {
      return Buffer.COMPONENT_TYPE;
    }
  
    public String getRendererType() {
      return BufferRenderer.RENDERER_TYPE;
    }
  
    protected void setProperties(UIComponent component) {
      super.setProperties(component);
      setStringProperty(component, "into", _into);
    }
  
    public void setInto(String into) {
      this._into = into;
    }
  }
  
  
  1.1                  incubator-myfaces/src/components/org/apache/myfaces/custom/buffer/HtmlResponseWriterImpl.java
  
  Index: HtmlResponseWriterImpl.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.buffer;
  
  import org.apache.myfaces.config.MyfacesConfig;
  import org.apache.myfaces.renderkit.html.HTML;
  import org.apache.myfaces.renderkit.html.util.DummyFormResponseWriter;
  import org.apache.myfaces.renderkit.html.util.DummyFormUtils;
  import org.apache.myfaces.renderkit.html.util.JavascriptUtils;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import javax.faces.component.UIComponent;
  import javax.faces.context.FacesContext;
  import javax.faces.context.ResponseWriter;
  import java.io.IOException;
  import java.io.Writer;
  import java.util.HashSet;
  import java.util.Set;
  
  /**
   * This is the exact same class as the one from org.apache.myfaces.renderkit.html package.
   * 
   * @author Manfred Geiler (latest modification by $Author: svieujot $)
   * @author Anton Koinov
   * @version $Revision: 1.1 $ $Date: 2005/01/04 15:41:06 $
   * $Log: HtmlResponseWriterImpl.java,v $
   * Revision 1.1  2005/01/04 15:41:06  svieujot
   * new x:buffer component.
   *
   */
  public class HtmlResponseWriterImpl
          extends ResponseWriter
          implements DummyFormResponseWriter
  {
      private static final Log log = LogFactory.getLog(HtmlResponseWriterImpl.class);
  
      private static final String DEFAULT_CONTENT_TYPE = "text/html";
      private static final String DEFAULT_CHARACTER_ENCODING = "ISO-8859-1";
  
      private boolean _writeDummyForm = false;
      private Set _dummyFormParams = null;
  
      private Writer _writer;
      private String _contentType;
      private String _characterEncoding;
      private String _startElementName;
      private boolean _startTagOpen;
  
      private static final Set s_emptyHtmlElements = new HashSet();
      static
      {
          s_emptyHtmlElements.add("area");
          s_emptyHtmlElements.add("br");
          s_emptyHtmlElements.add("base");
          s_emptyHtmlElements.add("basefont");
          s_emptyHtmlElements.add("col");
          s_emptyHtmlElements.add("frame");
          s_emptyHtmlElements.add("hr");
          s_emptyHtmlElements.add("img");
          s_emptyHtmlElements.add("input");
          s_emptyHtmlElements.add("isindex");
          s_emptyHtmlElements.add("link");
          s_emptyHtmlElements.add("meta");
          s_emptyHtmlElements.add("param");
      }
  
      public HtmlResponseWriterImpl(Writer writer, String contentType, String characterEncoding)
      {
          _writer = writer;
          _contentType = contentType;
          if (_contentType == null)
          {
              if (log.isInfoEnabled()) log.debug("No content type given, using default content type " + DEFAULT_CONTENT_TYPE);
              _contentType = DEFAULT_CONTENT_TYPE;
          }
          _characterEncoding = characterEncoding;
          if (_characterEncoding == null)
          {
              if (log.isInfoEnabled()) log.debug("No character encoding given, using default character encoding " + DEFAULT_CHARACTER_ENCODING);
              _characterEncoding = DEFAULT_CHARACTER_ENCODING;
          }
      }
  
      public static boolean supportsContentType(String contentType)
      {
          //return SUPPORTED_CONTENT_TYPES.contains(contentType);   //TODO: Match according to Section 14.1 of RFC 2616
          return true;
      }
  
      public String getContentType()
      {
          return _contentType;
      }
  
      public String getCharacterEncoding()
      {
          return _characterEncoding;
      }
  
      public void flush() throws IOException
      {
          // API doc says we should not flush the underlying writer
          //_writer.flush();
          // but rather clear any values buffered by this ResponseWriter:
          closeStartTagIfNecessary();
      }
  
      public void startDocument()
      {
          // do nothing
      }
  
      public void endDocument() throws IOException
      {
          flush();
          if (_writeDummyForm)
          {
              DummyFormUtils.writeDummyForm(this, _dummyFormParams);
          }
  
          FacesContext facesContext = FacesContext.getCurrentInstance();
          MyfacesConfig myfacesConfig = MyfacesConfig.getCurrentInstance(facesContext.getExternalContext());
          if (myfacesConfig.isDetectJavascript())
          {
              if (! JavascriptUtils.isJavascriptDetected(facesContext.getExternalContext()))
              {
                  write("<script type=\"text/javascript\">\n<!--\ndocument.location.replace('" + facesContext.getApplication().getViewHandler().getResourceURL(facesContext, "/_javascriptDetector_")  + "?goto=" + facesContext.getApplication().getViewHandler().getActionURL(facesContext, facesContext.getViewRoot().getViewId()) +"');\n//-->\n</script>");
              }
          }
  
          if (myfacesConfig.isAutoScroll())
          {
              JavascriptUtils.renderAutoScrollFunction(facesContext, this);
          }
  
          _writer.flush();
      }
  
      public void startElement(String name, UIComponent uiComponent) throws IOException
      {
          if (name == null)
          {
              throw new NullPointerException("elementName name must not be null");
          }
  
          closeStartTagIfNecessary();
          _writer.write('<');
          _writer.write(name);
          _startElementName = name;
          _startTagOpen = true;
      }
  
      private void closeStartTagIfNecessary() throws IOException
      {
          if (_startTagOpen)
          {
              if (s_emptyHtmlElements.contains(_startElementName.toLowerCase()))
              {
                  _writer.write("/>");
                  // make null, this will cause NullPointer in some invalid element nestings
                  // (better than doing nothing)
                  _startElementName = null;
              }
              else
              {
                  _writer.write('>');
              }
              _startTagOpen = false;
          }
      }
  
      public void endElement(String name) throws IOException
      {
          if (name == null)
          {
              throw new NullPointerException("elementName name must not be null");
          }
  
          if (log.isWarnEnabled())
          {
              if (_startElementName != null &&
                  !name.equals(_startElementName))
              {
                  if (log.isWarnEnabled())
                      log.warn("HTML nesting warning on closing " + name + ": element " + _startElementName + " not explicitly closed");
              }
          }
  
          if(_startTagOpen)
          {
              // we will get here only if no text or attribute was written after the start element was opened
              if (s_emptyHtmlElements.contains(name.toLowerCase()))
              {
                  _writer.write("/>");
              }
              else
              {
                  _writer.write("></");
                  _writer.write(name);
                  _writer.write('>');
              }
              _startTagOpen = false;
          }
          else
          {
              if (s_emptyHtmlElements.contains(name.toLowerCase()))
              {
                  if (log.isWarnEnabled())
                      log.warn("HTML nesting warning on closing " + name + ": This element must not contain nested elements or text in HTML");
              }
              else
              {
                  _writer.write("</");
                  _writer.write(name);
                  _writer.write('>');
              }
          }
  
          _startElementName = null;
      }
  
      public void writeAttribute(String name, Object value, String componentPropertyName) throws IOException
      {
          if (name == null)
          {
              throw new NullPointerException("attributeName name must not be null");
          }
          if (!_startTagOpen)
          {
              throw new IllegalStateException("Must be called before the start element is closed (attribute '" + name + "')");
          }
  
          if (value instanceof Boolean)
          {
              if (((Boolean)value).booleanValue())
              {
                  // name as value for XHTML compatibility
                  _writer.write(' ');
                  _writer.write(name);
                  _writer.write("=\"");
                  _writer.write(name);
                  _writer.write('"');
              }
          }
          else
          {
              String strValue = value.toString(); //TODO: Use converter for value
              _writer.write(' ');
              _writer.write(name);
              _writer.write("=\"");
              _writer.write(HTMLEncoder.encode(strValue, false, false));
              _writer.write('"');
          }
      }
  
      public void writeURIAttribute(String name, Object value, String componentPropertyName) throws IOException
      {
          if (name == null)
          {
              throw new NullPointerException("attributeName name must not be null");
          }
          if (!_startTagOpen)
          {
              throw new IllegalStateException("Must be called before the start element is closed (attribute '" + name + "')");
          }
  
          String strValue = value.toString(); //TODO: Use converter for value?
          _writer.write(' ');
          _writer.write(name);
          _writer.write("=\"");
          if (strValue.toLowerCase().startsWith("javascript:"))
          {
              _writer.write(HTMLEncoder.encode(strValue, false, false));
          }
          else
          {
              /*
              if (_startElementName.equalsIgnoreCase(HTML.ANCHOR_ELEM) && //TODO: Also support image and button urls ?
                  name.equalsIgnoreCase(HTML.HREF_ATTR) &&
                  !strValue.startsWith("#"))
              {
                  FacesContext facesContext = FacesContext.getCurrentInstance();
                  if (facesContext.getApplication().getStateManager().isSavingStateInClient(facesContext))
                  {
                      //TODO/HACK: saving state in url depends on the work together
                      // of 3 (theoretically) pluggable components:
                      // ViewHandler, ResponseWriter and ViewTag
                      // We should try to make this HtmlResponseWriterImpl able
                      // to handle this alone!
                      if (strValue.indexOf('?') < 0)
                      {
                          strValue = strValue + '?' + JspViewHandlerImpl.URL_STATE_MARKER;
                      }
                      else
                      {
                          strValue = strValue + '&' + JspViewHandlerImpl.URL_STATE_MARKER;
                      }
                  }
              }
              */
              _writer.write(strValue);
          }
          _writer.write('"');
      }
  
      public void writeComment(Object value) throws IOException
      {
          if (value == null)
          {
              throw new NullPointerException("comment name must not be null");
          }
  
          closeStartTagIfNecessary();
          _writer.write("<!--");
          _writer.write(value.toString());    //TODO: Escaping: must not have "-->" inside!
          _writer.write("-->");
      }
  
      public void writeText(Object value, String componentPropertyName) throws IOException
      {
          if (value == null)
          {
              throw new NullPointerException("text name must not be null");
          }
  
          closeStartTagIfNecessary();
          if(value == null)
              return;
  
          String strValue = value.toString(); //TODO: Use converter for value?
  
          if (isScriptOrStyle())
          {
              _writer.write(strValue);
          }
          else
          {
              _writer.write(HTMLEncoder.encode(strValue, false, false));
          }
      }
  
      public void writeText(char cbuf[], int off, int len) throws IOException
      {
          if (cbuf == null)
          {
              throw new NullPointerException("cbuf name must not be null");
          }
          if (cbuf.length < off + len)
          {
              throw new IndexOutOfBoundsException((off + len) + " > " + cbuf.length);
          }
  
          closeStartTagIfNecessary();
  
          if (isScriptOrStyle())
          {
              _writer.write(cbuf, off, len);
          }
          else if (isTextarea())
          {
              // For textareas we must *not* map successive spaces to &nbsp or Newlines to <br/>
              // TODO: Make HTMLEncoder support char arrays directly
              String strValue = new String(cbuf, off, len);
              _writer.write(HTMLEncoder.encode(strValue, false, false));
          }
          else
          {
              // We map successive spaces to &nbsp; and Newlines to <br/>
              // TODO: Make HTMLEncoder support char arrays directly
              String strValue = new String(cbuf, off, len);
              _writer.write(HTMLEncoder.encode(strValue, true, true));
          }
      }
  
      private boolean isScriptOrStyle()
      {
          return _startElementName != null &&
                 (_startElementName.equalsIgnoreCase(HTML.SCRIPT_ELEM) ||
                  _startElementName.equalsIgnoreCase(HTML.STYLE_ELEM));
      }
  
      private boolean isTextarea()
      {
          return _startElementName != null &&
                 (_startElementName.equalsIgnoreCase(HTML.TEXTAREA_ELEM));
      }
  
  
      public ResponseWriter cloneWithWriter(Writer writer)
      {
          HtmlResponseWriterImpl newWriter
                  = new HtmlResponseWriterImpl(writer, getContentType(), getCharacterEncoding());
          newWriter._writeDummyForm = _writeDummyForm;
          newWriter._dummyFormParams = _dummyFormParams;
          return newWriter;
      }
  
  
      // Writer methods
  
      public void close() throws IOException
      {
          if (_startTagOpen)
          {
              // we will get here only if no text was written after the start element was opened
              _writer.write(" />");
          }
          _writer.close();
      }
  
      public void write(char cbuf[], int off, int len) throws IOException
      {
          closeStartTagIfNecessary();
          _writer.write(cbuf, off, len);
      }
  
      public void write(int c) throws IOException
      {
          closeStartTagIfNecessary();
          _writer.write(c);
      }
  
      public void write(char cbuf[]) throws IOException
      {
          closeStartTagIfNecessary();
          _writer.write(cbuf);
      }
  
      public void write(String str) throws IOException
      {
          closeStartTagIfNecessary();
          // empty string commonly used to force the start tag to be closed.
          // in such case, do not call down the writer chain
          if (str.length() > 0)
          {
              _writer.write(str);
          }
      }
  
      public void write(String str, int off, int len) throws IOException
      {
          closeStartTagIfNecessary();
          _writer.write(str, off, len);
      }
  
      // DummyFormResponseWriter support
  
      public void setWriteDummyForm(boolean writeDummyForm)
      {
          _writeDummyForm = writeDummyForm;
      }
  
      public String getDummyFormName()
      {
          return DummyFormUtils.DUMMY_FORM_NAME;
      }
  
      public void addDummyFormParameter(String paramName)
      {
          if (_dummyFormParams == null)
          {
              _dummyFormParams = new HashSet();
          }
          _dummyFormParams.add(paramName);
      }
      
      public Set getDummyFormParams()
      {
          return _dummyFormParams;
      }
  }
  
  
  
  1.148     +12 -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.147
  retrieving revision 1.148
  diff -u -r1.147 -r1.148
  --- myfaces_ext.tld	4 Jan 2005 00:28:06 -0000	1.147
  +++ myfaces_ext.tld	4 Jan 2005 15:41:06 -0000	1.148
  @@ -1721,6 +1721,18 @@
               <rtexprvalue>false</rtexprvalue>
           </attribute>
       </tag>
  +    
  +    <!-- bufferBean -->
  +    <tag>
  +        <name>buffer</name>
  +        <tag-class>org.apache.myfaces.custom.buffer.BufferTag</tag-class>
  +        <body-content>JSP</body-content>
  +        <attribute>
  +            <name>into</name>
  +            <required>true</required>
  +            <rtexprvalue>false</rtexprvalue>
  +        </attribute>
  +    </tag>
   
       <!-- saveState -->
       <tag>
  
  
  
  1.40      +5 -0      incubator-myfaces/webapps/examples/web/WEB-INF/examples-config.xml
  
  Index: examples-config.xml
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/webapps/examples/web/WEB-INF/examples-config.xml,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- examples-config.xml	18 Dec 2004 16:13:37 -0000	1.39
  +++ examples-config.xml	4 Jan 2005 15:41:06 -0000	1.40
  @@ -231,6 +231,11 @@
               <from-outcome>go_aliasBean</from-outcome>
               <to-view-id>/aliasBean.jsp</to-view-id>
           </navigation-case>
  +        
  +        <navigation-case>
  +            <from-outcome>go_buffer</from-outcome>
  +            <to-view-id>/buffer.jsp</to-view-id>
  +        </navigation-case>
   
           <navigation-case>
               <from-outcome>go_dataTable</from-outcome>
  
  
  
  1.1                  incubator-myfaces/webapps/examples/web/buffer.jsp
  
  Index: buffer.jsp
  ===================================================================
  <%@ page session="false" contentType="text/html;charset=utf-8"%>
  <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
  <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
  <%@ taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
  <html>
  
  <%@include file="inc/head.inc" %>
  
  <!--
  /*
   * 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.
   */
  //-->
  
  <body>
  
  <f:view>
  
      <f:loadBundle basename="org.apache.myfaces.examples.resource.example_messages" var="example_messages"/>
  
      <x:panelLayout id="page" layout="#{globalOptions.pageLayout}"
              styleClass="pageLayout"
              headerClass="pageHeader"
              navigationClass="pageNavigation"
              bodyClass="pageBody"
              footerClass="pageFooter" >
  
          <f:facet name="header">
              <f:subview id="header">
                  <jsp:include page="inc/page_header.jsp" />
              </f:subview>
          </f:facet>
  
          <f:facet name="navigation">
              <f:subview id="menu" >
                  <jsp:include page="inc/navigation.jsp" />
              </f:subview>
          </f:facet>
  
          <f:facet name="body">
              <h:panelGroup id="body">
  				<f:verbatim>
  					<p>
  						This component allows you to render a part of the page to a buffer, and then use the buffer later.
  					</p>
  					<p>
  						One use of this is the dataScroller. If you display a table with x:dataTable,
  						you can't have dataScroller BEFORE the table, as it can't find the not yet rendered table.<br/>
  						So, the solution is that you first render the table to a buffer, then you render the dataScroller,
  						and then you render the buffer's content.<br/>
  						That way, the dataScroller will appear before the table even though it was rendered after it.
  					</p>
  					<p>
  						<b>
  							Note : the generated links within the buffer are only supported with the MyFaces implementation
  							because of the lack of standard dummy form parameters support.
  						</b>
  					</p>
  				</f:verbatim>
  
  				<x:buffer into="#{buffer1}">
  					<x:div><h:outputText value="Buffer One"/></x:div>
  				</x:buffer>
  				
  				<x:buffer into="#{buffer2}">
  					<x:div><h:outputText value="Buffer Two"/></x:div>
  				</x:buffer>
  				
  				<h:outputText value="#{buffer2}" escape="false"/>
  				<h:outputText value="#{buffer1}" escape="false"/>
  				<h:outputText value="#{buffer2}" escape="false"/>
  
  				<f:verbatim><h2>dataTable Example</h2></f:verbatim>
  				
  				<x:buffer into="#{table}">
  		            <x:dataTable id="data"
  		                    styleClass="scrollerTable"
  		                    headerClass="standardTable_Header"
  		                    footerClass="standardTable_Header"
  		                    rowClasses="standardTable_Row1,standardTable_Row2"
  		                    columnClasses="standardTable_Column,standardTable_ColumnCentered,standardTable_Column"
  		                    var="car"
  		                    value="#{scrollerList.list}"
  		                    preserveDataModel="true"
  		                    rows="10"
  		               >
  		               <h:column>
  		                   <f:facet name="header">
  		                   </f:facet>
  		                   <h:outputText value="#{car.id}" />
  		               </h:column>
  		
  		               <h:column>
  		                   <f:facet name="header">
  		                      <h:outputText value="#{example_messages['label_cars']}" />
  		                   </f:facet>
  		                   <h:outputText value="#{car.type}" />
  		               </h:column>
  		
  		               <h:column>
  		                   <f:facet name="header">
  		                      <h:outputText value="#{example_messages['label_color']}" />
  		                   </f:facet>
  		                   <h:outputText value="#{car.color}" />
  		               </h:column>
  		
  		            </x:dataTable>
  		        </x:buffer>
  
  				<x:buffer into="#{tableScroller}">
  	                <h:panelGrid columns="1" styleClass="scrollerTable2" columnClasses="standardTable_ColumnCentered" >
  	                    <x:dataScroller id="scroll_1"
  	                            for="data"
  	                            fastStep="10"
  	                            pageCountVar="pageCount"
  	                            pageIndexVar="pageIndex"
  	                            styleClass="scroller"
  	                            paginator="true"
  	                            paginatorMaxPages="9"
  	                            paginatorTableClass="paginator"
  	                            paginatorActiveColumnStyle="font-weight:bold;"
  	                            >
  	                        <f:facet name="first" >
  	                            <h:graphicImage url="images/arrow-first.gif" border="1" />
  	                        </f:facet>
  	                        <f:facet name="last">
  	                            <h:graphicImage url="images/arrow-last.gif" border="1" />
  	                        </f:facet>
  	                        <f:facet name="previous">
  	                            <h:graphicImage url="images/arrow-previous.gif" border="1" />
  	                        </f:facet>
  	                        <f:facet name="next">
  	                            <h:graphicImage url="images/arrow-next.gif" border="1" />
  	                        </f:facet>
  	                        <f:facet name="fastforward">
  	                            <h:graphicImage url="images/arrow-ff.gif" border="1" />
  	                        </f:facet>
  	                        <f:facet name="fastrewind">
  	                            <h:graphicImage url="images/arrow-fr.gif" border="1" />
  	                        </f:facet>
  	                    </x:dataScroller>
  	                    <x:dataScroller id="scroll_2"
  	                            for="data"
  	                            rowsCountVar="rowsCount"
  	                            displayedRowsCountVar="displayedRowsCountVar"
  	                            firstRowIndexVar="firstRowIndex"
  	                            lastRowIndexVar="lastRowIndex"
  	                            pageCountVar="pageCount"
  	                            pageIndexVar="pageIndex"
  	                            >
  	                        <h:outputFormat value="#{example_messages['dataScroller_pages']}" styleClass="standard" >
  	                            <f:param value="#{rowsCount}" />
  	                            <f:param value="#{displayedRowsCountVar}" />
  	                            <f:param value="#{firstRowIndex}" />
  	                            <f:param value="#{lastRowIndex}" />
  	                            <f:param value="#{pageIndex}" />
  	                            <f:param value="#{pageCount}" />
  	                        </h:outputFormat>
  	                    </x:dataScroller>
  	                </h:panelGrid>
  				</x:buffer>
                  
     				<h:outputText value="#{tableScroller}" escape="false"/>
  				<h:outputText value="#{table}" escape="false"/>
  				<h:outputText value="#{tableScroller}" escape="false"/>
                  
              </h:panelGroup>
          </f:facet>
  
          <%@include file="inc/page_footer.jsp" %>
  
      </x:panelLayout>
  
  </f:view>
  
  </body>
  
  </html>
  
  

Mime
View raw message