myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmarinsc...@apache.org
Subject cvs commit: incubator-myfaces/src/components/org/apache/myfaces/custom/jsvalueset HtmlJsValueSetTag.java
Date Tue, 04 Jan 2005 16:09:57 GMT
mmarinschek    2005/01/04 08:09:57

  Modified:    conf     faces-config.xml
               src/components/org/apache/myfaces/custom/jslistener
                        JsValueChangeListener.java
                        JsValueChangeListenerTag.java
               src/components/org/apache/myfaces/custom/jsvalueset
                        HtmlJsValueSetTag.java
  Added:       src/components/org/apache/myfaces/custom/jslistener
                        JsValueChangeListener.xml
                        JsValueChangeListenerRenderer.java
  Log:
  ChangeListener now uses renderer
  
  Revision  Changes    Path
  1.104     +11 -0     incubator-myfaces/conf/faces-config.xml
  
  Index: faces-config.xml
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/conf/faces-config.xml,v
  retrieving revision 1.103
  retrieving revision 1.104
  diff -u -r1.103 -r1.104
  --- faces-config.xml	4 Jan 2005 15:41:06 -0000	1.103
  +++ faces-config.xml	4 Jan 2005 16:09:57 -0000	1.104
  @@ -156,6 +156,11 @@
     </component>
   
     <component>
  +    <component-type>org.apache.myfaces.JsValueChangeListener</component-type>
  +    <component-class>org.apache.myfaces.custom.jslistener.JsValueChangeListener</component-class>
  +  </component>
  +
  +  <component>
       <component-type>org.apache.myfaces.HtmlNewspaperTable</component-type>
       <component-class>org.apache.myfaces.custom.newspaper.HtmlNewspaperTable</component-class>
     </component>
  @@ -472,6 +477,12 @@
             <component-family>javax.faces.Output</component-family>
             <renderer-type>org.apache.myfaces.JsValueSet</renderer-type>
             <renderer-class>org.apache.myfaces.custom.jsvalueset.HtmlJsValueSetRenderer</renderer-class>
  +      </renderer>
  +
  +      <renderer>
  +          <component-family>javax.faces.Output</component-family>
  +          <renderer-type>org.apache.myfaces.JsValueChangeListener</renderer-type>
  +          <renderer-class>org.apache.myfaces.custom.jslistener.JsValueChangeListenerRenderer</renderer-class>
         </renderer>
   
         <renderer>
  
  
  
  1.3       +81 -1     incubator-myfaces/src/components/org/apache/myfaces/custom/jslistener/JsValueChangeListener.java
  
  Index: JsValueChangeListener.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/jslistener/JsValueChangeListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JsValueChangeListener.java	24 Dec 2004 13:21:50 -0000	1.2
  +++ JsValueChangeListener.java	4 Jan 2005 16:09:57 -0000	1.3
  @@ -3,18 +3,98 @@
    */
   package org.apache.myfaces.custom.jslistener;
   
  +import javax.faces.component.UIOutput;
  +import javax.faces.context.FacesContext;
  +import javax.faces.el.ValueBinding;
   
   /**
    * @author Martin Marinschek (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  - * Revision 1.2  2004/12/24 13:21:50  matzew
  - * organized imports
  + * Revision 1.3  2005/01/04 16:09:57  mmarinschek
  + * ChangeListener now uses renderer
    *
    * Revision 1.1  2004/12/17 13:19:10  mmarinschek
    * new component jsValueChangeListener
    *
    */
  -public class JsValueChangeListener
  +public class JsValueChangeListener extends UIOutput
   {
  +    //------------------ GENERATED CODE BEGIN (do not modify!) --------------------
  +
  +    public static final String COMPONENT_TYPE = "org.apache.myfaces.JsValueChangeListener";
  +    public static final String COMPONENT_FAMILY = "javax.faces.Output";
  +    private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.JsValueChangeListener";
  +
  +    private String _for = null;
  +    private String _expressionValue = null;
  +    private String _property = null;
  +
  +    public JsValueChangeListener()
  +    {
  +        setRendererType(DEFAULT_RENDERER_TYPE);
  +    }
  +
  +    public String getFamily()
  +    {
  +        return COMPONENT_FAMILY;
  +    }
  +
  +    public void setFor(String forValue)
  +    {
  +        _for = forValue;
  +    }
  +
  +    public String getFor()
  +    {
  +        if (_for != null) return _for;
  +        ValueBinding vb = getValueBinding("for");
  +        return vb != null ? (String)vb.getValue(getFacesContext()) : null;
  +    }
  +
  +    public void setExpressionValue(String expressionValue)
  +    {
  +        _expressionValue = expressionValue;
  +    }
  +
  +    public String getExpressionValue()
  +    {
  +        if (_expressionValue != null) return _expressionValue;
  +        ValueBinding vb = getValueBinding("expressionValue");
  +        return vb != null ? (String)vb.getValue(getFacesContext()) : null;
  +    }
  +
  +    public void setProperty(String property)
  +    {
  +        _property = property;
  +    }
  +
  +    public String getProperty()
  +    {
  +        if (_property != null) return _property;
  +        ValueBinding vb = getValueBinding("property");
  +        return vb != null ? (String)vb.getValue(getFacesContext()) : null;
  +    }
  +
  +
  +
  +    public Object saveState(FacesContext context)
  +    {
  +        Object values[] = new Object[4];
  +        values[0] = super.saveState(context);
  +        values[1] = _for;
  +        values[2] = _expressionValue;
  +        values[3] = _property;
  +        return ((Object) (values));
  +    }
  +
  +    public void restoreState(FacesContext context, Object state)
  +    {
  +        Object values[] = (Object[])state;
  +        super.restoreState(context, values[0]);
  +        _for = (String)values[1];
  +        _expressionValue = (String)values[2];
  +        _property = (String)values[3];
  +    }
  +    //------------------ GENERATED CODE END ---------------------------------------
   }
  
  
  
  1.4       +49 -3     incubator-myfaces/src/components/org/apache/myfaces/custom/jslistener/JsValueChangeListenerTag.java
  
  Index: JsValueChangeListenerTag.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/jslistener/JsValueChangeListenerTag.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JsValueChangeListenerTag.java	20 Dec 2004 06:33:51 -0000	1.3
  +++ JsValueChangeListenerTag.java	4 Jan 2005 16:09:57 -0000	1.4
  @@ -6,6 +6,8 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.myfaces.component.html.util.AddResource;
  +import org.apache.myfaces.custom.jsvalueset.HtmlJsValueSet;
  +import org.apache.myfaces.taglib.UIComponentTagBase;
   
   import javax.faces.application.Application;
   import javax.faces.component.UIComponent;
  @@ -21,6 +23,9 @@
    * @author Martin Marinschek (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.4  2005/01/04 16:09:57  mmarinschek
  + * ChangeListener now uses renderer
  + *
    * Revision 1.3  2004/12/20 06:33:51  mmarinschek
    * bugs killed
    *
  @@ -33,8 +38,49 @@
    *
    */
   public class JsValueChangeListenerTag
  -        extends TagSupport
  +        extends UIComponentTagBase
   {
  +
  +    public String getComponentType()
  +    {
  +        return JsValueChangeListener.COMPONENT_TYPE;
  +    }
  +
  +    public String getRendererType()
  +    {
  +        return "org.apache.myfaces.JsValueChangeListener";
  +    }
  +
  +    private String _for;
  +    private String _property;
  +    private String _expressionValue;
  +
  +    protected void setProperties(UIComponent component)
  +    {
  +        super.setProperties(component);
  +
  +        setStringProperty(component, "for", _for);
  +        setStringProperty(component, "property", _property);
  +        setStringProperty(component, "expressionValue", _expressionValue);
  +    }
  +
  +    public void setExpressionValue(String expressionValue)
  +    {
  +        _expressionValue = expressionValue;
  +    }
  +
  +    public void setFor(String aFor)
  +    {
  +        _for = aFor;
  +    }
  +
  +    public void setProperty(String property)
  +    {
  +        _property = property;
  +    }
  +
  +    /*
  +
       //private static final Log log = LogFactory.getLog(UpdateActionListenerTag.class);
   
       private String _for;
  @@ -197,7 +243,7 @@
       protected FacesContext getFacesContext()
       {
           return FacesContext.getCurrentInstance();
  -    }
  +    }           */
   }
   
   
  
  
  
  1.1                  incubator-myfaces/src/components/org/apache/myfaces/custom/jslistener/JsValueChangeListener.xml
  
  Index: JsValueChangeListener.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 generateUserRoleMethods="false" >
      <component-class>org.apache.myfaces.custom.jslistener.JsValueChangeListener</component-class>
      <base-class>javax.faces.component.UIOutput</base-class>
      <component-type>org.apache.myfaces.JsValueChangeListener</component-type>
      <component-family>javax.faces.Output</component-family>
      <renderer-type>org.apache.myfaces.JsValueChangeListener</renderer-type>
      <field>
          <name>for</name>
          <type>java.lang.String</type>
      </field>
      <field>
          <name>expressionValue</name>
          <type>java.lang.String</type>
      </field>
      <field>
          <name>property</name>
          <type>java.lang.String</type>
      </field>
  </component>
  
  
  
  1.1                  incubator-myfaces/src/components/org/apache/myfaces/custom/jslistener/JsValueChangeListenerRenderer.java
  
  Index: JsValueChangeListenerRenderer.java
  ===================================================================
  /*
   * Copyright (c) 2005 Your Corporation. All Rights Reserved.
   */
  package org.apache.myfaces.custom.jslistener;
  
  import org.apache.myfaces.renderkit.RendererUtils;
  import org.apache.myfaces.renderkit.html.HTML;
  import org.apache.myfaces.renderkit.html.HtmlRenderer;
  import org.apache.myfaces.custom.jsvalueset.HtmlJsValueSet;
  import org.apache.myfaces.component.html.util.AddResource;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import javax.faces.application.Application;
  import javax.faces.component.UIComponent;
  import javax.faces.component.UINamingContainer;
  import javax.faces.context.FacesContext;
  import javax.faces.context.ResponseWriter;
  import java.io.IOException;
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.Map;
  
  /**
   * $Log: JsValueChangeListenerRenderer.java,v $
   * Revision 1.1  2005/01/04 16:09:57  mmarinschek
   * ChangeListener now uses renderer
   *
   * Revision 1.1  2004/12/19 00:50:55  mmarinschek
   * JsValueSetTag
   *
   *
   * @author Martin Marinschek (latest modification by $Author: mmarinschek $)
   * @version $Revision: 1.1 $ $Date: 2005/01/04 16:09:57 $
   */
  public class JsValueChangeListenerRenderer
          extends HtmlRenderer
  {
      private static Log log = LogFactory.getLog(JsValueChangeListenerRenderer.class);
  
      public void encodeEnd(FacesContext facesContext, UIComponent component)
              throws IOException
      {
          RendererUtils.checkParamValidity(facesContext, component, JsValueChangeListener.class);
  
          UIComponent parent = component.getParent();
  
          JsValueChangeListener jsValueChangeListener = (JsValueChangeListener) component;
  
  
          String aFor = jsValueChangeListener.getFor();
          String expressionValue = jsValueChangeListener.getExpressionValue();
          String property = jsValueChangeListener.getProperty();
  
          AddResource.addJavaScriptToHeader(
                  JsValueChangeListenerTag.class, "JSListener.js", false, getFacesContext());
  
          if(aFor!=null)
          {
              UIComponent forComponent = component.findComponent(aFor);
  
              String forComponentId = null;
  
              if (forComponent == null)
              {
                  if (log.isInfoEnabled())
                  {
                      log.info("Unable to find component '" + aFor + "' (calling findComponent
on component '" + component.getClientId(getFacesContext()) + "') - will try to render component
id based on the parent-id (on same level)");
                  }
                  if (aFor.length() > 0 && aFor.charAt(0) == UINamingContainer.SEPARATOR_CHAR)
                  {
                      //absolute id path
                      forComponentId = aFor.substring(1);
                  }
                  else
                  {
                      //relative id path, we assume a component on the same level as the label
component
                      String labelClientId = component.getClientId(getFacesContext());
                      int colon = labelClientId.lastIndexOf(UINamingContainer.SEPARATOR_CHAR);
                      if (colon == -1)
                      {
                          forComponentId = aFor;
                      }
                      else
                      {
                          forComponentId = labelClientId.substring(0, colon + 1) + aFor;
                      }
                  }
              }
              else
              {
                  forComponentId = forComponent.getClientId(getFacesContext());
              }
  
              expressionValue = expressionValue.replaceAll("\\'","\\\\'");
              expressionValue = expressionValue.replaceAll("\"","\\\"");
  
  
              String methodCall = "orgApacheMyfacesJsListenerSetExpressionProperty('"+
                      parent.getClientId(getFacesContext())+"','"+
                      forComponentId+"',"+
                      (property==null?"null":"'"+property+"'")+
                      ",'"+expressionValue+"');";
  
  
              callMethod(parent, "onchange",methodCall);
  
          }
      }
  
      private void callMethod(UIComponent uiComponent, String propName, String value)
      {
          Object oldValue = uiComponent.getAttributes().get(propName);
  
          if(oldValue != null)
          {
              String oldValueStr = oldValue.toString().trim();
  
              //check if method call has already been added...
              if(oldValueStr.indexOf(value)!=-1)
                  return;
  
              if(oldValueStr.length()>0 && !oldValueStr.endsWith(";"))
                  oldValueStr +=";";
  
              value = oldValueStr + value;
  
          }
  
          uiComponent.getAttributes().put(propName, value);
      }
  
  
      protected Application getApplication()
      {
          return getFacesContext().getApplication();
      }
  
      protected FacesContext getFacesContext()
      {
          return FacesContext.getCurrentInstance();
      }
  
  }
  
  
  
  1.2       +6 -3      incubator-myfaces/src/components/org/apache/myfaces/custom/jsvalueset/HtmlJsValueSetTag.java
  
  Index: HtmlJsValueSetTag.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/jsvalueset/HtmlJsValueSetTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HtmlJsValueSetTag.java	19 Dec 2004 00:50:55 -0000	1.1
  +++ HtmlJsValueSetTag.java	4 Jan 2005 16:09:57 -0000	1.2
  @@ -11,6 +11,9 @@
    * @author Martin Marinschek (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.2  2005/01/04 16:09:57  mmarinschek
  + * ChangeListener now uses renderer
  + *
    * Revision 1.1  2004/12/19 00:50:55  mmarinschek
    * JsValueSetTag
    *
  @@ -42,7 +45,7 @@
   
       // HTML event handler attributes --> already implemented in HtmlComponentTagBase
   
  -    // HtmlCheckbox attributes
  +    // HtmlJsValueSet attributes
       private String _name;
   
       protected void setProperties(UIComponent component)
  
  
  

Mime
View raw message