From 82ab40dab49ecc047d74afe64859be311e4d54d0 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Fri, 12 Dec 2014 18:40:32 +0900 Subject: [PATCH 01/21] Struts2-TypeConversion Error handling added , but not performed. --- pom.xml | 15 ++- .../plugins/thymeleaf/StrutsContext.java | 46 ++++++- .../spi/DefaultTemplateEngineProvider.java | 120 +++++++++--------- src/main/resources/struts-plugin.xml | 2 +- 4 files changed, 119 insertions(+), 64 deletions(-) diff --git a/pom.xml b/pom.xml index f4d97fe..52ef662 100644 --- a/pom.xml +++ b/pom.xml @@ -5,12 +5,12 @@ org.codework struts2-thymeleaf-plugin jar - 2.3.16.3 + 2.3.20 struts2-thymeleaf-plugin http://www.codework.org/struts2-thymeleaf-plugin UTF-8 - 2.3.16.3 + 2.3.20 2.1.3.RELEASE @@ -39,6 +39,17 @@ thymeleaf ${thymeleaf.version} + + org.thymeleaf + thymeleaf-spring4 + 2.1.2.RELEASE + + + org.projectlombok + lombok + 1.14.4 + provided + diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/StrutsContext.java b/src/main/java/org/codework/struts/plugins/thymeleaf/StrutsContext.java index b4e71e5..04c10aa 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/StrutsContext.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/StrutsContext.java @@ -15,13 +15,23 @@ */ package org.codework.struts.plugins.thymeleaf; -import com.opensymphony.xwork2.LocaleProvider; -import org.thymeleaf.context.WebContext; +import java.util.Iterator; +import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; + +import org.thymeleaf.context.WebContext; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; +import com.opensymphony.xwork2.LocaleProvider; +import com.opensymphony.xwork2.ognl.OgnlValueStack; +import com.opensymphony.xwork2.util.ValueStack; + /** * Extends the {@link org.thymeleaf.context.WebContext} to provide access to the * Struts action. @@ -34,6 +44,7 @@ * @author Steven Benitez * @since 2.3.15 */ +@Slf4j public class StrutsContext extends WebContext { /** * Name of the variable that contains the action. @@ -49,6 +60,14 @@ public StrutsContext(HttpServletRequest request, HttpServletResponse response, S if (action instanceof LocaleProvider) { setLocale(((LocaleProvider) action).getLocale()); } + ValueStack stack = null; + // If found "TypeConversion Error" , repopulation request parameter. + if (action instanceof ActionSupport) { + repopulateConvertionErrorField(); + stack = ActionContext.getContext().getValueStack(); + } + + setVariable(ACTION_VARIABLE_NAME, action); } @@ -56,4 +75,27 @@ public StrutsContext(HttpServletRequest request, HttpServletResponse response, S public Object getAction() { return action; } + + /** + * If found type conversion error , + * original request paremeter repopulate same name. + */ + void repopulateConvertionErrorField() { + OgnlValueStack stack = (OgnlValueStack) ActionContext.getContext().getValueStack(); + Map overrides = stack.getExprOverrides(); + // if ( overrides != null && !overrides.isEmpty()) { + if (overrides != null) { + log.debug("overrides:" + overrides.toString()); + + Iterator keys = overrides.keySet().iterator(); + while (keys.hasNext()) { + String key = (String)keys.next(); + Object overval = overrides.get(key); + + stack.setValue(key, overval, false); + } + + ActionContext.getContext().setValueStack(stack); + } + } } diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java index 10e2e88..3403389 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java @@ -15,11 +15,13 @@ */ package org.codework.struts.plugins.thymeleaf.spi; -import com.opensymphony.xwork2.inject.Inject; import org.codework.struts.plugins.thymeleaf.StrutsMessageResolver; import org.thymeleaf.TemplateEngine; +import org.thymeleaf.spring4.SpringTemplateEngine; import org.thymeleaf.templateresolver.ServletContextTemplateResolver; +import com.opensymphony.xwork2.inject.Inject; + /** * A default implementation of {@link TemplateEngineProvider}. * @@ -27,74 +29,74 @@ * @since 2.3.15 */ public class DefaultTemplateEngineProvider implements TemplateEngineProvider { - // HTML5 is the future! - private String templateMode = "HTML5"; - private String characterEncoding = "UTF-8"; - // This will convert "home" to "/WEB-INF/templates/home.html" - private String prefix = "/WEB-INF/templates/"; - private String suffix = ".html"; - private boolean cacheable = true; + // HTML5 is the future! + private String templateMode = "HTML5"; + private String characterEncoding = "UTF-8"; + // This will convert "home" to "/WEB-INF/templates/home.html" + private String prefix = "/WEB-INF/templates/"; + private String suffix = ".html"; + private boolean cacheable = true; - // Default template cache TTL to 1 hour. If not set, entries would live in - // cache until expelled by LRU. - private Long cacheTtlMillis = 3600000L; + // Default template cache TTL to 1 hour. If not set, entries would live in + // cache until expelled by LRU. + private Long cacheTtlMillis = 3600000L; - private TemplateEngine templateEngine; + private TemplateEngine templateEngine; - /** - * Configure settings from the struts.xml or struts.properties, using sensible - * defaults if values are not provided. - */ - public void configure() { - ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); - templateResolver.setTemplateMode(templateMode); - templateResolver.setCharacterEncoding(characterEncoding); - templateResolver.setPrefix(prefix); - templateResolver.setSuffix(suffix); - templateResolver.setCacheable(cacheable); - templateResolver.setCacheTTLMs(cacheTtlMillis); + /** + * Configure settings from the struts.xml or struts.properties, using + * sensible defaults if values are not provided. + */ + public void configure() { + ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); + templateResolver.setTemplateMode(templateMode); + templateResolver.setCharacterEncoding(characterEncoding); + templateResolver.setPrefix(prefix); + templateResolver.setSuffix(suffix); + templateResolver.setCacheable(cacheable); + templateResolver.setCacheTTLMs(cacheTtlMillis); - templateEngine = new TemplateEngine(); - templateEngine.setTemplateResolver(templateResolver); - templateEngine.setMessageResolver(new StrutsMessageResolver()); - } + templateEngine = new SpringTemplateEngine(); + templateEngine.setTemplateResolver(templateResolver); + templateEngine.setMessageResolver(new StrutsMessageResolver()); + } - @Override - public TemplateEngine get() { - if (templateEngine == null) { - configure(); - } + @Override + public TemplateEngine get() { + if ( templateEngine == null ) { + configure(); + } - return templateEngine; - } + return templateEngine; + } - @Inject(value = "struts.thymeleaf.templateMode", required = false) - public void setTemplateMode(String templateMode) { - this.templateMode = templateMode; - } + @Inject(value = "struts.thymeleaf.templateMode", required = false) + public void setTemplateMode(String templateMode) { + this.templateMode = templateMode; + } - @Inject(value = "struts.thymeleaf.encoding", required = false) - public void setCharacterEncoding(String characterEncoding) { - this.characterEncoding = characterEncoding; - } + @Inject(value = "struts.thymeleaf.encoding", required = false) + public void setCharacterEncoding(String characterEncoding) { + this.characterEncoding = characterEncoding; + } - @Inject(value = "struts.thymeleaf.prefix", required = false) - public void setPrefix(String prefix) { - this.prefix = prefix; - } + @Inject(value = "struts.thymeleaf.prefix", required = false) + public void setPrefix(String prefix) { + this.prefix = prefix; + } - @Inject(value = "struts.thymeleaf.suffix", required = false) - public void setSuffix(String suffix) { - this.suffix = suffix; - } + @Inject(value = "struts.thymeleaf.suffix", required = false) + public void setSuffix(String suffix) { + this.suffix = suffix; + } - @Inject(value = "struts.thymeleaf.cacheable", required = false) - public void setCacheable(String cacheable) { - this.cacheable = Boolean.parseBoolean(cacheable); - } + @Inject(value = "struts.thymeleaf.cacheable", required = false) + public void setCacheable(String cacheable) { + this.cacheable = Boolean.parseBoolean(cacheable); + } - @Inject(value = "struts.thymeleaf.cacheTtlMillis", required = false) - public void setCacheTtlMillis(String cacheTtlMillis) { - this.cacheTtlMillis = Long.parseLong(cacheTtlMillis); - } + @Inject(value = "struts.thymeleaf.cacheTtlMillis", required = false) + public void setCacheTtlMillis(String cacheTtlMillis) { + this.cacheTtlMillis = Long.parseLong(cacheTtlMillis); + } } diff --git a/src/main/resources/struts-plugin.xml b/src/main/resources/struts-plugin.xml index f21e252..bf2241d 100644 --- a/src/main/resources/struts-plugin.xml +++ b/src/main/resources/struts-plugin.xml @@ -7,7 +7,7 @@ - + From 57f8e535e1b7a8f3f8a233a35acd6594698f4050 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Mon, 22 Dec 2014 14:58:57 +0900 Subject: [PATCH 02/21] Struts2.3.20 update+Thymeleaf-Spring plugin support --- pom.xml | 15 ++- .../thymeleaf/ThymeleafSpringResult.java | 112 ++++++++++++++++++ src/main/resources/struts-plugin.xml | 6 +- 3 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java diff --git a/pom.xml b/pom.xml index 52ef662..6562b7d 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,8 @@ UTF-8 2.3.20 - 2.1.3.RELEASE + 2.1.4.RELEASE + 4.1.1.RELEASE @@ -42,7 +43,7 @@ org.thymeleaf thymeleaf-spring4 - 2.1.2.RELEASE + ${thymeleaf.version} org.projectlombok @@ -50,6 +51,16 @@ 1.14.4 provided + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java new file mode 100644 index 0000000..9b7da54 --- /dev/null +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java @@ -0,0 +1,112 @@ +/* + * Copyright 2013 Steven Benitez. + * + * Licensed 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.codework.struts.plugins.thymeleaf; + +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.StrutsConstants; +import org.codework.struts.plugins.thymeleaf.spi.TemplateEngineProvider; +import org.springframework.context.ApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.spring4.context.SpringWebContext; + +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.LocaleProvider; +import com.opensymphony.xwork2.Result; +import com.opensymphony.xwork2.inject.Inject; + +/** + * Renders a Thymeleaf-Spring template as the result of invoking a Struts action. + * + * @author Steven Benitez ( Update A-pZ ) + * @since 2.3.15 + * @version 2.3.20 ( Update A-pZ ) + */ +public class ThymeleafSpringResult implements Result { + private String defaultEncoding = "UTF-8"; + private TemplateEngineProvider templateEngineProvider; + private String templateName; + + /** + * The result parameter name to set the name of the template to. + *

