You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2007/01/09 22:27:58 UTC

svn commit: r494593 - in /myfaces/tobago/trunk: contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/ core/src/main/java/org/apache/myfaces/tobago/event/ core/src/main/java/org/apache/myfaces/tobago/taglib/component/ tobago-tool/maven-apt-...

Author: bommel
Date: Tue Jan  9 13:27:57 2007
New Revision: 494593

URL: http://svn.apache.org/viewvc?view=rev&rev=494593
Log:
(TOBAGO-236) Binding attribute of TabChangeListenerTag doesn't work in a managed bean

Added:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/event/TabChangeListenerValueBindingDelegate.java
Modified:
    myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TabChangeListenerHandler.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabChangeListenerTag.java
    myfaces/tobago/trunk/tobago-tool/maven-apt-plugin/src/main/java/org/apache/myfaces/maven/plugin/AbstractAPTMojo.java

Modified: myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TabChangeListenerHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TabChangeListenerHandler.java?view=diff&rev=494593&r1=494592&r2=494593
==============================================================================
--- myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TabChangeListenerHandler.java (original)
+++ myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TabChangeListenerHandler.java Tue Jan  9 13:27:57 2007
@@ -23,11 +23,13 @@
 import com.sun.facelets.tag.TagAttributeException;
 import com.sun.facelets.tag.TagException;
 import com.sun.facelets.FaceletContext;
+import com.sun.facelets.el.LegacyValueBinding;
 
 import java.io.IOException;
 
 import org.apache.myfaces.tobago.event.TabChangeSource;
 import org.apache.myfaces.tobago.event.TabChangeListener;
+import org.apache.myfaces.tobago.event.TabChangeListenerValueBindingDelegate;
 
 import javax.faces.FacesException;
 import javax.faces.component.UIComponent;
@@ -87,7 +89,12 @@
             valueExpression.setValue(faceletContext, listener);
           }
         }
