[struts] branch ww_5125_2_5 created (now 20e4529)
This is an automated email from the ASF dual-hosted git repository. yasserzamani pushed a change to branch ww_5125_2_5 in repository https://gitbox.apache.org/repos/asf/struts.git. at 20e4529 [WW-5125] use .get(...) instead of [...] for fieldErrors This branch includes the following new commits: new 20e4529 [WW-5125] use .get(...) instead of [...] for fieldErrors The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
[struts] 01/01: [WW-5125] use .get(...) instead of [...] for fieldErrors
This is an automated email from the ASF dual-hosted git repository. yasserzamani pushed a commit to branch ww_5125_2_5 in repository https://gitbox.apache.org/repos/asf/struts.git commit 20e4529e355d427c26916174259470fb91e3029f Author: Yasser Zamani AuthorDate: Sun Apr 25 14:56:47 2021 +0430 [WW-5125] use .get(...) instead of [...] for fieldErrors All [ occurrences in all ftl files reviewed. Only fieldErrors had used [...] which replaced by .get(...) to fix WW-5125 as well as aligning with other ftl files conduct. --- .../template/ajaxErrorContainers/controlfooter.ftl | 4 +- .../ajaxErrorContainers/controlheader-core.ftl | 4 +- .../main/resources/template/css_xhtml/checkbox.ftl | 4 +- .../resources/template/css_xhtml/controlfooter.ftl | 4 +- .../template/css_xhtml/controlheader-core.ftl | 4 +- core/src/main/resources/template/simple/css.ftl| 2 +- .../main/resources/template/simple/fielderror.ftl | 4 +- .../src/main/resources/template/xhtml/checkbox.ftl | 4 +- .../resources/template/xhtml/controlfooter.ftl | 4 +- .../template/xhtml/controlheader-core.ftl | 4 +- .../apache/struts2/views/jsp/ui/TextfieldTest.java | 18 - .../struts2/views/jsp/ui/Textfield-WW-5125.txt | 80 ++ 12 files changed, 116 insertions(+), 20 deletions(-) diff --git a/apps/showcase/src/main/resources/template/ajaxErrorContainers/controlfooter.ftl b/apps/showcase/src/main/resources/template/ajaxErrorContainers/controlfooter.ftl index 5d27b6f..89f9f2f 100644 --- a/apps/showcase/src/main/resources/template/ajaxErrorContainers/controlfooter.ftl +++ b/apps/showcase/src/main/resources/template/ajaxErrorContainers/controlfooter.ftl @@ -22,12 +22,12 @@ ${parameters.after!}<#t/> <#lt/> <#if (parameters.errorposition!"top") == 'bottom'> -<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors[parameters.name]??/> +<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors.get(parameters.name)??/> <#if hasFieldErrors> <#rt/> <#if hasFieldErrors> -<#list fieldErrors[parameters.name] as error> +<#list fieldErrors.get(parameters.name) as error> ${error?html}<#t/> diff --git a/apps/showcase/src/main/resources/template/ajaxErrorContainers/controlheader-core.ftl b/apps/showcase/src/main/resources/template/ajaxErrorContainers/controlheader-core.ftl index fe0b96c..df67d27 100644 --- a/apps/showcase/src/main/resources/template/ajaxErrorContainers/controlheader-core.ftl +++ b/apps/showcase/src/main/resources/template/ajaxErrorContainers/controlheader-core.ftl @@ -21,12 +21,12 @@ <#-- Always include elements to show errors. They may be filled later via AJAX. --> -<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors[parameters.name]??/> +<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors.get(parameters.name)??/> <#if (parameters.errorposition!"top") == 'top'> <#rt/> <#if hasFieldErrors> -<#list fieldErrors[parameters.name] as error> +<#list fieldErrors.get(parameters.name) as error> ${error?html}<#t/> diff --git a/core/src/main/resources/template/css_xhtml/checkbox.ftl b/core/src/main/resources/template/css_xhtml/checkbox.ftl index 5bb7eb2..65d4dcc 100644 --- a/core/src/main/resources/template/css_xhtml/checkbox.ftl +++ b/core/src/main/resources/template/css_xhtml/checkbox.ftl @@ -23,12 +23,12 @@ NOTE: The 'header' stuff that follows is in this one file for checkbox due to th that for checkboxes we do not want the label field to show up as checkboxes handle their own lables --> -<#assign hasFieldErrors = fieldErrors?? && fieldErrors[parameters.name]??/> +<#assign hasFieldErrors = fieldErrors?? && fieldErrors.get(parameters.name)??/> <#if parameters.id??>id="wwgrp_${parameters.id}"<#rt/> class="wwgrp"> <#if hasFieldErrors> <#if parameters.id??>id="wwerr_${parameters.id}"<#rt/> class="wwerr"> -<#list fieldErrors[parameters.name] as error> +<#list fieldErrors.get(parameters.name) as error> <#if parameters.id??> errorFor="${parameters.id}"<#rt/> diff --git a/core/src/main/resources/template/css_xhtml/controlfooter.ftl b/core/src/main/resources/template/css_xhtml/controlfooter.ftl index c4b06b6..e740952 100644 --- a/core/src/main/resources/template/css_xhtml/controlfooter.ftl +++ b/core/src/main/resources/template/css_xhtml/controlfooter.ftl @@ -31,10 +31,10 @@ ${parameters.after!}<#t/> <#rt/> <#if (parameters.errorposition!"top") == 'bottom'> -<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors[parameters.name]??/> +<#assign hasFieldErrors = parameters.name?? && fieldErrors?? && fieldErrors.get(parameters.name)??/> <#if hasFieldErrors> <#if parameters.id??>id="wwerr_${parameters.id}"<#rt/> class="wwerr"> -<#list fieldErrors[para
[struts] branch ww_5126_2_5 created (now 5096637)
This is an automated email from the ASF dual-hosted git repository. yasserzamani pushed a change to branch ww_5126_2_5 in repository https://gitbox.apache.org/repos/asf/struts.git. at 5096637 [WW-5126] use == instead of .equals in ModelDrivenInterceptor This branch includes the following new commits: new 5096637 [WW-5126] use == instead of .equals in ModelDrivenInterceptor The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
[struts] 01/01: [WW-5126] use == instead of .equals in ModelDrivenInterceptor
This is an automated email from the ASF dual-hosted git repository. yasserzamani pushed a commit to branch ww_5126_2_5 in repository https://gitbox.apache.org/repos/asf/struts.git commit 509663717a955669d987ebd3792a0049145a235f Author: Yasser Zamani AuthorDate: Sun Apr 25 19:04:55 2021 +0430 [WW-5126] use == instead of .equals in ModelDrivenInterceptor due to refreshing model regardless of potential overridden Object.equals --- .../xwork2/interceptor/ModelDrivenInterceptor.java | 12 ++-- .../interceptor/ModelDrivenInterceptorTest.java| 80 -- 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java b/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java index a70a5e3..fa90a31 100644 --- a/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java +++ b/core/src/main/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptor.java @@ -105,7 +105,7 @@ public class ModelDrivenInterceptor extends AbstractInterceptor { * Refreshes the model instance on the value stack, if it has changed */ protected static class RefreshModelBeforeResult implements PreResultListener { -private Object originalModel = null; +private Object originalModel; protected ModelDriven action; @@ -122,10 +122,12 @@ public class ModelDrivenInterceptor extends AbstractInterceptor { Object newModel = action.getModel(); // Check to see if the new model instance is already on the stack -for (Object item : root) { -if (item.equals(newModel)) { -needsRefresh = false; -break; +if (newModel != null) { +for (Object item : root) { +if (item == newModel) { +needsRefresh = false; +break; +} } } diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java index 71a8876..4f3589f 100644 --- a/core/src/test/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java @@ -37,10 +37,10 @@ public class ModelDrivenInterceptorTest extends XWorkTestCase { ModelDrivenInterceptor modelDrivenInterceptor; Object model; PreResultListener preResultListener; +ValueStack stack; public void testModelDrivenGetsPushedOntoStack() throws Exception { -ValueStack stack = ActionContext.getContext().getValueStack(); action = new ModelDrivenAction(); mockActionInvocation.expectAndReturn("getAction", action); mockActionInvocation.expectAndReturn("getStack", stack); @@ -52,8 +52,7 @@ public class ModelDrivenInterceptorTest extends XWorkTestCase { assertEquals("our model should be on the top of the stack", model, topOfStack); } -public void testModelDrivenUpdatedAndGetsPushedOntoStack() throws Exception { -ValueStack stack = ActionContext.getContext().getValueStack(); +private void setupRefreshModelBeforeResult() { action = new ModelDrivenAction(); mockActionInvocation.expectAndReturn("getAction", action); mockActionInvocation.matchAndReturn("getStack", stack); @@ -70,18 +69,86 @@ public class ModelDrivenInterceptorTest extends XWorkTestCase { } }); modelDrivenInterceptor.setRefreshModelBeforeResult(true); +} + +public void testModelDrivenUpdatedAndGetsPushedOntoStack() throws Exception { +setupRefreshModelBeforeResult(); modelDrivenInterceptor.intercept((ActionInvocation) mockActionInvocation.proxy()); assertNotNull(preResultListener); -model = "this is my model"; +model = "this is my new model"; preResultListener.beforeResult((ActionInvocation) mockActionInvocation.proxy(), "success"); Object topOfStack = stack.pop(); -assertEquals("our model should be on the top of the stack", model, topOfStack); +assertSame("our new model should be on the top of the stack", model, topOfStack); +assertEquals(1, stack.getRoot().size()); +} + +public void testWW5126() throws Exception { +model = new Object() { +@Override +public boolean equals(Object obj) { +return true; +} +}; +setupRefreshModelBeforeResult(); + +modelDrivenInterceptor.intercept((ActionInvocation) mockActionInvocation.proxy()); +assertNotNull(preResultListener); +model = "this is my new model"; +preResultListener.beforeResult((ActionInvocation) mock