You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by dcabasson <gi...@git.apache.org> on 2017/06/12 20:27:28 UTC

[GitHub] struts pull request #141: WW-4799 Adding struts.date.format as a conversion ...

GitHub user dcabasson opened a pull request:

    https://github.com/apache/struts/pull/141

    WW-4799 Adding struts.date.format as a conversion format for DateConv…

    …erter

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/dcabasson/struts master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/struts/pull/141.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #141
    
----

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


[GitHub] struts pull request #141: WW-4799 Adding struts.date.format as a conversion ...

Posted by lukaszlenart <gi...@git.apache.org>.
Github user lukaszlenart commented on a diff in the pull request:

    https://github.com/apache/struts/pull/141#discussion_r123429169
  
    --- Diff: core/src/main/java/com/opensymphony/xwork2/conversion/impl/DateConverter.java ---
    @@ -48,7 +51,28 @@ public Object convertValue(Map<String, Object> context, Object target, Member me
                     }
                 } else if (java.util.Date.class == toType) {
                     Date check;
    -                DateFormat[] dfs = getDateFormats(locale);
    +
    +
    +                // Add the user provided date format if any
    +                final TextProvider tp = findProviderInStack((ValueStack) context.get(ActionContext.VALUE_STACK));
    +                SimpleDateFormat globalDateFormat = null;
    +
    +                if (tp != null) {
    +                    String globalFormat = tp.getText(org.apache.struts2.components.Date.DATETAG_PROPERTY);
    +
    +                    // if tp.getText can not find the property then the
    +                    // returned string is the same as input =
    +                    // DATETAG_PROPERTY
    +                    if (globalFormat != null
    +                        && !org.apache.struts2.components.Date.DATETAG_PROPERTY.equals(globalFormat)) {
    +                        globalDateFormat = new SimpleDateFormat(globalFormat, locale);
    +                    }
    +                }
    --- End diff --
    
    Could you move this whole section into `getDateFormats` to avoid passing the `globalDateFormat` as a parameter? Also it would be good to extract this logic into a protected method to allow override, so the finally it should look like this:
    
    ```java
         DateFormat[] dfs = getDateFormats(globalDateFormat, locale);
    
    ...
    
    private DateFormat[] getDateFormats(Locale locale) {
        ...
        DateFormat globalDateFormat = getGlobalDateFormat();
        ...
    }
    
    protected getGlobalDateFormat() {
         // your code here
    }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org