Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-3833

Repopulating Field upon conversion Error does not work when doing localization

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.3, 2.3.4
    • 2.3.7
    • None
    • 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);
      
              }
          }
      

      Attachments

        1. struts-test.zip
          48 kB
          J. Garcia

        Activity

          People

            lukaszlenart Lukasz Lenart
            jogaco J. Garcia
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: