You need to sign in to do that
Don't have an account?
<apex:outputfield> like formatting in APEX
I'm passing back some field values via SOAP to a mobile client.
I'd like to pass these back as formatted text to make life easier for the mobile developer. So, a currency field would be correctly formatted as currency, a number field with commas etc.
In VisualForce, I can get great default formatting via the apex:outputfield. If I try to do the conversion to a string in APEX via string.valueOf, I get a pretty crude string (e.g. for numbers I get an exponential representation).
Is there any way I can access the VisualForce like formatting used in Apex:OutputField from within APEX?
thanks!
Aiden
Unfortunately the mechanism that should lend itself to this - String.format(), doesn't work in this way. There's a blog post exploring this at:
http://www.tgerm.com/2011/01/message-format-string-format-apex.html
All Answers
Not that I am aware of. I see where you are going with this. But I doubt if it's a good idea to get the formatted text produced by outputField since it might include some custom JavaScript and references to styles that may not work if you blindly embed the snippet on the mobile UI.
Agreed, I mentioned outputField as there is code somewhere in Salesforce.COM that does great default formatting for an sObject field to text that then may have additional javascript attribution applied to it. So, I'm not trying to get access to OutputField from within APEX, rather to the same logic that lets OutputField build a nicely formatted string.
Unfortunately the mechanism that should lend itself to this - String.format(), doesn't work in this way. There's a blog post exploring this at:
http://www.tgerm.com/2011/01/message-format-string-format-apex.html
Ok, thanks all