Struts 2
  1. Struts 2
  2. WW-3833

Repopulating Field upon conversion Error does not work when doing localization

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.3, 2.3.4
    • Fix Version/s: 2.3.7
    • Component/s: None
    • Labels:
      None

      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:

      <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);
      
              }
          }
      

        Activity

        Hide
        J. Garcia added a comment -

        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.

        Show
        J. Garcia added a comment - 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.
        Hide
        J. Garcia added a comment -

        Attachment for WWW-3833

        Show
        J. Garcia added a comment - Attachment for WWW-3833
        Hide
        Lukasz Lenart added a comment -

        New method getFormatted implemented, docs updated. Thanks for pointing this out.

        Show
        Lukasz Lenart added a comment - New method getFormatted implemented, docs updated. Thanks for pointing this out.
        Hide
        Hudson added a comment -

        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
        Show
        Hudson added a comment - 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

          People

          • Assignee:
            Lukasz Lenart
            Reporter:
            J. Garcia
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development