You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2020/10/15 10:02:12 UTC

[myfaces-tobago] 03/06: might be deprecated

This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit bf17a0d7fa2834d69208140c16352f773bad6f0d
Author: Udo Schnurpfeil <ud...@irian.eu>
AuthorDate: Wed Oct 7 12:43:52 2020 +0200

    <tc:attribute> might be deprecated
---
 .../tobago/el/ConstantMethodExpression.java        | 103 ---------------------
 .../myfaces/tobago/facelets/AttributeHandler.java  |  81 +++++++++++++++-
 .../taglib/component/AttributeTagDeclaration.java  |   7 +-
 .../tobago-example-demo/src/main/webapp/main.xhtml |   7 +-
 4 files changed, 89 insertions(+), 109 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/el/ConstantMethodExpression.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/el/ConstantMethodExpression.java
deleted file mode 100644
index 6a063ec..0000000
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/el/ConstantMethodExpression.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.myfaces.tobago.el;
-
-import javax.el.ELContext;
-import javax.el.ELException;
-import javax.el.MethodExpression;
-import javax.el.MethodInfo;
-import javax.faces.component.StateHolder;
-import javax.faces.context.FacesContext;
-import java.util.Objects;
-
-public class ConstantMethodExpression extends MethodExpression implements StateHolder {
-
-  private String outcome;
-
-  private boolean transientFlag;
-
-  public ConstantMethodExpression() {
-  }
-
-  public ConstantMethodExpression(final String outcome) {
-    this.outcome = outcome;
-  }
-
-  @Override
-  public MethodInfo getMethodInfo(final ELContext context)
-      throws NullPointerException, ELException {
-    return null;
-  }
-
-  @Override
-  public Object invoke(final ELContext context, final Object[] params)
-      throws NullPointerException, ELException {
-    return outcome;
-  }
-
-  @Override
-  public boolean equals(final Object o) {
-    if (this == o) {
-      return true;
-    }
-    if (o == null || getClass() != o.getClass()) {
-      return false;
-    }
-
-    final ConstantMethodExpression that = (ConstantMethodExpression) o;
-
-    return Objects.equals(outcome, that.outcome);
-  }
-
-  @Override
-  public int hashCode() {
-    return outcome.hashCode();
-  }
-
-  @Override
-  public String getExpressionString() {
-    return outcome;
-  }
-
-  @Override
-  public boolean isLiteralText() {
-    return true;
-  }
-
-  @Override
-  public Object saveState(final FacesContext context) {
-    return outcome;
-  }
-
-  @Override
-  public void restoreState(final FacesContext context, final Object state) {
-    this.outcome = (String) state;
-  }
-
-  @Override
-  public void setTransient(final boolean transientFlagParameter) {
-    this.transientFlag = transientFlag;
-  }
-
-  @Override
-  public boolean isTransient() {
-    return transientFlag;
-  }
-}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java
index 3b4319f..7083046 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/AttributeHandler.java
@@ -22,22 +22,25 @@ package org.apache.myfaces.tobago.facelets;
 import org.apache.myfaces.tobago.component.Attributes;
 import org.apache.myfaces.tobago.component.Visual;
 import org.apache.myfaces.tobago.context.Markup;
-import org.apache.myfaces.tobago.el.ConstantMethodExpression;
 import org.apache.myfaces.tobago.internal.util.StringUtils;
 import org.apache.myfaces.tobago.util.ComponentUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.el.ELContext;
 import javax.el.ELException;
 import javax.el.ExpressionFactory;
 import javax.el.MethodExpression;
+import javax.el.MethodInfo;
 import javax.el.ValueExpression;
 import javax.faces.FacesException;
 import javax.faces.component.ActionSource;
 import javax.faces.component.ActionSource2;
 import javax.faces.component.EditableValueHolder;
+import javax.faces.component.StateHolder;
 import javax.faces.component.UIComponent;
 import javax.faces.component.ValueHolder;
+import javax.faces.context.FacesContext;
 import javax.faces.convert.Converter;
 import javax.faces.event.MethodExpressionActionListener;
 import javax.faces.event.MethodExpressionValueChangeListener;
@@ -51,6 +54,7 @@ import javax.faces.view.facelets.TagHandler;
 import java.beans.IntrospectionException;
 import java.beans.PropertyDescriptor;
 import java.lang.invoke.MethodHandles;
+import java.util.Objects;
 
 public final class AttributeHandler extends TagHandler {
 
@@ -351,4 +355,79 @@ public final class AttributeHandler extends TagHandler {
       parent.setValueExpression(nameValue, expression);
     }
   }
+
+  private static class ConstantMethodExpression extends MethodExpression implements StateHolder {
+
+    private String outcome;
+
+    private boolean transientFlag;
+
+    public ConstantMethodExpression() {
+    }
+
+    public ConstantMethodExpression(final String outcome) {
+      this.outcome = outcome;
+    }
+
+    @Override
+    public MethodInfo getMethodInfo(final ELContext context)
+        throws NullPointerException, ELException {
+      return null;
+    }
+
+    @Override
+    public Object invoke(final ELContext context, final Object[] params)
+        throws NullPointerException, ELException {
+      return outcome;
+    }
+
+    @Override
+    public boolean equals(final Object o) {
+      if (this == o) {
+        return true;
+      }
+      if (o == null || getClass() != o.getClass()) {
+        return false;
+      }
+
+      final ConstantMethodExpression that = (ConstantMethodExpression) o;
+
+      return Objects.equals(outcome, that.outcome);
+    }
+
+    @Override
+    public int hashCode() {
+      return outcome.hashCode();
+    }
+
+    @Override
+    public String getExpressionString() {
+      return outcome;
+    }
+
+    @Override
+    public boolean isLiteralText() {
+      return true;
+    }
+
+    @Override
+    public Object saveState(final FacesContext context) {
+      return outcome;
+    }
+
+    @Override
+    public void restoreState(final FacesContext context, final Object state) {
+      this.outcome = (String) state;
+    }
+
+    @Override
+    public void setTransient(final boolean transientFlagParameter) {
+      this.transientFlag = transientFlag;
+    }
+
+    @Override
+    public boolean isTransient() {
+      return transientFlag;
+    }
+  }
 }
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/AttributeTagDeclaration.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/AttributeTagDeclaration.java
index 25f2034..21a39de 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/AttributeTagDeclaration.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/AttributeTagDeclaration.java
@@ -26,8 +26,14 @@ import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
 import javax.el.ValueExpression;
 
 /**
+ * <p>
  * Add an attribute on the UIComponent
  * associated with the closest parent UIComponent custom action.
+ * </p>
+ * <p>
+ * You might not need this attribute.
+ * Is there a real use case any longer for this tag?
+ * </p>
  */
 @Tag(name = "attribute")
 @SimpleTag(
@@ -46,7 +52,6 @@ public interface AttributeTagDeclaration {
   @TagAttribute(required = true, name = "value", type = "java.lang.String")
   void setValue(final ValueExpression value);
   /**
-   * Warning: The mode is only available when using Facelets.
    * Allowed values are "action", "actionListener", "actionFromValue", "isNotSet", "isSet", "valueIfSet".
    * <br>
    * "action" (method binding) evaluate the expression to find the method binding which is referenced with the template.
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/main.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/main.xhtml
index eb6655f..fc58ee4 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/main.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/main.xhtml
@@ -25,8 +25,8 @@
         xmlns:ui="http://java.sun.com/jsf/facelets"
         xmlns="http://www.w3.org/1999/xhtml">
   <f:view locale="#{localeController.locale}">
-    <tc:page label="Tobago Demo - #{navigationState.currentNode.label}" id="page">
-      <tc:attribute name="label" value="#{title}" mode="valueIfSet"/>
+
+    <tc:page label="#{title != null ? title : 'Tobago Demo - '.concat(navigationState.currentNode.label)}" id="page">
 
       <!--
             <tc:dataAttribute name="tobago-log-level" value="DEBUG"/>
@@ -59,8 +59,7 @@
             <tc:panel>
               <tc:messages id="messages" orderBy="severity" rendered="#{!hideGlobalMessages}"/>
 
-              <tc:section label="#{navigationState.currentNode.label}" id="content">
-                <tc:attribute name="label" value="#{title}" mode="valueIfSet"/>
+              <tc:section label="#{title != null ? title : navigationState.currentNode.label}" id="content">
                 <tc:form id="mainForm">
                   <ui:insert/>
                 </tc:form>