You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "J. Garcia (JIRA)" <ji...@apache.org> on 2012/06/01 12:45:22 UTC

[jira] [Created] (WW-3833) Repopulating Field upon conversion Error does not work when doing localization

J. Garcia created WW-3833:
-----------------------------

             Summary: Repopulating Field upon conversion Error does not work when doing localization
                 Key: WW-3833
                 URL: https://issues.apache.org/jira/browse/WW-3833
             Project: Struts 2
          Issue Type: Bug
    Affects Versions: 2.3.4, 2.3.3
            Reporter: J. Garcia
             Fix For: 2.3.5


In the documentation, there is a way to repopulate a field with the original user input when there is a conversion error:

http://struts.apache.org/2.3.3/docs/conversion-validator.html

However, this does not work if you try to apply l10n to user input: integers, dates, real numbers.

Current workaround:

In jsp:

<s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />


In BaseAction:

    public String getFormatted(String key, String expr) {

        Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();
        if (conversionErrors.containsKey(expr)) {
            String[] vals = (String[]) conversionErrors.get(expr);
            return vals[0];
        } else {
            final ValueStack valueStack = ActionContext.getContext().getValueStack();
            final Object val = valueStack.findValue(expr);
            List<Object> valList = new ArrayList<Object>();
            valList.add(val);
            return getText(key, valList);

        }
    }



--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (WW-3833) Repopulating Field upon conversion Error does not work when doing localization

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3833?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart updated WW-3833:
------------------------------

    Description: 
In the documentation, there is a way to repopulate a field with the original user input when there is a conversion error:

http://struts.apache.org/2.3.3/docs/conversion-validator.html

However, this does not work if you try to apply l10n to user input: integers, dates, real numbers.

Current workaround:

In jsp:

{code:xml}
<s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />
{code}

In BaseAction:

{code:java}
    public String getFormatted(String key, String expr) {

        Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();
        if (conversionErrors.containsKey(expr)) {
            String[] vals = (String[]) conversionErrors.get(expr);
            return vals[0];
        } else {
            final ValueStack valueStack = ActionContext.getContext().getValueStack();
            final Object val = valueStack.findValue(expr);
            List<Object> valList = new ArrayList<Object>();
            valList.add(val);
            return getText(key, valList);

        }
    }
{code}

  was:
In the documentation, there is a way to repopulate a field with the original user input when there is a conversion error:

http://struts.apache.org/2.3.3/docs/conversion-validator.html

However, this does not work if you try to apply l10n to user input: integers, dates, real numbers.

Current workaround:

In jsp:

<s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />


In BaseAction:

    public String getFormatted(String key, String expr) {

        Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();
        if (conversionErrors.containsKey(expr)) {
            String[] vals = (String[]) conversionErrors.get(expr);
            return vals[0];
        } else {
            final ValueStack valueStack = ActionContext.getContext().getValueStack();
            final Object val = valueStack.findValue(expr);
            List<Object> valList = new ArrayList<Object>();
            valList.add(val);
            return getText(key, valList);

        }
    }



    