-        changeSource.addTabChangeListener(listener);
+        if (valueExpression != null) {
+          changeSource.addTabChangeListener(new TabChangeListenerValueBindingDelegate(type.getValue(),
+              new LegacyValueBinding(valueExpression)));
+        } else {
+          changeSource.addTabChangeListener(listener);
+        }
       }
     } else {
       throw new TagException(tag, "Parent is not of type TabChangeSource, type is: " + parent);

Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/event/TabChangeListenerValueBindingDelegate.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/event/TabChangeListenerValueBindingDelegate.java?view=auto&rev=494593
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/event/TabChangeListenerValueBindingDelegate.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/event/TabChangeListenerValueBindingDelegate.java Tue Jan  9 13:27:57 2007
@@ -0,0 +1,105 @@
+package org.apache.myfaces.tobago.event;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/*
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: Jan 9, 2007
+ * Time: 8:08:01 PM
+ */
+public class TabChangeListenerValueBindingDelegate implements TabChangeListener, StateHolder {
+  private static final Log LOG = LogFactory.getLog(TabChangeListenerValueBindingDelegate.class);
+  private String type;
+  private ValueBinding valueBinding;
+
+  public TabChangeListenerValueBindingDelegate() {
+  }
+
+  public TabChangeListenerValueBindingDelegate(String type, ValueBinding valueBinding) {
+    this.type = type;
+    this.valueBinding = valueBinding;
+  }
+
+  public void processTabChange(TabChangeEvent tabChangeEvent) {
+    TabChangeListener handler = getTabChangeListener();
+    if (handler != null) {
+      handler.processTabChange(tabChangeEvent);
+    } else {
+      LOG.error("Ignoring TabChangeEvent. No TabChangeListener found.");
+    }
+  }
+
+  public Object saveState(FacesContext context) {
+    Object[] state = new Object[2];
+    state[0] = UIComponentBase.saveAttachedState(context, valueBinding);
+    state[1] = type;
+    return state;
+  }
+
+  public void restoreState(FacesContext context, Object state) {
+    Object[] values = (Object[]) state;
+    valueBinding = (ValueBinding) UIComponentBase.restoreAttachedState(context, values[0]);
+    type = (String) values[1];
+
+  }
+
+  public boolean isTransient() {
+    return false;
+  }
+
+  public void setTransient(boolean newTransientValue) {
+    // ignore
+  }
+
+  private TabChangeListener getTabChangeListener() {
+    TabChangeListener handler = null;
+    if (valueBinding != null) {
+      Object obj = valueBinding.getValue(FacesContext.getCurrentInstance());
+      if (obj != null && obj instanceof TabChangeListener) {
+        handler = (TabChangeListener) obj;
+      }
+    }
+    if (handler == null && type != null) {
+      handler = createTabChangeListener(type);
+      if (handler != null && valueBinding != null) {
+        valueBinding.setValue(FacesContext.getCurrentInstance(), handler);
+      }
+    }
+    return handler;
+  }
+
+  private TabChangeListener createTabChangeListener(String className) {
+    try {
+      Class clazz = getClass().getClassLoader().loadClass(className);
+      return ((TabChangeListener) clazz.newInstance());
+    } catch (Exception e) {
+      LOG.error("", e);
+    }
+    return null;
+  }
+
+}

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabChangeListenerTag.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabChangeListenerTag.java?view=diff&rev=494593&r1=494592&r2=494593
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabChangeListenerTag.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/TabChangeListenerTag.java Tue Jan  9 13:27:57 2007
@@ -23,6 +23,9 @@
 import org.apache.myfaces.tobago.component.ComponentUtil;
 import org.apache.myfaces.tobago.event.TabChangeListener;
 import org.apache.myfaces.tobago.event.TabChangeSource;
+import org.apache.myfaces.tobago.event.TabChangeListenerValueBindingDelegate;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
@@ -38,7 +41,7 @@
 @Tag(name = "tabChangeListener", bodyContent = BodyContent.EMPTY)
 public class TabChangeListenerTag extends TagSupport {
 
-
+  private static final Log LOG = LogFactory.getLog(TabChangeListenerTag.class);
   /**
    * <p>The fully qualified class name of the {@link TabChangeListener}
    * instance to be created.</p>
@@ -99,9 +102,9 @@
     TabChangeSource changeSource = (TabChangeSource) component;
 
     TabChangeListener handler = null;
-
+    ValueBinding valueBinding = null;
     if (binding != null && UIComponentTag.isValueReference(binding)) {
-      ValueBinding valueBinding = ComponentUtil.createValueBinding(binding);
+      valueBinding = ComponentUtil.createValueBinding(binding);
       if (valueBinding != null) {
         Object obj = valueBinding.getValue(FacesContext.getCurrentInstance());
         if (obj != null && obj instanceof TabChangeListener) {
@@ -111,21 +114,17 @@
     }
 
     if (handler == null && type != null) {
-      String className;
-      // evaluate any VB expression that we were passed
-      if (UIComponentTag.isValueReference(type)) {
-        ValueBinding typeValueBinding = ComponentUtil.createValueBinding(type);
-        className = (String) typeValueBinding.getValue(FacesContext.getCurrentInstance());
-      } else {
-        className = type;
-      }
-      handler = createStateChangeListener(className);
-      if (handler != null && binding != null) {
-        ComponentUtil.setValueForValueBinding(binding, handler);
+      handler = createTabChangeListener(type);
+      if (handler != null && valueBinding != null) {
+        valueBinding.setValue(FacesContext.getCurrentInstance(), handler);
       }
     }
     if (handler != null) {
-      changeSource.addTabChangeListener(handler);
+      if (valueBinding != null) {
+        changeSource.addTabChangeListener(new TabChangeListenerValueBindingDelegate(type, valueBinding));
+      } else {
+        changeSource.addTabChangeListener(handler);
+      }
     }
     // TODO else LOG.warn?
     return (SKIP_BODY);
@@ -146,7 +145,7 @@
    *
    * @throws javax.servlet.jsp.JspException if a new instance cannot be created
    */
-  protected TabChangeListener createStateChangeListener(String className) throws JspException {
+  protected TabChangeListener createTabChangeListener(String className) throws JspException {
     try {
       Class clazz = getClass().getClassLoader().loadClass(className);
       return ((TabChangeListener) clazz.newInstance());

Modified: myfaces/tobago/trunk/tobago-tool/maven-apt-plugin/src/main/java/org/apache/myfaces/maven/plugin/AbstractAPTMojo.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-tool/maven-apt-plugin/src/main/java/org/apache/myfaces/maven/plugin/AbstractAPTMojo.java?view=diff&rev=494593&r1=494592&r2=494593
==============================================================================
--- myfaces/tobago/trunk/tobago-tool/maven-apt-plugin/src/main/java/org/apache/myfaces/maven/plugin/AbstractAPTMojo.java (original)
+++ myfaces/tobago/trunk/tobago-tool/maven-apt-plugin/src/main/java/org/apache/myfaces/maven/plugin/AbstractAPTMojo.java Tue Jan  9 13:27:57 2007
@@ -83,6 +83,13 @@
      */
     private static boolean isClasspathModified;
 
+   /**
+    * Working directory when APT compiler is forked
+    * @parameter default-value="${basedir}"
+    * @since 1.0.10
+    */
+    private File workingDir;
+
     /**
      *  A List of targetFiles for SingleSourceTargetMapping
      *
@@ -359,7 +366,7 @@
                      {
                          FileUtils.fileWrite( file.getAbsolutePath(),
                                  StringUtils.join( sourceFiles.iterator(), "\n" ) );
-                         cmd.createArgument().setValue( "@files" );
+                         cmd.createArgument().setValue( '@' + file.getPath() );
                      }
                      catch ( IOException e )
                      {
@@ -379,9 +386,9 @@
             {
                 if ( getLog().isDebugEnabled() )
                 {
-                    getLog().debug( "Working dir: " + tempRoot.getAbsolutePath() );
+                    getLog().debug( "Working dir: " + workingDir.getAbsolutePath() );
                 }
-                cmd.setWorkingDirectory( tempRoot.getAbsolutePath() );
+                cmd.setWorkingDirectory( workingDir.getAbsolutePath() );
                 cmd.setExecutable( getAptPath() );
 
                 if ( getLog().isDebugEnabled() )