Details
Description
We need a generic scheme for providing alternative representations of model data, or their properties.
For example in a page we may need to render data in various forms:
- URL Encoded
- HTML Escaped
- Localized (to the client browser's locale)
The solution should cater for any range of user-registerable encoding handlers. We do not know all the encodings that may exist
For discussion see: http://grails.org/Property+Encodings+Proposal
One possible solution is for us to add generic dynamic methods on Object:
Object encode(String encoding)
Object encode(String encoding, Object params)
In partnership with a convention or mechanism for an EncodingRegistry taking encoder obects with encode(Object value, Object params), we could then name encodings and use them with any object:
Your name is: ${user.name.encode('HTML')}<br/> <input name="userName" value="${user.name.encode('URL')}"/><br/> <input name="userDOB" value="${user.dateOfBirth.encode('Localized', locale)}"/>