+ * IMPORTANT! Struts2 will look for this field reflectively to determine + * which parameter is the default. This allows us to have a simplified + * result configuration. Don't remove it! + */ + public static final String DEFAULT_PARAM = "templateName"; + + public ThymeleafSpringResult() { + } + + public ThymeleafSpringResult(String templateName) { + this.templateName = templateName; + } + + @Override + public void execute(ActionInvocation actionInvocation) throws Exception { + TemplateEngine templateEngine = templateEngineProvider.get(); + + HttpServletRequest request = ServletActionContext.getRequest(); + HttpServletResponse response = ServletActionContext.getResponse(); + ServletContext servletContext = ServletActionContext + .getServletContext(); + + Object action = actionInvocation.getAction(); + + // Action instance put to Thymeleaf context. + Map variables = new HashMap(); + variables.put("action", action); + + // Locale by Struts2-Action. + Locale locale = ((LocaleProvider) action).getLocale(); + + // Spring-ApplicationContext. + ApplicationContext appctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); + + // Use SpringWebContext( by Thymeleaf-spring plugin. ) + SpringWebContext context = new SpringWebContext(request, response, + servletContext, locale, variables, appctx); + + // response to TemplateEngine. + response.setContentType("text/html"); + response.setCharacterEncoding(defaultEncoding); + templateEngine.process(templateName, context, response.getWriter()); + } + + @Inject(StrutsConstants.STRUTS_I18N_ENCODING) + public void setDefaultEncoding(String defaultEncoding) { + this.defaultEncoding = defaultEncoding; + } + + @Inject + public void setTemplateEngineProvider( + TemplateEngineProvider templateEngineProvider) { + this.templateEngineProvider = templateEngineProvider; + } + + public void setTemplateName(String templateName) { + this.templateName = templateName; + } +} diff --git a/src/main/resources/struts-plugin.xml b/src/main/resources/struts-plugin.xml index bf2241d..7eaca43 100644 --- a/src/main/resources/struts-plugin.xml +++ b/src/main/resources/struts-plugin.xml @@ -1,15 +1,15 @@ - + "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" + "http://struts.apache.org/dtds/struts-2.3.dtd"> + \ No newline at end of file From 68e4e2239f9f70073a4951a3e75f6c766b59025a Mon Sep 17 00:00:00 2001 From: A-pZ Date: Fri, 26 Dec 2014 10:56:56 +0900 Subject: [PATCH 03/21] update thymeleaf 2.1.4 --- pom.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6562b7d..87be6fc 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ UTF-8 2.3.20 2.1.4.RELEASE - 4.1.1.RELEASE + 4.1.3.RELEASE @@ -61,6 +61,11 @@ spring-web ${spring.version} + + org.springframework + spring-webmvc + ${spring.version} + From 51a9ac0e7aee12e451945c787e34e174b6a74282 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Fri, 16 Jan 2015 10:43:00 +0900 Subject: [PATCH 04/21] add Thymeleaf Spring Result. --- .../plugins/thymeleaf/StrutsContext.java | 46 +------------------ .../thymeleaf/ThymeleafSpringResult.java | 39 +++++++++++++++- 2 files changed, 39 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/StrutsContext.java b/src/main/java/org/codework/struts/plugins/thymeleaf/StrutsContext.java index 04c10aa..b4e71e5 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/StrutsContext.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/StrutsContext.java @@ -15,23 +15,13 @@ */ package org.codework.struts.plugins.thymeleaf; -import java.util.Iterator; -import java.util.Map; +import com.opensymphony.xwork2.LocaleProvider; +import org.thymeleaf.context.WebContext; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import lombok.extern.slf4j.Slf4j; - -import org.thymeleaf.context.WebContext; - -import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.ActionSupport; -import com.opensymphony.xwork2.LocaleProvider; -import com.opensymphony.xwork2.ognl.OgnlValueStack; -import com.opensymphony.xwork2.util.ValueStack; - /** * Extends the {@link org.thymeleaf.context.WebContext} to provide access to the * Struts action. @@ -44,7 +34,6 @@ * @author Steven Benitez * @since 2.3.15 */ -@Slf4j public class StrutsContext extends WebContext { /** * Name of the variable that contains the action. @@ -60,14 +49,6 @@ public StrutsContext(HttpServletRequest request, HttpServletResponse response, S if (action instanceof LocaleProvider) { setLocale(((LocaleProvider) action).getLocale()); } - ValueStack stack = null; - // If found "TypeConversion Error" , repopulation request parameter. - if (action instanceof ActionSupport) { - repopulateConvertionErrorField(); - stack = ActionContext.getContext().getValueStack(); - } - - setVariable(ACTION_VARIABLE_NAME, action); } @@ -75,27 +56,4 @@ public StrutsContext(HttpServletRequest request, HttpServletResponse response, S public Object getAction() { return action; } - - /** - * If found type conversion error , - * original request paremeter repopulate same name. - */ - void repopulateConvertionErrorField() { - OgnlValueStack stack = (OgnlValueStack) ActionContext.getContext().getValueStack(); - Map overrides = stack.getExprOverrides(); - // if ( overrides != null && !overrides.isEmpty()) { - if (overrides != null) { - log.debug("overrides:" + overrides.toString()); - - Iterator keys = overrides.keySet().iterator(); - while (keys.hasNext()) { - String key = (String)keys.next(); - Object overval = overrides.get(key); - - stack.setValue(key, overval, false); - } - - ActionContext.getContext().setValueStack(stack); - } - } } diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java index 9b7da54..4cd6fa0 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java @@ -16,6 +16,7 @@ package org.codework.struts.plugins.thymeleaf; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; @@ -31,7 +32,9 @@ import org.thymeleaf.TemplateEngine; import org.thymeleaf.spring4.context.SpringWebContext; +import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.LocaleProvider; import com.opensymphony.xwork2.Result; import com.opensymphony.xwork2.inject.Inject; @@ -57,6 +60,15 @@ public class ThymeleafSpringResult implements Result { */ public static final String DEFAULT_PARAM = "templateName"; + /** instance name of struts2-action */ + public static final String ACTION_VARIABLE_NAME = "action"; + + /** field errors */ + public static final String FIELD_ERRORS_NAME ="field"; + + /** struts2 convertion errors fields and value */ + public static final String OVERWRITE_NAME = "overwrite"; + public ThymeleafSpringResult() { } @@ -76,8 +88,7 @@ public void execute(ActionInvocation actionInvocation) throws Exception { Object action = actionInvocation.getAction(); // Action instance put to Thymeleaf context. - Map variables = new HashMap(); - variables.put("action", action); + Map variables = bindStrutsContest(action); // Locale by Struts2-Action. Locale locale = ((LocaleProvider) action).getLocale(); @@ -109,4 +120,28 @@ public void setTemplateEngineProvider( public void setTemplateName(String templateName) { this.templateName = templateName; } + + /** + * Binding Struts2 action and context, field-errors , convertion error values bind another name. + * @param action Action instance + * @return ContextMap + */ + Map bindStrutsContest(Object action) { + Map variables = new HashMap(); + variables.put(ACTION_VARIABLE_NAME, action); + + if ( action instanceof ActionSupport) { + ActionSupport actSupport = (ActionSupport)action; + + // Struts2 field errors.( Map) + Map> fieldErrors = actSupport.getFieldErrors(); + variables.put(FIELD_ERRORS_NAME, fieldErrors); + + // Struts2 convertion errors + ActionContext ctx = ActionContext.getContext(); + variables.put(OVERWRITE_NAME, ctx.getValueStack().getExprOverrides()); + } + + return variables; + } } From 828bfb35eae5754f68f240e04e54aaf9627bf715 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Mon, 9 Feb 2015 15:45:41 +0900 Subject: [PATCH 05/21] Loading config from struts.xml * TemplateEngine loading from struts(-plugin).xml * TemplateEngine choose at struts.properties, default or spring. * Thymeleaf-Spring4 support. --- pom.xml | 7 ++- .../thymeleaf/ThymeleafSpringResult.java | 7 +-- .../spi/DefaultTemplateEngineProvider.java | 55 ++++++++++++++++--- .../Struts2SpringTemplateEngineProvider.java | 41 ++++++++++++++ src/main/resources/struts-plugin.xml | 3 + 5 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java diff --git a/pom.xml b/pom.xml index 87be6fc..578311b 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codework struts2-thymeleaf-plugin jar - 2.3.20 + 2.3.21-SNAPSHOT struts2-thymeleaf-plugin http://www.codework.org/struts2-thymeleaf-plugin @@ -66,6 +66,11 @@ spring-webmvc ${spring.version} + + serendip.lumi + thymeleaf-struts2-extension + 0.0.1-SNAPSHOT + diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java index 4cd6fa0..1dd0ef9 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java @@ -32,7 +32,6 @@ import org.thymeleaf.TemplateEngine; import org.thymeleaf.spring4.context.SpringWebContext; -import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.LocaleProvider; @@ -67,7 +66,7 @@ public class ThymeleafSpringResult implements Result { public static final String FIELD_ERRORS_NAME ="field"; /** struts2 convertion errors fields and value */ - public static final String OVERWRITE_NAME = "overwrite"; + public static final String OVERRIDES_NAME = "overrides"; public ThymeleafSpringResult() { } @@ -136,10 +135,6 @@ Map bindStrutsContest(Object action) { // Struts2 field errors.( Map) Map> fieldErrors = actSupport.getFieldErrors(); variables.put(FIELD_ERRORS_NAME, fieldErrors); - - // Struts2 convertion errors - ActionContext ctx = ActionContext.getContext(); - variables.put(OVERWRITE_NAME, ctx.getValueStack().getExprOverrides()); } return variables; diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java index 3403389..8552678 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java @@ -15,11 +15,18 @@ */ package org.codework.struts.plugins.thymeleaf.spi; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import lombok.extern.slf4j.Slf4j; + import org.codework.struts.plugins.thymeleaf.StrutsMessageResolver; import org.thymeleaf.TemplateEngine; -import org.thymeleaf.spring4.SpringTemplateEngine; import org.thymeleaf.templateresolver.ServletContextTemplateResolver; +import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.inject.Inject; /** @@ -28,6 +35,7 @@ * @author Steven Benitez * @since 2.3.15 */ +@Slf4j public class DefaultTemplateEngineProvider implements TemplateEngineProvider { // HTML5 is the future! private String templateMode = "HTML5"; @@ -41,7 +49,11 @@ public class DefaultTemplateEngineProvider implements TemplateEngineProvider { // cache until expelled by LRU. private Long cacheTtlMillis = 3600000L; - private TemplateEngine templateEngine; + protected TemplateEngine templateEngine; + + private String templateEngineName; + private Container container; + private Map templateEngines = new HashMap(); /** * Configure settings from the struts.xml or struts.properties, using @@ -56,17 +68,12 @@ public void configure() { templateResolver.setCacheable(cacheable); templateResolver.setCacheTTLMs(cacheTtlMillis); - templateEngine = new SpringTemplateEngine(); templateEngine.setTemplateResolver(templateResolver); templateEngine.setMessageResolver(new StrutsMessageResolver()); } @Override public TemplateEngine get() { - if ( templateEngine == null ) { - configure(); - } - return templateEngine; } @@ -99,4 +106,38 @@ public void setCacheable(String cacheable) { public void setCacheTtlMillis(String cacheTtlMillis) { this.cacheTtlMillis = Long.parseLong(cacheTtlMillis); } + + /** + * Thymeleaf template type loading from struts.properties. + * @param templateEngineType ( default | spring ) + */ + @Inject(value = "struts.thymeleaf.templateEngineType", required = true) + public void setTemplateEngineName(String templateEngineType) { + this.templateEngine = templateEngines.get(templateEngineType); + + log.debug(" - use template type:" + templateEngineType); + // configure template engine. + configure(); + } + + /** + * loading di container configulation from struts-plugins.xml , choise thymeleaf template engine. + * @param container + */ + @Inject + public void setContainer(Container container) { + log.debug("loading di container config."); + this.container = container; + + Map map = new HashMap(); + + Set prefixes = container.getInstanceNames(TemplateEngine.class); + for (String prefix : prefixes) { + TemplateEngine engine = (TemplateEngine) container.getInstance(TemplateEngine.class, prefix); + + map.put(prefix, engine); + log.debug(" -- prefix:" + prefix + " / engine:" + engine.getClass().getName()); + } + this.templateEngines = Collections.unmodifiableMap(map); + } } diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java new file mode 100644 index 0000000..d977b71 --- /dev/null +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2013 Steven Benitez. + * + * Licensed 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.codework.struts.plugins.thymeleaf.spi; + +import serendip.thymeleaf.FieldDiarect; + +/** + * Struts2-Spring4-Thymeleaf implementation.{@link TemplateEngineProvider}. + * + * @author Steven Benitez(Original Source) - overwrite by A-pZ ( 2.3.20 ) + * + * @since 2.3.15 + * @version 2.3.20 + */ +public class Struts2SpringTemplateEngineProvider extends DefaultTemplateEngineProvider { + + /** + * Configure settings from the struts.xml or struts.properties, using + * sensible defaults if values are not provided. + */ + public void configure() { + super.configure(); + + // add extended dialect. + FieldDiarect fieldDiarect = new FieldDiarect(); + templateEngine.addDialect(fieldDiarect); + } +} diff --git a/src/main/resources/struts-plugin.xml b/src/main/resources/struts-plugin.xml index 7eaca43..e896e81 100644 --- a/src/main/resources/struts-plugin.xml +++ b/src/main/resources/struts-plugin.xml @@ -6,6 +6,9 @@ + + + From dc7ab334d63cc615f535f2d16689102731392bfb Mon Sep 17 00:00:00 2001 From: A-pZ Date: Mon, 9 Feb 2015 17:18:19 +0900 Subject: [PATCH 06/21] Add Struts2-Spring-Diarect for Struts2-Type convetion error, --- pom.xml | 5 -- .../thymeleaf/diarect/FieldAttrProcessor.java | 81 +++++++++++++++++++ .../thymeleaf/diarect/FieldDiarect.java | 30 +++++++ .../thymeleaf/diarect/package-info.java | 6 ++ .../Struts2SpringTemplateEngineProvider.java | 2 +- 5 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java create mode 100644 src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDiarect.java create mode 100644 src/main/java/org/codework/struts/plugins/thymeleaf/diarect/package-info.java diff --git a/pom.xml b/pom.xml index 578311b..d2390e6 100644 --- a/pom.xml +++ b/pom.xml @@ -66,11 +66,6 @@ spring-webmvc ${spring.version} - - serendip.lumi - thymeleaf-struts2-extension - 0.0.1-SNAPSHOT - diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java new file mode 100644 index 0000000..21f8347 --- /dev/null +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java @@ -0,0 +1,81 @@ +/** + * + */ +package org.codework.struts.plugins.thymeleaf.diarect; + +import java.util.Map; + +import org.thymeleaf.Arguments; +import org.thymeleaf.dom.Element; +import org.thymeleaf.processor.attr.AbstractAttributeModifierAttrProcessor; +import org.thymeleaf.standard.processor.attr.AbstractStandardSingleAttributeModifierAttrProcessor; + +import com.opensymphony.xwork2.ActionContext; + +/** + * Thymeleaf extensions,field. + * @author A-pZ + * + */ +//@Slf4j +public class FieldAttrProcessor extends AbstractStandardSingleAttributeModifierAttrProcessor { + public static final int ATTR_PRECEDENCE = 1010; + public static final String ATTR_NAME = "value"; + + public FieldAttrProcessor() { + super(ATTR_NAME); + } + + protected String getTargetAttributeValue(Arguments arguments, Element element, String attributeName) + { + String attributeValue = super.getTargetAttributeValue(arguments, element, attributeName); + /* + if (element.hasNormalizedAttribute(Attribute.getPrefixFromAttributeName(attributeName), ATTR_NAME)) { + return attributeValue; + }*/ + String name = element.getAttributeValueFromNormalizedName("name"); + String type = element.getAttributeValueFromNormalizedName("type"); + return processOverridesValue(name,attributeValue); + } + + /** + * If Type-Convertion Error found at Struts2, overwrite request-parameter same name. + * + * @param name parameter-name + * @param value thymeleaf parameter-value + * @return request-parameter-value(if convertion error occurs,return from struts2 , not else thymeleaf.) + */ + protected String processOverridesValue(String name , String value) { + ActionContext ctx = ActionContext.getContext(); + Map overrideMap = ctx.getValueStack().getExprOverrides(); + if ( overrideMap != null && !overrideMap.isEmpty()) { + if (overrideMap.containsKey(name)) { + // log.debug(" - hit override map:[" + name + "] - " + value); + String convertionValue = (String)overrideMap.get(name); + + return convertionValue; + } + } + return value; + } + + @Override + protected String getTargetAttributeName(Arguments paramArguments, Element paramElement, String paramString) { + return ATTR_NAME; + } + + @Override + protected ModificationType getModificationType(Arguments paramArguments, Element paramElement, String paramString1, String paramString2) { + return AbstractAttributeModifierAttrProcessor.ModificationType.SUBSTITUTION; + } + + @Override + protected boolean removeAttributeIfEmpty(Arguments paramArguments, Element paramElement, String paramString1, String paramString2) { + return false; + } + + @Override + public int getPrecedence() { + return ATTR_PRECEDENCE; + } +} diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDiarect.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDiarect.java new file mode 100644 index 0000000..29c835d --- /dev/null +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDiarect.java @@ -0,0 +1,30 @@ +/** + * + */ +package org.codework.struts.plugins.thymeleaf.diarect; + +import java.util.HashSet; +import java.util.Set; + +import org.thymeleaf.dialect.AbstractDialect; +import org.thymeleaf.processor.IProcessor; + +/** + * diarect:sth. + * @author A-pZ + * + */ +public class FieldDiarect extends AbstractDialect { + + @Override + public String getPrefix() { + return "sth"; + } + + public Set getProcessors() { + final Set processors = new HashSet(); + processors.add(new FieldAttrProcessor()); + return processors; + } + +} diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/package-info.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/package-info.java new file mode 100644 index 0000000..25d35f4 --- /dev/null +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/package-info.java @@ -0,0 +1,6 @@ +/** + * Struts2-Spring-Thymeleaf diarect extension. + * @author A-pZ + * + */ +package org.codework.struts.plugins.thymeleaf.diarect; \ No newline at end of file diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java index d977b71..e3290c0 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java @@ -15,7 +15,7 @@ */ package org.codework.struts.plugins.thymeleaf.spi; -import serendip.thymeleaf.FieldDiarect; +import org.codework.struts.plugins.thymeleaf.diarect.FieldDiarect; /** * Struts2-Spring4-Thymeleaf implementation.{@link TemplateEngineProvider}. From 175465326cc1b2483219508eabf6c225c5a26e32 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Fri, 13 Feb 2015 15:38:50 +0900 Subject: [PATCH 07/21] Configulation and logging update. * add slf4j annotation(lombok) * add Struts2SpringTemplateEngine configuration. --- .../plugins/thymeleaf/ThymeleafResult.java | 13 ++++---- .../thymeleaf/ThymeleafSpringResult.java | 6 ++++ .../spi/DefaultTemplateEngineProvider.java | 31 +++++++++++-------- .../Struts2SpringTemplateEngineProvider.java | 5 +++ src/main/resources/struts-plugin.xml | 1 + 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafResult.java b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafResult.java index e093974..f7c4513 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafResult.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafResult.java @@ -15,17 +15,18 @@ */ package org.codework.struts.plugins.thymeleaf; -import com.opensymphony.xwork2.ActionInvocation; -import com.opensymphony.xwork2.Result; -import com.opensymphony.xwork2.inject.Inject; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsConstants; import org.codework.struts.plugins.thymeleaf.spi.TemplateEngineProvider; import org.thymeleaf.TemplateEngine; -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.Result; +import com.opensymphony.xwork2.inject.Inject; /** * Renders a Thymeleaf template as the result of invoking a Struts action. diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java index 1dd0ef9..122be04 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java @@ -24,6 +24,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; + import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsConstants; import org.codework.struts.plugins.thymeleaf.spi.TemplateEngineProvider; @@ -45,6 +47,7 @@ * @since 2.3.15 * @version 2.3.20 ( Update A-pZ ) */ +@Slf4j public class ThymeleafSpringResult implements Result { private String defaultEncoding = "UTF-8"; private TemplateEngineProvider templateEngineProvider; @@ -113,6 +116,9 @@ public void setDefaultEncoding(String defaultEncoding) { @Inject public void setTemplateEngineProvider( TemplateEngineProvider templateEngineProvider) { + + log.debug(" - templateEngineProvider :" + templateEngineProvider); + this.templateEngineProvider = templateEngineProvider; } diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java index 8552678..68be247 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java @@ -60,6 +60,8 @@ public class DefaultTemplateEngineProvider implements TemplateEngineProvider { * sensible defaults if values are not provided. */ public void configure() { + log.debug(" configure."); + ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); templateResolver.setTemplateMode(templateMode); templateResolver.setCharacterEncoding(characterEncoding); @@ -107,19 +109,6 @@ public void setCacheTtlMillis(String cacheTtlMillis) { this.cacheTtlMillis = Long.parseLong(cacheTtlMillis); } - /** - * Thymeleaf template type loading from struts.properties. - * @param templateEngineType ( default | spring ) - */ - @Inject(value = "struts.thymeleaf.templateEngineType", required = true) - public void setTemplateEngineName(String templateEngineType) { - this.templateEngine = templateEngines.get(templateEngineType); - - log.debug(" - use template type:" + templateEngineType); - // configure template engine. - configure(); - } - /** * loading di container configulation from struts-plugins.xml , choise thymeleaf template engine. * @param container @@ -140,4 +129,20 @@ public void setContainer(Container container) { } this.templateEngines = Collections.unmodifiableMap(map); } + + /** + * Thymeleaf template type loading from struts.properties. + * @param templateEngineType ( default | spring ) + */ + @Inject(value = "struts.thymeleaf.templateEngineName", required = true) + public void setTemplateEngineName(String templateEngineName) { + this.templateEngine = templateEngines.get(templateEngineName); + + log.debug(" - use template engine name :" + templateEngineName); + log.debug(" template engine class:" + this.templateEngine); + // configure template engine. + configure(); + } + + } diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java index e3290c0..0fa1293 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java @@ -15,6 +15,8 @@ */ package org.codework.struts.plugins.thymeleaf.spi; +import lombok.extern.slf4j.Slf4j; + import org.codework.struts.plugins.thymeleaf.diarect.FieldDiarect; /** @@ -25,6 +27,7 @@ * @since 2.3.15 * @version 2.3.20 */ +@Slf4j public class Struts2SpringTemplateEngineProvider extends DefaultTemplateEngineProvider { /** @@ -32,6 +35,8 @@ public class Struts2SpringTemplateEngineProvider extends DefaultTemplateEnginePr * sensible defaults if values are not provided. */ public void configure() { + log.debug(" * configure *"); + super.configure(); // add extended dialect. diff --git a/src/main/resources/struts-plugin.xml b/src/main/resources/struts-plugin.xml index e896e81..4f11b94 100644 --- a/src/main/resources/struts-plugin.xml +++ b/src/main/resources/struts-plugin.xml @@ -5,6 +5,7 @@ "http://struts.apache.org/dtds/struts-2.3.dtd"> + From 70ff34e213349f6e76e351fccedd44ab89f6a337 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Mon, 16 Feb 2015 14:18:02 +0900 Subject: [PATCH 08/21] Change template engine provider loading and DI Container loading. * remove Struts2SpringTemplateEngineProvider * update ThymeleafSpringResult, DI container change to set config. * add customed diarect. * update struts-plugin.xml --- .../thymeleaf/ThymeleafSpringResult.java | 13 ++---- .../thymeleaf/diarect/FieldAttrProcessor.java | 15 ++++-- .../spi/DefaultTemplateEngineProvider.java | 34 ++++++++++---- .../Struts2SpringTemplateEngineProvider.java | 46 ------------------- src/main/resources/struts-plugin.xml | 5 +- 5 files changed, 43 insertions(+), 70 deletions(-) delete mode 100644 src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java index 122be04..f10157d 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java @@ -24,13 +24,11 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import lombok.extern.slf4j.Slf4j; - import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsConstants; import org.codework.struts.plugins.thymeleaf.spi.TemplateEngineProvider; import org.springframework.context.ApplicationContext; -import org.springframework.web.context.support.WebApplicationContextUtils; +import org.springframework.web.context.WebApplicationContext; import org.thymeleaf.TemplateEngine; import org.thymeleaf.spring4.context.SpringWebContext; @@ -47,7 +45,7 @@ * @since 2.3.15 * @version 2.3.20 ( Update A-pZ ) */ -@Slf4j +//@Slf4j public class ThymeleafSpringResult implements Result { private String defaultEncoding = "UTF-8"; private TemplateEngineProvider templateEngineProvider; @@ -96,7 +94,9 @@ public void execute(ActionInvocation actionInvocation) throws Exception { Locale locale = ((LocaleProvider) action).getLocale(); // Spring-ApplicationContext. - ApplicationContext appctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); + //ApplicationContext appctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); + ApplicationContext appctx = + (ApplicationContext)servletContext.getAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); // Use SpringWebContext( by Thymeleaf-spring plugin. ) SpringWebContext context = new SpringWebContext(request, response, @@ -116,9 +116,6 @@ public void setDefaultEncoding(String defaultEncoding) { @Inject public void setTemplateEngineProvider( TemplateEngineProvider templateEngineProvider) { - - log.debug(" - templateEngineProvider :" + templateEngineProvider); - this.templateEngineProvider = templateEngineProvider; } diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java index 21f8347..3b55114 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java @@ -5,19 +5,23 @@ import java.util.Map; +import lombok.extern.slf4j.Slf4j; + +import org.apache.struts2.util.ComponentUtils; import org.thymeleaf.Arguments; import org.thymeleaf.dom.Element; import org.thymeleaf.processor.attr.AbstractAttributeModifierAttrProcessor; import org.thymeleaf.standard.processor.attr.AbstractStandardSingleAttributeModifierAttrProcessor; import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.util.ValueStack; /** * Thymeleaf extensions,field. * @author A-pZ * */ -//@Slf4j +@Slf4j public class FieldAttrProcessor extends AbstractStandardSingleAttributeModifierAttrProcessor { public static final int ATTR_PRECEDENCE = 1010; public static final String ATTR_NAME = "value"; @@ -47,12 +51,17 @@ protected String getTargetAttributeValue(Arguments arguments, Element element, S */ protected String processOverridesValue(String name , String value) { ActionContext ctx = ActionContext.getContext(); - Map overrideMap = ctx.getValueStack().getExprOverrides(); + ValueStack stack = ctx.getValueStack(); + Map overrideMap = stack.getExprOverrides(); if ( overrideMap != null && !overrideMap.isEmpty()) { if (overrideMap.containsKey(name)) { - // log.debug(" - hit override map:[" + name + "] - " + value); + log.debug(" - hit override map:[" + name + "] - " + value); String convertionValue = (String)overrideMap.get(name); + // Struts2-Conponent is wrapped String quote, which erase for output value. + String altString = ComponentUtils.stripExpressionIfAltSyntax(stack, convertionValue); + log.debug(" - alt string:" + altString); + return convertionValue; } } diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java index 68be247..5174f97 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java @@ -22,7 +22,9 @@ import lombok.extern.slf4j.Slf4j; +import org.apache.struts2.dispatcher.Dispatcher; import org.codework.struts.plugins.thymeleaf.StrutsMessageResolver; +import org.codework.struts.plugins.thymeleaf.diarect.FieldDiarect; import org.thymeleaf.TemplateEngine; import org.thymeleaf.templateresolver.ServletContextTemplateResolver; @@ -72,10 +74,27 @@ public void configure() { templateEngine.setTemplateResolver(templateResolver); templateEngine.setMessageResolver(new StrutsMessageResolver()); + + // extension diarects. + FieldDiarect fieldDiarect = new FieldDiarect(); + templateEngine.addDialect(fieldDiarect); } @Override public TemplateEngine get() { + if ( templateEngine == null ) { + Container container = Dispatcher.getInstance().getContainer(); + setContainer(container); + + // loading template engine from struts2 di container. + this.templateEngine = templateEngines.get(templateEngineName); + + log.debug(" - use template engine name :" + templateEngineName); + log.debug(" template engine class:" + this.templateEngine); + + configure(); + } + return templateEngine; } @@ -110,16 +129,16 @@ public void setCacheTtlMillis(String cacheTtlMillis) { } /** - * loading di container configulation from struts-plugins.xml , choise thymeleaf template engine. + * loading di container configulation from struts-plugin.xml , choise thymeleaf template engine. * @param container */ - @Inject public void setContainer(Container container) { log.debug("loading di container config."); this.container = container; Map map = new HashMap(); - + + // loading TemplateEngine class from DI Container. Set prefixes = container.getInstanceNames(TemplateEngine.class); for (String prefix : prefixes) { TemplateEngine engine = (TemplateEngine) container.getInstance(TemplateEngine.class, prefix); @@ -134,14 +153,9 @@ public void setContainer(Container container) { * Thymeleaf template type loading from struts.properties. * @param templateEngineType ( default | spring ) */ - @Inject(value = "struts.thymeleaf.templateEngineName", required = true) + @Inject(value = "struts.thymeleaf.templateEngineName") public void setTemplateEngineName(String templateEngineName) { - this.templateEngine = templateEngines.get(templateEngineName); - - log.debug(" - use template engine name :" + templateEngineName); - log.debug(" template engine class:" + this.templateEngine); - // configure template engine. - configure(); + this.templateEngineName = templateEngineName; } diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java deleted file mode 100644 index 0fa1293..0000000 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/Struts2SpringTemplateEngineProvider.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2013 Steven Benitez. - * - * Licensed 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.codework.struts.plugins.thymeleaf.spi; - -import lombok.extern.slf4j.Slf4j; - -import org.codework.struts.plugins.thymeleaf.diarect.FieldDiarect; - -/** - * Struts2-Spring4-Thymeleaf implementation.{@link TemplateEngineProvider}. - * - * @author Steven Benitez(Original Source) - overwrite by A-pZ ( 2.3.20 ) - * - * @since 2.3.15 - * @version 2.3.20 - */ -@Slf4j -public class Struts2SpringTemplateEngineProvider extends DefaultTemplateEngineProvider { - - /** - * Configure settings from the struts.xml or struts.properties, using - * sensible defaults if values are not provided. - */ - public void configure() { - log.debug(" * configure *"); - - super.configure(); - - // add extended dialect. - FieldDiarect fieldDiarect = new FieldDiarect(); - templateEngine.addDialect(fieldDiarect); - } -} diff --git a/src/main/resources/struts-plugin.xml b/src/main/resources/struts-plugin.xml index 4f11b94..2496911 100644 --- a/src/main/resources/struts-plugin.xml +++ b/src/main/resources/struts-plugin.xml @@ -5,15 +5,14 @@ "http://struts.apache.org/dtds/struts-2.3.dtd"> - - + - + \ No newline at end of file From 4e89977311075f1b7ebbaa81a4a503748210758f Mon Sep 17 00:00:00 2001 From: A-pZ Date: Wed, 18 Feb 2015 10:09:25 +0900 Subject: [PATCH 09/21] update plugin config. --- src/main/resources/struts-plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/struts-plugin.xml b/src/main/resources/struts-plugin.xml index 2496911..644ea54 100644 --- a/src/main/resources/struts-plugin.xml +++ b/src/main/resources/struts-plugin.xml @@ -12,7 +12,7 @@ - + \ No newline at end of file From 3b60eacaa2d0c6067be7cd23fc7f5103ba8b243e Mon Sep 17 00:00:00 2001 From: A-pZ Date: Thu, 26 Feb 2015 11:59:23 +0900 Subject: [PATCH 10/21] Request-parameter overwrite from Struts2 which cause convertion error fields , unescape values. --- .../struts/plugins/thymeleaf/ThymeleafSpringResult.java | 2 +- .../plugins/thymeleaf/diarect/FieldAttrProcessor.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java index f10157d..b88e9fe 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java @@ -124,7 +124,7 @@ public void setTemplateName(String templateName) { } /** - * Binding Struts2 action and context, field-errors , convertion error values bind another name. + * Binding Struts2 action and context, field-errors bind another name. * @param action Action instance * @return ContextMap */ diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java index 3b55114..3b6b967 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java @@ -7,7 +7,7 @@ import lombok.extern.slf4j.Slf4j; -import org.apache.struts2.util.ComponentUtils; +import org.apache.commons.lang3.StringEscapeUtils; import org.thymeleaf.Arguments; import org.thymeleaf.dom.Element; import org.thymeleaf.processor.attr.AbstractAttributeModifierAttrProcessor; @@ -59,10 +59,12 @@ protected String processOverridesValue(String name , String value) { String convertionValue = (String)overrideMap.get(name); // Struts2-Conponent is wrapped String quote, which erase for output value. - String altString = ComponentUtils.stripExpressionIfAltSyntax(stack, convertionValue); + String altString = StringEscapeUtils.unescapeJava(convertionValue); + altString = altString.substring(1, altString.length() -1); + //String altString = log.debug(" - alt string:" + altString); - return convertionValue; + return altString; } } return value; From 7bbc0a8cb25b967e542dca488509d87c1826ed3b Mon Sep 17 00:00:00 2001 From: A-pZ Date: Thu, 26 Feb 2015 13:01:14 +0900 Subject: [PATCH 11/21] update version 2.3.22 * remove lombok , lombok annotations , logging. --- pom.xml | 8 +------ .../thymeleaf/ThymeleafSpringResult.java | 3 +-- .../thymeleaf/diarect/FieldAttrProcessor.java | 6 ------ .../spi/DefaultTemplateEngineProvider.java | 21 ++++--------------- 4 files changed, 6 insertions(+), 32 deletions(-) diff --git a/pom.xml b/pom.xml index d2390e6..9d8aed0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codework struts2-thymeleaf-plugin jar - 2.3.21-SNAPSHOT + 2.3.22 struts2-thymeleaf-plugin http://www.codework.org/struts2-thymeleaf-plugin @@ -45,12 +45,6 @@ thymeleaf-spring4 ${thymeleaf.version} - - org.projectlombok - lombok - 1.14.4 - provided - org.springframework spring-context diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java index b88e9fe..c4083fe 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java @@ -45,7 +45,6 @@ * @since 2.3.15 * @version 2.3.20 ( Update A-pZ ) */ -//@Slf4j public class ThymeleafSpringResult implements Result { private String defaultEncoding = "UTF-8"; private TemplateEngineProvider templateEngineProvider; @@ -124,7 +123,7 @@ public void setTemplateName(String templateName) { } /** - * Binding Struts2 action and context, field-errors bind another name. + * Binding Struts2 action and context, and field-errors list binding "field". * @param action Action instance * @return ContextMap */ diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java index 3b6b967..2ccc584 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java @@ -5,8 +5,6 @@ import java.util.Map; -import lombok.extern.slf4j.Slf4j; - import org.apache.commons.lang3.StringEscapeUtils; import org.thymeleaf.Arguments; import org.thymeleaf.dom.Element; @@ -21,7 +19,6 @@ * @author A-pZ * */ -@Slf4j public class FieldAttrProcessor extends AbstractStandardSingleAttributeModifierAttrProcessor { public static final int ATTR_PRECEDENCE = 1010; public static final String ATTR_NAME = "value"; @@ -55,14 +52,11 @@ protected String processOverridesValue(String name , String value) { Map overrideMap = stack.getExprOverrides(); if ( overrideMap != null && !overrideMap.isEmpty()) { if (overrideMap.containsKey(name)) { - log.debug(" - hit override map:[" + name + "] - " + value); String convertionValue = (String)overrideMap.get(name); // Struts2-Conponent is wrapped String quote, which erase for output value. String altString = StringEscapeUtils.unescapeJava(convertionValue); altString = altString.substring(1, altString.length() -1); - //String altString = - log.debug(" - alt string:" + altString); return altString; } diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java index 5174f97..fcbe515 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java @@ -20,8 +20,6 @@ import java.util.Map; import java.util.Set; -import lombok.extern.slf4j.Slf4j; - import org.apache.struts2.dispatcher.Dispatcher; import org.codework.struts.plugins.thymeleaf.StrutsMessageResolver; import org.codework.struts.plugins.thymeleaf.diarect.FieldDiarect; @@ -36,8 +34,8 @@ * * @author Steven Benitez * @since 2.3.15 + * @version 2.3.20 A-pZ */ -@Slf4j public class DefaultTemplateEngineProvider implements TemplateEngineProvider { // HTML5 is the future! private String templateMode = "HTML5"; @@ -62,8 +60,6 @@ public class DefaultTemplateEngineProvider implements TemplateEngineProvider { * sensible defaults if values are not provided. */ public void configure() { - log.debug(" configure."); - ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver(); templateResolver.setTemplateMode(templateMode); templateResolver.setCharacterEncoding(characterEncoding); @@ -85,13 +81,9 @@ public TemplateEngine get() { if ( templateEngine == null ) { Container container = Dispatcher.getInstance().getContainer(); setContainer(container); - + // loading template engine from struts2 di container. this.templateEngine = templateEngines.get(templateEngineName); - - log.debug(" - use template engine name :" + templateEngineName); - log.debug(" template engine class:" + this.templateEngine); - configure(); } @@ -133,18 +125,15 @@ public void setCacheTtlMillis(String cacheTtlMillis) { * @param container */ public void setContainer(Container container) { - log.debug("loading di container config."); this.container = container; Map map = new HashMap(); - - // loading TemplateEngine class from DI Container. + + // loading TemplateEngine class from DI Container. Set prefixes = container.getInstanceNames(TemplateEngine.class); for (String prefix : prefixes) { TemplateEngine engine = (TemplateEngine) container.getInstance(TemplateEngine.class, prefix); - map.put(prefix, engine); - log.debug(" -- prefix:" + prefix + " / engine:" + engine.getClass().getName()); } this.templateEngines = Collections.unmodifiableMap(map); } @@ -157,6 +146,4 @@ public void setContainer(Container container) { public void setTemplateEngineName(String templateEngineName) { this.templateEngineName = templateEngineName; } - - } From 79c5354f85dcdcfc072bc4f84848cbf13a856226 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Fri, 20 Mar 2015 16:35:58 +0900 Subject: [PATCH 12/21] templateEngine property name changed. templateEngineName definition updated. --- README.md | 2 +- changelog.2.3.22.txt | 6 ++++++ pom.xml | 2 +- .../thymeleaf/spi/DefaultTemplateEngineProvider.java | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 changelog.2.3.22.txt diff --git a/README.md b/README.md index 7f927ea..576ff8d 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ The following reflects the default settings. - + ## License Copyright 2013 Steven Benitez. diff --git a/changelog.2.3.22.txt b/changelog.2.3.22.txt new file mode 100644 index 0000000..3d5f64d --- /dev/null +++ b/changelog.2.3.22.txt @@ -0,0 +1,6 @@ +ChangeLog 2.3.16.3 -> 2.3.22 + +* Add new result-type : "thymeleaf-spring" , usable to spring beans '${beans.(beanName)}'. +* Add new diarect for Struts2 Type convertion error output, namespace and attribute 'sth:field'. +* Add support output Struts2 'Field error' , named 'field'. An example usage ${field['task']}. + diff --git a/pom.xml b/pom.xml index 9d8aed0..4fc1c72 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codework struts2-thymeleaf-plugin jar - 2.3.22 + 2.3.22-SNAPSHOT struts2-thymeleaf-plugin http://www.codework.org/struts2-thymeleaf-plugin diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java index fcbe515..a399a6d 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java @@ -51,7 +51,7 @@ public class DefaultTemplateEngineProvider implements TemplateEngineProvider { protected TemplateEngine templateEngine; - private String templateEngineName; + private String templateEngineName = "default"; private Container container; private Map templateEngines = new HashMap(); @@ -140,7 +140,7 @@ public void setContainer(Container container) { /** * Thymeleaf template type loading from struts.properties. - * @param templateEngineType ( default | spring ) + * @param templateEngineName ( default | spring ) */ @Inject(value = "struts.thymeleaf.templateEngineName") public void setTemplateEngineName(String templateEngineName) { From 7e08d6ed6c7eaa1e3fd6b4eebfb962bd3e43b6b0 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Tue, 7 Apr 2015 18:53:46 +0900 Subject: [PATCH 13/21] update struts 2.3.23 --- pom.xml | 228 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 114 insertions(+), 114 deletions(-) diff --git a/pom.xml b/pom.xml index 4fc1c72..c3ede67 100644 --- a/pom.xml +++ b/pom.xml @@ -1,115 +1,115 @@ - - - 4.0.0 - org.codework - struts2-thymeleaf-plugin - jar - 2.3.22-SNAPSHOT - struts2-thymeleaf-plugin - http://www.codework.org/struts2-thymeleaf-plugin - - UTF-8 - 2.3.20 - 2.1.4.RELEASE - 4.1.3.RELEASE - - - - - maven-org-repo - http://repo1.maven.org/maven2/ - - - - - javax.servlet - servlet-api - 2.5 - provided - - - - org.apache.struts - struts2-core - ${struts2.version} - - - - org.thymeleaf - thymeleaf - ${thymeleaf.version} - - - org.thymeleaf - thymeleaf-spring4 - ${thymeleaf.version} - - - org.springframework - spring-context - ${spring.version} - - - org.springframework - spring-web - ${spring.version} - - - org.springframework - spring-webmvc - ${spring.version} - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - true - 256m - 512m - 1.6 - 1.6 - ${project.build.sourceEncoding} - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-idea-plugin - 2.2 - - true - true - 1.6 - 1.6 - - - - + + + 4.0.0 + org.codework + struts2-thymeleaf-plugin + jar + ${struts2.version} + struts2-thymeleaf-plugin + http://www.codework.org/struts2-thymeleaf-plugin + + UTF-8 + 2.3.23 + 2.1.4.RELEASE + 4.1.3.RELEASE + + + + + maven-org-repo + http://repo1.maven.org/maven2/ + + + + + javax.servlet + servlet-api + 2.5 + provided + + + + org.apache.struts + struts2-core + ${struts2.version} + + + + org.thymeleaf + thymeleaf + ${thymeleaf.version} + + + org.thymeleaf + thymeleaf-spring4 + ${thymeleaf.version} + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + true + 256m + 512m + 1.6 + 1.6 + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-idea-plugin + 2.2 + + true + true + 1.6 + 1.6 + + + + \ No newline at end of file From 0fe2a78675fb873c24047e6245db8ff9cbb294b9 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Thu, 9 Apr 2015 15:23:21 +0900 Subject: [PATCH 14/21] correct misspelled... --- .../diarect/{FieldDiarect.java => FieldDialect.java} | 2 +- .../thymeleaf/spi/DefaultTemplateEngineProvider.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/main/java/org/codework/struts/plugins/thymeleaf/diarect/{FieldDiarect.java => FieldDialect.java} (90%) diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDiarect.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java similarity index 90% rename from src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDiarect.java rename to src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java index 29c835d..9b89f38 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDiarect.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java @@ -14,7 +14,7 @@ * @author A-pZ * */ -public class FieldDiarect extends AbstractDialect { +public class FieldDialect extends AbstractDialect { @Override public String getPrefix() { diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java index a399a6d..754edaf 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java @@ -22,7 +22,7 @@ import org.apache.struts2.dispatcher.Dispatcher; import org.codework.struts.plugins.thymeleaf.StrutsMessageResolver; -import org.codework.struts.plugins.thymeleaf.diarect.FieldDiarect; +import org.codework.struts.plugins.thymeleaf.diarect.FieldDialect; import org.thymeleaf.TemplateEngine; import org.thymeleaf.templateresolver.ServletContextTemplateResolver; @@ -72,8 +72,8 @@ public void configure() { templateEngine.setMessageResolver(new StrutsMessageResolver()); // extension diarects. - FieldDiarect fieldDiarect = new FieldDiarect(); - templateEngine.addDialect(fieldDiarect); + FieldDialect fieldDialect = new FieldDialect(); + templateEngine.addDialect(fieldDialect); } @Override From 2233bbc66760dfd4cb62d79da127ae5435329118 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Mon, 4 May 2015 13:55:38 +0900 Subject: [PATCH 15/21] update pom.xml - Struts2.3.23-SNAPSHOT version updated. --- pom.xml | 223 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 114 insertions(+), 109 deletions(-) diff --git a/pom.xml b/pom.xml index c3ede67..46914d4 100644 --- a/pom.xml +++ b/pom.xml @@ -1,115 +1,120 @@ - 4.0.0 - org.codework - struts2-thymeleaf-plugin - jar - ${struts2.version} - struts2-thymeleaf-plugin - http://www.codework.org/struts2-thymeleaf-plugin - - UTF-8 - 2.3.23 - 2.1.4.RELEASE - 4.1.3.RELEASE - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + org.codework + struts2-thymeleaf-plugin + jar + ${struts2.version} + struts2-thymeleaf-plugin + http://www.codework.org/struts2-thymeleaf-plugin + + UTF-8 + 2.3.24-SNAPSHOT + 2.1.4.RELEASE + 4.1.6.RELEASE + - - - maven-org-repo - http://repo1.maven.org/maven2/ - - - - - javax.servlet - servlet-api - 2.5 - provided - + + + maven-org-repo + http://repo1.maven.org/maven2/ + + + apache.snapshots + ASF Maven 2 Snapshot + https://repository.apache.org/content/groups/snapshots/ + + + + + javax.servlet + servlet-api + 2.5 + provided + - - org.apache.struts - struts2-core - ${struts2.version} - + + org.apache.struts + struts2-core + ${struts2.version} + - - org.thymeleaf - thymeleaf - ${thymeleaf.version} - - - org.thymeleaf - thymeleaf-spring4 - ${thymeleaf.version} - - - org.springframework - spring-context - ${spring.version} - - - org.springframework - spring-web - ${spring.version} - - - org.springframework - spring-webmvc - ${spring.version} - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - true - 256m - 512m - 1.6 - 1.6 - ${project.build.sourceEncoding} - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-idea-plugin - 2.2 - - true - true - 1.6 - 1.6 - - - - + + org.thymeleaf + thymeleaf + ${thymeleaf.version} + + + org.thymeleaf + thymeleaf-spring4 + ${thymeleaf.version} + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + true + 256m + 512m + 1.6 + 1.6 + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-idea-plugin + 2.2 + + true + true + 1.6 + 1.6 + + + + \ No newline at end of file From bd3928ead7ffb7dcae43b4191bee4188e0356563 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Mon, 4 May 2015 15:12:06 +0900 Subject: [PATCH 16/21] Add FieldErrorClassAttrProcessor --- .../thymeleaf/diarect/FieldDialect.java | 61 +++++----- .../Struts2ErrorClassAttrProcessor.java | 112 ++++++++++++++++++ 2 files changed, 143 insertions(+), 30 deletions(-) create mode 100644 src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2ErrorClassAttrProcessor.java diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java index 9b89f38..9bdc0cb 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java @@ -1,30 +1,31 @@ -/** - * - */ -package org.codework.struts.plugins.thymeleaf.diarect; - -import java.util.HashSet; -import java.util.Set; - -import org.thymeleaf.dialect.AbstractDialect; -import org.thymeleaf.processor.IProcessor; - -/** - * diarect:sth. - * @author A-pZ - * - */ -public class FieldDialect extends AbstractDialect { - - @Override - public String getPrefix() { - return "sth"; - } - - public Set getProcessors() { - final Set processors = new HashSet(); - processors.add(new FieldAttrProcessor()); - return processors; - } - -} +/** + * + */ +package org.codework.struts.plugins.thymeleaf.diarect; + +import java.util.HashSet; +import java.util.Set; + +import org.thymeleaf.dialect.AbstractDialect; +import org.thymeleaf.processor.IProcessor; + +/** + * diarect:sth. + * @author A-pZ + * + */ +public class FieldDialect extends AbstractDialect { + + @Override + public String getPrefix() { + return "sth"; + } + + public Set getProcessors() { + final Set processors = new HashSet(); + processors.add(new FieldAttrProcessor()); + processors.add(new Struts2ErrorClassAttrProcessor()); + return processors; + } + +} diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2ErrorClassAttrProcessor.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2ErrorClassAttrProcessor.java new file mode 100644 index 0000000..aa1adcc --- /dev/null +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2ErrorClassAttrProcessor.java @@ -0,0 +1,112 @@ +/** + * + */ +package org.codework.struts.plugins.thymeleaf.diarect; + +import java.util.List; +import java.util.Map; + +import org.thymeleaf.Arguments; +import org.thymeleaf.dom.Element; +import org.thymeleaf.standard.processor.attr.AbstractStandardSingleAttributeModifierAttrProcessor; +import org.thymeleaf.util.StringUtils; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; + +/** + * Field error css class processor for Struts2-Thymeleaf plugin. + * @author A-pZ + * + */ +public class Struts2ErrorClassAttrProcessor extends + AbstractStandardSingleAttributeModifierAttrProcessor { + + public static final int ATTR_PRECEDENCE = 10100; + public static final String ATTR_NAME = "errorclass"; + public static final String TARGET_ATTR_NAME = "class"; + + /** + * Default Constructor. + */ + public Struts2ErrorClassAttrProcessor() { + super(ATTR_NAME); + } + + /** + * Update to attribute name. + * @see org.thymeleaf.processor.attr.AbstractSingleAttributeModifierAttrProcessor#getTargetAttributeName(org.thymeleaf.Arguments, org.thymeleaf.dom.Element, java.lang.String) + */ + @Override + protected String getTargetAttributeName(Arguments arguments, + Element element, String attributeName) { + return TARGET_ATTR_NAME; + } + + /** + * Attribute update type. APPEND_WITH_SPACE is attribute value append with white-space. + * @see org.thymeleaf.processor.attr.AbstractAttributeModifierAttrProcessor#getModificationType(org.thymeleaf.Arguments, org.thymeleaf.dom.Element, java.lang.String, java.lang.String) + */ + @Override + protected ModificationType getModificationType(Arguments arguments, + Element element, String attributeName, String newAttributeName) { + return ModificationType.APPEND_WITH_SPACE; + } + + /** + * If this method is true , remove attribute. + * @see org.thymeleaf.processor.attr.AbstractAttributeModifierAttrProcessor#removeAttributeIfEmpty(org.thymeleaf.Arguments, org.thymeleaf.dom.Element, java.lang.String, java.lang.String) + */ + @Override + protected boolean removeAttributeIfEmpty(Arguments arguments, + Element element, String attributeName, String newAttributeName) { + return true; + } + + /** + * Attribute write precedence, default value is 1000. + * @see org.thymeleaf.processor.AbstractProcessor#getPrecedence() + */ + @Override + public int getPrecedence() { + return ATTR_PRECEDENCE; + } + + /** + * If has field error, output field error from strus2-field-errors. + */ + @Override + protected String getTargetAttributeValue( + final Arguments arguments, final Element element, final String attributeName) { + + Object actobj = ActionContext.getContext().getActionInvocation().getAction(); + if ( actobj == null ) { + return BLANK; + } + + if (!( actobj instanceof ActionSupport )) { + return BLANK; + } + + ActionSupport action = (ActionSupport)actobj; + if (! action.hasFieldErrors()) { + return BLANK; + } + + final String fieldName = element.getAttributeValue("name"); + if (StringUtils.isEmptyOrWhitespace(fieldName)) { + return BLANK; + } + + Map> fieldErrors = action.getFieldErrors(); + + List targetFieldErrors = fieldErrors.get(fieldName); + if ( targetFieldErrors.isEmpty() || targetFieldErrors.size() == 0 ) { + return BLANK; + } + + return super.getTargetAttributeValue(arguments, element, attributeName); + } + + public static final String BLANK = ""; +} From f5e275d5e738abc4d398f8faaf826e5581c3e10a Mon Sep 17 00:00:00 2001 From: A-pZ Date: Mon, 11 May 2015 10:57:38 +0900 Subject: [PATCH 17/21] =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB?= =?UTF-8?q?=E3=83=89Diarect=E6=9B=B4=E6=96=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * errorclassを追加 --- pom.xml | 233 +++++++++--------- .../thymeleaf/diarect/FieldDialect.java | 1 + .../Struts2FieldErrorAttrProcessor.java | 120 +++++++++ 3 files changed, 240 insertions(+), 114 deletions(-) create mode 100644 src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2FieldErrorAttrProcessor.java diff --git a/pom.xml b/pom.xml index c3ede67..415d0cd 100644 --- a/pom.xml +++ b/pom.xml @@ -1,115 +1,120 @@ - - - 4.0.0 - org.codework - struts2-thymeleaf-plugin - jar - ${struts2.version} - struts2-thymeleaf-plugin - http://www.codework.org/struts2-thymeleaf-plugin - - UTF-8 - 2.3.23 - 2.1.4.RELEASE - 4.1.3.RELEASE - - - - - maven-org-repo - http://repo1.maven.org/maven2/ - - - - - javax.servlet - servlet-api - 2.5 - provided - - - - org.apache.struts - struts2-core - ${struts2.version} - - - - org.thymeleaf - thymeleaf - ${thymeleaf.version} - - - org.thymeleaf - thymeleaf-spring4 - ${thymeleaf.version} - - - org.springframework - spring-context - ${spring.version} - - - org.springframework - spring-web - ${spring.version} - - - org.springframework - spring-webmvc - ${spring.version} - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - true - 256m - 512m - 1.6 - 1.6 - ${project.build.sourceEncoding} - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-idea-plugin - 2.2 - - true - true - 1.6 - 1.6 - - - - + + + 4.0.0 + org.codework + struts2-thymeleaf-plugin + jar + ${struts2.version} + struts2-thymeleaf-plugin + http://www.codework.org/struts2-thymeleaf-plugin + + UTF-8 + 2.3.24-SNAPSHOT + 2.1.4.RELEASE + 4.1.3.RELEASE + + + + + maven-org-repo + http://repo1.maven.org/maven2/ + + + apache.snapshots + ASF Maven 2 Snapshot + https://repository.apache.org/content/groups/snapshots/ + + + + + javax.servlet + servlet-api + 2.5 + provided + + + + org.apache.struts + struts2-core + ${struts2.version} + + + + org.thymeleaf + thymeleaf + ${thymeleaf.version} + + + org.thymeleaf + thymeleaf-spring4 + ${thymeleaf.version} + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + true + 256m + 512m + 1.6 + 1.6 + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-idea-plugin + 2.2 + + true + true + 1.6 + 1.6 + + + + \ No newline at end of file diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java index 9b89f38..da27207 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java @@ -24,6 +24,7 @@ public String getPrefix() { public Set getProcessors() { final Set processors = new HashSet(); processors.add(new FieldAttrProcessor()); + processors.add(new Struts2FieldErrorAttrProcessor()); return processors; } diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2FieldErrorAttrProcessor.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2FieldErrorAttrProcessor.java new file mode 100644 index 0000000..edb35df --- /dev/null +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2FieldErrorAttrProcessor.java @@ -0,0 +1,120 @@ +/** + * + */ +package org.codework.struts.plugins.thymeleaf.diarect; + +import java.util.List; +import java.util.Map; + +import org.thymeleaf.Arguments; +import org.thymeleaf.dom.Element; +import org.thymeleaf.standard.processor.attr.AbstractStandardSingleAttributeModifierAttrProcessor; +import org.thymeleaf.util.StringUtils; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionSupport; + +/** + * IF Struts2-Fielderror raise, append css-class for field. + * + * @author A-pZ + * @Since 2.3.23 + */ +public class Struts2FieldErrorAttrProcessor extends + AbstractStandardSingleAttributeModifierAttrProcessor { + + public static final int ATTR_PRECEDENCE = 1010; + public static final String ATTR_NAME = "errorclass"; + public static final String TARGET_ATTR_NAME = "class"; + + /** + * Default Constructor. + */ + public Struts2FieldErrorAttrProcessor() { + super(ATTR_NAME); + } + + /** + * Target attirbute name to append class. + * + * @see org.thymeleaf.processor.attr.AbstractSingleAttributeModifierAttrProcessor#getTargetAttributeName(org.thymeleaf.Arguments, + * org.thymeleaf.dom.Element, java.lang.String) + */ + @Override + protected String getTargetAttributeName(Arguments arguments, + Element element, String attributeName) { + return TARGET_ATTR_NAME; + } + + /** + * Get attribute value 'errorclass'. + * + * @return errorclass value + */ + protected String getTargetAttributeValue(final Arguments arguments, + final Element element, final String attributeName) { + + Object action = ActionContext.getContext().getActionInvocation() + .getAction(); + // check action instance 'ActionSupport'. + if (!(action instanceof ActionSupport)) { + return BLANK; + } + + ActionSupport asupport = (ActionSupport) action; + Map> fieldErrors = asupport.getFieldErrors(); + if (fieldErrors == null || fieldErrors.size() == 0) { + return BLANK; + } + + final String fieldName = element.getAttributeValue("name"); + if (StringUtils.isEmptyOrWhitespace(fieldName)) { + return BLANK; + } + + List fieldErrorList = fieldErrors.get(fieldName); + if ( fieldErrorList == null || fieldErrorList.size() == 0 ) { + return BLANK; + } + + return super.getTargetAttributeValue(arguments, element, attributeName); + } + + /** + * Attribute write type. APPEND_WITH_SPACE is append attirbute before white + * space. + * + * @see org.thymeleaf.processor.attr.AbstractAttributeModifierAttrProcessor#getModificationType(org.thymeleaf.Arguments, + * org.thymeleaf.dom.Element, java.lang.String, java.lang.String) + */ + @Override + protected ModificationType getModificationType(Arguments arguments, + Element element, String attributeName, String newAttributeName) { + return ModificationType.APPEND_WITH_SPACE; + } + + /** + * Empty attribute behavior. + * + * @see org.thymeleaf.processor.attr.AbstractAttributeModifierAttrProcessor#removeAttributeIfEmpty(org.thymeleaf.Arguments, + * org.thymeleaf.dom.Element, java.lang.String, java.lang.String) + */ + @Override + protected boolean removeAttributeIfEmpty(Arguments arguments, + Element element, String attributeName, String newAttributeName) { + return true; + } + + /** + * Return this processor precedence. + * + * @see org.thymeleaf.processor.AbstractProcessor#getPrecedence() + */ + @Override + public int getPrecedence() { + return ATTR_PRECEDENCE; + } + + private static final String BLANK = ""; + +} From 69a0c827a650e9fdc1404cba619c65e3b933d8ef Mon Sep 17 00:00:00 2001 From: A-pZ Date: Mon, 11 May 2015 19:42:10 +0900 Subject: [PATCH 18/21] Revert "Add FieldErrorClassAttrProcessor" This reverts commit bd3928ead7ffb7dcae43b4191bee4188e0356563. --- .../thymeleaf/diarect/FieldDialect.java | 61 +++++----- .../Struts2ErrorClassAttrProcessor.java | 112 ------------------ 2 files changed, 30 insertions(+), 143 deletions(-) delete mode 100644 src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2ErrorClassAttrProcessor.java diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java index 9bdc0cb..9b89f38 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldDialect.java @@ -1,31 +1,30 @@ -/** - * - */ -package org.codework.struts.plugins.thymeleaf.diarect; - -import java.util.HashSet; -import java.util.Set; - -import org.thymeleaf.dialect.AbstractDialect; -import org.thymeleaf.processor.IProcessor; - -/** - * diarect:sth. - * @author A-pZ - * - */ -public class FieldDialect extends AbstractDialect { - - @Override - public String getPrefix() { - return "sth"; - } - - public Set getProcessors() { - final Set processors = new HashSet(); - processors.add(new FieldAttrProcessor()); - processors.add(new Struts2ErrorClassAttrProcessor()); - return processors; - } - -} +/** + * + */ +package org.codework.struts.plugins.thymeleaf.diarect; + +import java.util.HashSet; +import java.util.Set; + +import org.thymeleaf.dialect.AbstractDialect; +import org.thymeleaf.processor.IProcessor; + +/** + * diarect:sth. + * @author A-pZ + * + */ +public class FieldDialect extends AbstractDialect { + + @Override + public String getPrefix() { + return "sth"; + } + + public Set getProcessors() { + final Set processors = new HashSet(); + processors.add(new FieldAttrProcessor()); + return processors; + } + +} diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2ErrorClassAttrProcessor.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2ErrorClassAttrProcessor.java deleted file mode 100644 index aa1adcc..0000000 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2ErrorClassAttrProcessor.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * - */ -package org.codework.struts.plugins.thymeleaf.diarect; - -import java.util.List; -import java.util.Map; - -import org.thymeleaf.Arguments; -import org.thymeleaf.dom.Element; -import org.thymeleaf.standard.processor.attr.AbstractStandardSingleAttributeModifierAttrProcessor; -import org.thymeleaf.util.StringUtils; - -import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.ActionSupport; - -/** - * Field error css class processor for Struts2-Thymeleaf plugin. - * @author A-pZ - * - */ -public class Struts2ErrorClassAttrProcessor extends - AbstractStandardSingleAttributeModifierAttrProcessor { - - public static final int ATTR_PRECEDENCE = 10100; - public static final String ATTR_NAME = "errorclass"; - public static final String TARGET_ATTR_NAME = "class"; - - /** - * Default Constructor. - */ - public Struts2ErrorClassAttrProcessor() { - super(ATTR_NAME); - } - - /** - * Update to attribute name. - * @see org.thymeleaf.processor.attr.AbstractSingleAttributeModifierAttrProcessor#getTargetAttributeName(org.thymeleaf.Arguments, org.thymeleaf.dom.Element, java.lang.String) - */ - @Override - protected String getTargetAttributeName(Arguments arguments, - Element element, String attributeName) { - return TARGET_ATTR_NAME; - } - - /** - * Attribute update type. APPEND_WITH_SPACE is attribute value append with white-space. - * @see org.thymeleaf.processor.attr.AbstractAttributeModifierAttrProcessor#getModificationType(org.thymeleaf.Arguments, org.thymeleaf.dom.Element, java.lang.String, java.lang.String) - */ - @Override - protected ModificationType getModificationType(Arguments arguments, - Element element, String attributeName, String newAttributeName) { - return ModificationType.APPEND_WITH_SPACE; - } - - /** - * If this method is true , remove attribute. - * @see org.thymeleaf.processor.attr.AbstractAttributeModifierAttrProcessor#removeAttributeIfEmpty(org.thymeleaf.Arguments, org.thymeleaf.dom.Element, java.lang.String, java.lang.String) - */ - @Override - protected boolean removeAttributeIfEmpty(Arguments arguments, - Element element, String attributeName, String newAttributeName) { - return true; - } - - /** - * Attribute write precedence, default value is 1000. - * @see org.thymeleaf.processor.AbstractProcessor#getPrecedence() - */ - @Override - public int getPrecedence() { - return ATTR_PRECEDENCE; - } - - /** - * If has field error, output field error from strus2-field-errors. - */ - @Override - protected String getTargetAttributeValue( - final Arguments arguments, final Element element, final String attributeName) { - - Object actobj = ActionContext.getContext().getActionInvocation().getAction(); - if ( actobj == null ) { - return BLANK; - } - - if (!( actobj instanceof ActionSupport )) { - return BLANK; - } - - ActionSupport action = (ActionSupport)actobj; - if (! action.hasFieldErrors()) { - return BLANK; - } - - final String fieldName = element.getAttributeValue("name"); - if (StringUtils.isEmptyOrWhitespace(fieldName)) { - return BLANK; - } - - Map> fieldErrors = action.getFieldErrors(); - - List targetFieldErrors = fieldErrors.get(fieldName); - if ( targetFieldErrors.isEmpty() || targetFieldErrors.size() == 0 ) { - return BLANK; - } - - return super.getTargetAttributeValue(arguments, element, attributeName); - } - - public static final String BLANK = ""; -} From fac0c6808920ddb7b73df7322bbd1b913226b803 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Tue, 12 May 2015 15:14:42 +0900 Subject: [PATCH 19/21] refactoring, guard block. --- .../thymeleaf/diarect/FieldAttrProcessor.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java index 2ccc584..ea72d24 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/FieldAttrProcessor.java @@ -30,10 +30,7 @@ public FieldAttrProcessor() { protected String getTargetAttributeValue(Arguments arguments, Element element, String attributeName) { String attributeValue = super.getTargetAttributeValue(arguments, element, attributeName); - /* - if (element.hasNormalizedAttribute(Attribute.getPrefixFromAttributeName(attributeName), ATTR_NAME)) { - return attributeValue; - }*/ + String name = element.getAttributeValueFromNormalizedName("name"); String type = element.getAttributeValueFromNormalizedName("type"); return processOverridesValue(name,attributeValue); @@ -50,18 +47,23 @@ protected String processOverridesValue(String name , String value) { ActionContext ctx = ActionContext.getContext(); ValueStack stack = ctx.getValueStack(); Map overrideMap = stack.getExprOverrides(); - if ( overrideMap != null && !overrideMap.isEmpty()) { - if (overrideMap.containsKey(name)) { - String convertionValue = (String)overrideMap.get(name); - // Struts2-Conponent is wrapped String quote, which erase for output value. - String altString = StringEscapeUtils.unescapeJava(convertionValue); - altString = altString.substring(1, altString.length() -1); + if ( overrideMap == null || overrideMap.isEmpty()) { + return value; + } - return altString; - } + if (! overrideMap.containsKey(name)) { + return value; } - return value; + + + String convertionValue = (String)overrideMap.get(name); + + // Struts2-Conponent is wrapped String quote, which erase for output value. + String altString = StringEscapeUtils.unescapeJava(convertionValue); + altString = altString.substring(1, altString.length() -1); + + return altString; } @Override From 8669fa31c8de4ae2ae49b3ba206a8a384c6c518d Mon Sep 17 00:00:00 2001 From: A-pZ Date: Tue, 19 May 2015 15:45:11 +0900 Subject: [PATCH 20/21] change to valid Javadoc. --- pom.xml | 2 +- .../codework/struts/plugins/thymeleaf/StrutsContext.java | 9 +++++---- .../struts/plugins/thymeleaf/ThymeleafResult.java | 2 +- .../struts/plugins/thymeleaf/ThymeleafSpringResult.java | 4 +--- .../diarect/Struts2FieldErrorAttrProcessor.java | 3 +-- .../thymeleaf/spi/DefaultTemplateEngineProvider.java | 4 +--- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 34a63a8..0c1dfda 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ http://www.codework.org/struts2-thymeleaf-plugin UTF-8 - 2.3.24-SNAPSHOT + 2.3.24 2.1.4.RELEASE 4.1.6.RELEASE diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/StrutsContext.java b/src/main/java/org/codework/struts/plugins/thymeleaf/StrutsContext.java index b4e71e5..81a4cb2 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/StrutsContext.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/StrutsContext.java @@ -15,17 +15,18 @@ */ package org.codework.struts.plugins.thymeleaf; -import com.opensymphony.xwork2.LocaleProvider; -import org.thymeleaf.context.WebContext; - import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.thymeleaf.context.WebContext; + +import com.opensymphony.xwork2.LocaleProvider; + /** * Extends the {@link org.thymeleaf.context.WebContext} to provide access to the * Struts action. - *