> Repopulating Field upon conversion Error does not work when doing localization
> ------------------------------------------------------------------------------
>
>                 Key: WW-3833
>                 URL: https://issues.apache.org/jira/browse/WW-3833
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.3.3, 2.3.4
>            Reporter: J. Garcia
>             Fix For: 2.3.5
>
>         Attachments: struts-test.zip, struts-test_5.zip
>
>
> In the documentation, there is a way to repopulate a field with the original user input when there is a conversion error:
> http://struts.apache.org/2.3.3/docs/conversion-validator.html
> However, this does not work if you try to apply l10n to user input: integers, dates, real numbers.
> Current workaround:
> In jsp:
> {code:xml}
> <s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />
> {code}
> In BaseAction:
> {code:java}
>     public String getFormatted(String key, String expr) {
>         Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();
>         if (conversionErrors.containsKey(expr)) {
>             String[] vals = (String[]) conversionErrors.get(expr);
>             return vals[0];
>         } else {
>             final ValueStack valueStack = ActionContext.getContext().getValueStack();
>             final Object val = valueStack.findValue(expr);
>             List<Object> valList = new ArrayList<Object>();
>             valList.add(val);
>             return getText(key, valList);
>         }
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (WW-3833) Repopulating Field upon conversion Error does not work when doing localization

Posted by "J. Garcia (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3833?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

J. Garcia updated WW-3833:
--------------------------

    Attachment:     (was: struts-test_5.zip)
    
> Repopulating Field upon conversion Error does not work when doing localization
> ------------------------------------------------------------------------------
>
>                 Key: WW-3833
>                 URL: https://issues.apache.org/jira/browse/WW-3833
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.3.3, 2.3.4
>            Reporter: J. Garcia
>             Fix For: 2.3.5
>
>         Attachments: struts-test.zip
>
>
> In the documentation, there is a way to repopulate a field with the original user input when there is a conversion error:
> http://struts.apache.org/2.3.3/docs/conversion-validator.html
> However, this does not work if you try to apply l10n to user input: integers, dates, real numbers.
> Current workaround:
> In jsp:
> {code:xml}
> <s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />
> {code}
> In BaseAction:
> {code:java}
>     public String getFormatted(String key, String expr) {
>         Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();
>         if (conversionErrors.containsKey(expr)) {
>             String[] vals = (String[]) conversionErrors.get(expr);
>             return vals[0];
>         } else {
>             final ValueStack valueStack = ActionContext.getContext().getValueStack();
>             final Object val = valueStack.findValue(expr);
>             List<Object> valList = new ArrayList<Object>();
>             valList.add(val);
>             return getText(key, valList);
>         }
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (WW-3833) Repopulating Field upon conversion Error does not work when doing localization

Posted by "Lukasz Lenart (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3833?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart resolved WW-3833.
-------------------------------

    Resolution: Fixed
      Assignee: Lukasz Lenart

New method getFormatted implemented, docs updated. Thanks for pointing this out.
                
> Repopulating Field upon conversion Error does not work when doing localization
> ------------------------------------------------------------------------------
>
>                 Key: WW-3833
>                 URL: https://issues.apache.org/jira/browse/WW-3833
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.3.3, 2.3.4
>            Reporter: J. Garcia
>            Assignee: Lukasz Lenart
>             Fix For: 2.3.5
>
>         Attachments: struts-test.zip
>
>
> In the documentation, there is a way to repopulate a field with the original user input when there is a conversion error:
> http://struts.apache.org/2.3.3/docs/conversion-validator.html
> However, this does not work if you try to apply l10n to user input: integers, dates, real numbers.
> Current workaround:
> In jsp:
> {code:xml}
> <s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />
> {code}
> In BaseAction:
> {code:java}
>     public String getFormatted(String key, String expr) {
>         Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();
>         if (conversionErrors.containsKey(expr)) {
>             String[] vals = (String[]) conversionErrors.get(expr);
>             return vals[0];
>         } else {
>             final ValueStack valueStack = ActionContext.getContext().getValueStack();
>             final Object val = valueStack.findValue(expr);
>             List<Object> valList = new ArrayList<Object>();
>             valList.add(val);
>             return getText(key, valList);
>         }
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (WW-3833) Repopulating Field upon conversion Error does not work when doing localization

Posted by "Hudson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WW-3833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13419873#comment-13419873 ] 

Hudson commented on WW-3833:
----------------------------

Integrated in Struts2 #505 (See [https://builds.apache.org/job/Struts2/505/])
    WW-3833 adds new getFormatted method to support localization and conversion errors (Revision 1364110)

     Result = FAILURE
lukaszlenart : 
Files : 
* /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ActionSupport.java
* /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/ActionSupportTest.java
* /struts/struts2/trunk/xwork-core/src/test/resources/com/opensymphony/xwork2/ActionSupportTest$MyActionSupport_da.properties

                
> Repopulating Field upon conversion Error does not work when doing localization
> ------------------------------------------------------------------------------
>
>                 Key: WW-3833
>                 URL: https://issues.apache.org/jira/browse/WW-3833
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.3.3, 2.3.4
>            Reporter: J. Garcia
>            Assignee: Lukasz Lenart
>             Fix For: 2.3.5
>
>         Attachments: struts-test.zip
>
>
> In the documentation, there is a way to repopulate a field with the original user input when there is a conversion error:
> http://struts.apache.org/2.3.3/docs/conversion-validator.html
> However, this does not work if you try to apply l10n to user input: integers, dates, real numbers.
> Current workaround:
> In jsp:
> {code:xml}
> <s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />
> {code}
> In BaseAction:
> {code:java}
>     public String getFormatted(String key, String expr) {
>         Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();
>         if (conversionErrors.containsKey(expr)) {
>             String[] vals = (String[]) conversionErrors.get(expr);
>             return vals[0];
>         } else {
>             final ValueStack valueStack = ActionContext.getContext().getValueStack();
>             final Object val = valueStack.findValue(expr);
>             List<Object> valList = new ArrayList<Object>();
>             valList.add(val);
>             return getText(key, valList);
>         }
>     }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (WW-3833) Repopulating Field upon conversion Error does not work when doing localization

Posted by "J. Garcia (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3833?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

J. Garcia updated WW-3833:
--------------------------

    Attachment: struts-test.zip

Attachment for WWW-3833
                
> Repopulating Field upon conversion Error does not work when doing localization
> ------------------------------------------------------------------------------
>
>                 Key: WW-3833
>                 URL: https://issues.apache.org/jira/browse/WW-3833
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.3.3, 2.3.4
>            Reporter: J. Garcia
>             Fix For: 2.3.5
>
>         Attachments: struts-test.zip, struts-test_5.zip
>
>
> In the documentation, there is a way to repopulate a field with the original user input when there is a conversion error:
> http://struts.apache.org/2.3.3/docs/conversion-validator.html
> However, this does not work if you try to apply l10n to user input: integers, dates, real numbers.
> Current workaround:
> In jsp:
> <s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />
> In BaseAction:
>     public String getFormatted(String key, String expr) {
>         Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();
>         if (conversionErrors.containsKey(expr)) {
>             String[] vals = (String[]) conversionErrors.get(expr);
>             return vals[0];
>         } else {
>             final ValueStack valueStack = ActionContext.getContext().getValueStack();
>             final Object val = valueStack.findValue(expr);
>             List<Object> valList = new ArrayList<Object>();
>             valList.add(val);
>             return getText(key, valList);
>         }
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (WW-3833) Repopulating Field upon conversion Error does not work when doing localization

Posted by "J. Garcia (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3833?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

J. Garcia updated WW-3833:
--------------------------

    Attachment: struts-test.zip
    
> Repopulating Field upon conversion Error does not work when doing localization
> ------------------------------------------------------------------------------
>
>                 Key: WW-3833
>                 URL: https://issues.apache.org/jira/browse/WW-3833
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.3.3, 2.3.4
>            Reporter: J. Garcia
>             Fix For: 2.3.5
>
>         Attachments: struts-test.zip
>
>
> In the documentation, there is a way to repopulate a field with the original user input when there is a conversion error:
> http://struts.apache.org/2.3.3/docs/conversion-validator.html
> However, this does not work if you try to apply l10n to user input: integers, dates, real numbers.
> Current workaround:
> In jsp:
> <s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />
> In BaseAction:
>     public String getFormatted(String key, String expr) {
>         Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();
>         if (conversionErrors.containsKey(expr)) {
>             String[] vals = (String[]) conversionErrors.get(expr);
>             return vals[0];
>         } else {
>             final ValueStack valueStack = ActionContext.getContext().getValueStack();
>             final Object val = valueStack.findValue(expr);
>             List<Object> valList = new ArrayList<Object>();
>             valList.add(val);
>             return getText(key, valList);
>         }
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (WW-3833) Repopulating Field upon conversion Error does not work when doing localization

Posted by "J. Garcia (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3833?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

J. Garcia updated WW-3833:
--------------------------

    Attachment:     (was: struts-test.zip)
    
> Repopulating Field upon conversion Error does not work when doing localization
> ------------------------------------------------------------------------------
>
>                 Key: WW-3833
>                 URL: https://issues.apache.org/jira/browse/WW-3833
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.3.3, 2.3.4
>            Reporter: J. Garcia
>             Fix For: 2.3.5
>
>         Attachments: struts-test_5.zip
>
>
> In the documentation, there is a way to repopulate a field with the original user input when there is a conversion error:
> http://struts.apache.org/2.3.3/docs/conversion-validator.html
> However, this does not work if you try to apply l10n to user input: integers, dates, real numbers.
> Current workaround:
> In jsp:
> <s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />
> In BaseAction:
>     public String getFormatted(String key, String expr) {
>         Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();
>         if (conversionErrors.containsKey(expr)) {
>             String[] vals = (String[]) conversionErrors.get(expr);
>             return vals[0];
>         } else {
>             final ValueStack valueStack = ActionContext.getContext().getValueStack();
>             final Object val = valueStack.findValue(expr);
>             List<Object> valList = new ArrayList<Object>();
>             valList.add(val);
>             return getText(key, valList);
>         }
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (WW-3833) Repopulating Field upon conversion Error does not work when doing localization

Posted by "J. Garcia (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WW-3833?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

J. Garcia updated WW-3833:
--------------------------

    Attachment: struts-test_5.zip

run with mvn jetty:run. I use maven 2.2.1.
- on browser, type: localhost:8080/struts-test/example/Login
- you'll see a form, with formatted integer.
- modify the integer like this: AAA
- submit. An error msg informing of conversion error is shown. However, the value AAA is not maintained. Instead, the current bean value is shown.

The attached example uses the described workaround. Comment-out to reproduce the bug.
                
> Repopulating Field upon conversion Error does not work when doing localization
> ------------------------------------------------------------------------------
>
>                 Key: WW-3833
>                 URL: https://issues.apache.org/jira/browse/WW-3833
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.3.3, 2.3.4
>            Reporter: J. Garcia
>             Fix For: 2.3.5
>
>         Attachments: struts-test.zip, struts-test_5.zip
>
>
> In the documentation, there is a way to repopulate a field with the original user input when there is a conversion error:
> http://struts.apache.org/2.3.3/docs/conversion-validator.html
> However, this does not work if you try to apply l10n to user input: integers, dates, real numbers.
> Current workaround:
> In jsp:
> <s:textfield key="user.born" value="%{getFormatted('format.number','user.born')}" />
> In BaseAction:
>     public String getFormatted(String key, String expr) {
>         Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();
>         if (conversionErrors.containsKey(expr)) {
>             String[] vals = (String[]) conversionErrors.get(expr);
>             return vals[0];
>         } else {
>             final ValueStack valueStack = ActionContext.getContext().getValueStack();
>             final Object val = valueStack.findValue(expr);
>             List<Object> valList = new ArrayList<Object>();
>             valList.add(val);
>             return getText(key, valList);
>         }
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira