title: How can I change the way GRAILS GSP fieldValue formats Integers?
body: <p>I have a field in my domain object which I define as an Integer...</p>
  
  <pre><code>Integer minPrice
  </code></pre>
  
  <p>I then access it in a GSP page as follows:</p>
  
  <pre><code>${fieldValue(bean: myBean, field: 'minPrice')}
  </code></pre>
  
  <p>and what I get in my HTML is...</p>
  
  <pre><code>100,000
  </code></pre>
  
  <p>which is not an Integer, it's a String.  Worse still it's a formatted String in a particular locale.</p>
  
  <p>This is a problem because I have a SELECT control on an HTML FORM which has a (non-ordinal) range of values for minPrice which I want to store in my domain object as integers, and I don't want to store an index to some array of values that I have to repeatedly map back and forth between, I want the value itself.</p>
  
  <p>My select control looks like this...</p>
  
  <pre><code>&lt;g:select name="minPrice" 
  value="${fieldValue(bean: personInstance, field: 'minPrice')}"  
  onchange="setDirty()"
  noSelection='${['0':'Select a number...']}'
  from="${[
      ['name':'100,000', 'id':100000],
      ['name':'200,000', 'id':200000],
      ['name':'300,000', 'id':300000]
      ]}"
  optionKey="id" optionValue="name"
  /&gt;
  </code></pre>
  
  <p>When I get the value from the SELECT field to post back to the server it correctly has an Integer value, which I persist.  However the return trip never pre-selects the right row in the drop-down because the value is this comma separated String.</p>
  
  <p>This works fine elsewhere in my code for small numbers where the comma formatting doesn't come into play, and the round-trip in and out of the SELECT is successful.  But values >999 don't work.</p>
  
  <p>The docs say <em>"This tag will inspect a bean which has been the subject of data binding and obtain the value of the field either from the originally submitted value contained within the bean's errors object populating during data binding or from the value of a bean's property. Once the value is obtained it will be automatically HTML encoded."</em></p>
  
  <p>It's that last bit that I want to avoid as it appears to format Integers.  So, what little bit of Grails/GSP magic do I need to know so I can get my Integer to be rendered as an integer into my SELECT and pre-select the right row?</p>
  
  <p><strong>EDIT:</strong>
  I have tried some further things based on the answers below, with pretty disappointing results so far...</p>
  
  <p>If I put the <code>&lt;gformatNumber/&gt;</code> tag in my <code>&lt;g:select/&gt;</code> I get the page code as text in the browser.</p>
  
  <pre><code>&lt;g:select name="minPrice" 
  value='&lt;g:formatNumber number="${fieldValue(bean: personInstance, field: 'minPrice')}" format="#" /&gt;'
  onchange="setDirty()"
  noSelection='${['0':'Select a number...']}'
  from="${[
  ['name':'100,000', 'id':100000],
  ['name':'200,000', 'id':200000],
  ['name':'300,000', 'id':300000],
  ]}"
  optionKey="id" optionValue="name"
  /&gt;
  </code></pre>
  
  <p>Using the number format tag from GSP on my Integer value of 100000 like this...</p>
  
  <pre><code>var x = &lt;g:formatNumber number="${fieldValue(bean: personInstance, field: 'minPrice')}" format="#" /&gt;;
  </code></pre>
  
  <p>gives <code>100</code>.  Remember that the <code>fieldValue</code> gives back <code>100,000</code>, so this is not a surprise.</p>
  
  <p>If I use the jsp taglib like this...</p>
  
  <pre><code>&lt;%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %&gt;
  var y = &lt;fmt:formatNumber value="${fieldValue(bean: personInstance, field: 'minPrice')}" pattern=".00"/&gt;;
  </code></pre>
  
  <p>I get an error from the page compiler <code>Cannot format given Object as a Number</code>.</p>
  
  <p>I guess I have a wider concern than I can't seem to get an Integer value as a genuine integer into my code if it is greater than 999 because of the default (and unconfigurable) behaviour of the fieldValue directive.  However my specific problem of not being able to pre-select an Integer value in a SELECT control is not going away.  At the moment I'm at a bit of a loss.</p>
  
  <p>Anyone have any further ideas?</p>