+ * * For actions that implement the {@link com.opensymphony.xwork2.LocaleProvider} * interface (i.e., actions that extend ActionSupport), the action's locale will * be used in this context. Otherwise, the context will default to the diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafResult.java b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafResult.java index f7c4513..71b537f 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafResult.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafResult.java @@ -41,7 +41,7 @@ public class ThymeleafResult implements Result { /** * The result parameter name to set the name of the template to. - *

+ * * IMPORTANT! Struts2 will look for this field reflectively to determine which * parameter is the default. This allows us to have a simplified result * configuration. Don't remove it! diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java index c4083fe..fc95a03 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/ThymeleafSpringResult.java @@ -42,8 +42,6 @@ * Renders a Thymeleaf-Spring template as the result of invoking a Struts action. * * @author Steven Benitez ( Update A-pZ ) - * @since 2.3.15 - * @version 2.3.20 ( Update A-pZ ) */ public class ThymeleafSpringResult implements Result { private String defaultEncoding = "UTF-8"; @@ -52,7 +50,7 @@ public class ThymeleafSpringResult implements Result { /** * The result parameter name to set the name of the template to. - *

+ * * IMPORTANT! Struts2 will look for this field reflectively to determine * which parameter is the default. This allows us to have a simplified * result configuration. Don't remove it! diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2FieldErrorAttrProcessor.java b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2FieldErrorAttrProcessor.java index edb35df..9b52c93 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2FieldErrorAttrProcessor.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/diarect/Struts2FieldErrorAttrProcessor.java @@ -18,8 +18,7 @@ * IF Struts2-Fielderror raise, append css-class for field. * * @author A-pZ - * @Since 2.3.23 - */ +*/ public class Struts2FieldErrorAttrProcessor extends AbstractStandardSingleAttributeModifierAttrProcessor { diff --git a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java index 754edaf..06e37a6 100644 --- a/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java +++ b/src/main/java/org/codework/struts/plugins/thymeleaf/spi/DefaultTemplateEngineProvider.java @@ -33,8 +33,6 @@ * A default implementation of {@link TemplateEngineProvider}. * * @author Steven Benitez - * @since 2.3.15 - * @version 2.3.20 A-pZ */ public class DefaultTemplateEngineProvider implements TemplateEngineProvider { // HTML5 is the future! @@ -122,7 +120,7 @@ public void setCacheTtlMillis(String cacheTtlMillis) { /** * loading di container configulation from struts-plugin.xml , choise thymeleaf template engine. - * @param container + * @param container Struts2Container */ public void setContainer(Container container) { this.container = container; From 2251332ec3df9eba30413587d9aed318b5d5c504 Mon Sep 17 00:00:00 2001 From: A-pZ Date: Fri, 5 Jun 2015 09:52:56 +0900 Subject: [PATCH 21/21] Update readme.md version 2.3.24 --- README.md | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 576ff8d..65378b6 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,35 @@ The following reflects the default settings. - + +## Version 2.3.24 - Spring support & type conversion handling + +Since version 2.3.24 , this plugin provided accessibility for spring bean , and Struts2 type conversion error handling support. + +### How to use Spring Bean + +* use result type : thymeleaf-spring +* in html template : ${beans.[BeanName]} +* struts.properties : struts.thymeleaf.templateEngineName=spring + +### Hot to use Type conversion support field. + +use this namespace : sth +this diarect supported value and errorclass such as thymeleaf spring support. + +Code example : + + + + ... + + ... + + ## License Copyright 2013 Steven Benitez. @@ -84,4 +111,4 @@ The following reflects the default settings. 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. \ No newline at end of file + limitations under the License.