title: How to submit locale-aware values in Struts 2
body: <p>I wish to enter a double via a Struts 2 textfield, but respecting the current locale. Example: for "en" it would be entered as "3.4" (using a point), in "de" it would be entered as "3,4" (using a comma).</p>
  
  <p>In my app, the locale is set via the request_locale parameter e.g.:</p>
  
  <pre><code>&lt;s:url id="localeDE" namespace="/" action="locale" &gt;
  &lt;s:param name="request_locale" &gt;de&lt;/s:param&gt;
  &lt;/s:url&gt;
  </code></pre>
  
  <p>and the number format "format.number" is defined in the en and de properties file as </p>
  
  <pre><code>format.number ={0,number,#0.0##}
  </code></pre>
  
  <p>But I cannot get it to work. I've tried using the following to input the number:</p>
  
  <pre><code>&lt;s:textfield key="global.amount" name="%{getFormatted('format.number','myValue')}" /&gt;
  </code></pre>
  
  <p>This doesn't work - the submit doesn't fail, but the value is not assigned to the target action (it remains the default 0,0), and the warning "Parameters: Invalid chunk ignored" is written to the logs.</p>
  
  <p>I've also tried this:</p>
  
  <pre><code>&lt;s:textfield key="global.amount" name="%{getText('format.number',{myValue})}" /&gt;
  </code></pre>
  
  <p>This doesn't work - the submit doesn't fail, but the value is not assigned to the target action (it remains the default 0,0), and the warning "Parameters: Invalid chunk ignored" is written to the logs.</p>
  
  <p>And tried this:</p>
  
  <pre><code>&lt;s:textfield key="global.amount" name="myValue" /&gt;
  </code></pre>
  
  <p>The submit fails, the input page is re-displayed, and the following is written to the browser (of course because 3.4 is expected, not 3,4): </p>
  
  <pre><code>Invalid field value for field "myValue"
  The following is written to the logs:
  Apr 03, 2015 9:58:18 AM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
  Avertissement: Error setting expression 'myValue' with value '[Ljava.lang.String;@8a9396'
  ognl.MethodFailedException: Method "setMyValue" failed for object com.planet.user.action.FinanceData@326ce2 [java.lang.NoSuchMethodException: com.planet.user.action.FinanceData.setMyValue([Ljava.lang.String;)]
      at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1285)
      at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1474)
  </code></pre>
  
  <p><em>Displaying</em> a value in the current locale is easy, using:</p>
  
  <pre><code>&lt;s:textfield key="global.amount" value="%{getText('format.number',{myValue})}" /&gt;
  </code></pre>
  
  <p>But how can we allow the value to be <em>submitted</em> locale-aware?</p>
  
  <p>I couldn't find any example/thread regarding this. The only hint I found was the following in the struts doc: 
  "... type conversion is locale aware. The solution is to again use the message formats as defined above, by using the getText Method of ActionSupport"</p>
  
  <p>(see <a href="https://struts.apache.org/docs/formatting-dates-and-numbers.html" rel="nofollow">formatting-dates-and-numbers</a> )</p>
  
  <p>This suggests that locale-aware submission is possible out-of-the-box with Struts, but how? Any help much appreciated ...</p>