struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [1/2] struts git commit: WW-4861 Adds fallback to lookup container using ActionContext
Date Tue, 19 Sep 2017 07:26:30 GMT
Repository: struts
Updated Branches:
  refs/heads/master bca42a209 -> 50a0a72e9


WW-4861 Adds fallback to lookup container using ActionContext


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/50a0a72e
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/50a0a72e
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/50a0a72e

Branch: refs/heads/master
Commit: 50a0a72e9d4bcf96bdcb6e1d9adaefa8c11f19e8
Parents: d41bd50
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Tue Sep 19 09:24:08 2017 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Tue Sep 19 09:26:20 2017 +0200

----------------------------------------------------------------------
 .../com/opensymphony/xwork2/ActionSupport.java  | 26 ++++++++++++++++++++
 1 file changed, 26 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/50a0a72e/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java b/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java
index cb1ac47..7d79471 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ActionSupport.java
@@ -19,6 +19,9 @@ import com.opensymphony.xwork2.inject.Container;
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.interceptor.ValidationAware;
 import com.opensymphony.xwork2.util.ValueStack;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.struts2.StrutsConstants;
 
 import java.io.Serializable;
 import java.util.*;
@@ -29,6 +32,8 @@ import java.util.*;
  */
 public class ActionSupport implements Action, Validateable, ValidationAware, TextProvider,
LocaleProvider, Serializable {
 
+    private static final Logger LOG = LogManager.getLogger(ActionSupport.class);
+
     private final ValidationAwareSupport validationAware = new ValidationAwareSupport();
 
     private transient TextProvider textProvider;
@@ -274,6 +279,7 @@ public class ActionSupport implements Action, Validateable, ValidationAware,
Tex
      * @return reference to field with TextProvider
      */
     protected TextProvider getTextProvider() {
+        checkContainer();
         if (textProvider == null) {
             TextProviderFactory tpf = container.getInstance(TextProviderFactory.class);
             textProvider = tpf.createInstance(getClass());
@@ -282,6 +288,7 @@ public class ActionSupport implements Action, Validateable, ValidationAware,
Tex
     }
 
     protected LocaleProvider getLocaleProvider() {
+        checkContainer();
         if (localeProvider == null) {
             LocaleProviderFactory localeProviderFactory = container.getInstance(LocaleProviderFactory.class);
             localeProvider = localeProviderFactory.createLocaleProvider();
@@ -289,6 +296,25 @@ public class ActionSupport implements Action, Validateable, ValidationAware,
Tex
         return localeProvider;
     }
 
+    /**
+     * TODO: This a temporary solution, maybe we should consider stop injecting container
into beans
+     */
+    private void checkContainer() {
+        if (container == null) {
+            container = ActionContext.getContext().getContainer();
+            if (container != null) {
+                boolean devMode = Boolean.parseBoolean(container.getInstance(String.class,
StrutsConstants.STRUTS_DEVMODE));
+                if (devMode) {
+                    LOG.warn("Container is null, action was created manually? Fallback to
ActionContext");
+                } else {
+                    LOG.debug("Container is null, action was created manually? Fallback to
ActionContext");
+                }
+            } else {
+                LOG.warn("Container is null, action was created out of ActionContext scope?!?");
+            }
+        }
+    }
+
     @Inject
     public void setContainer(Container container) {
         this.container = container;


Mime
View raw message