Grails

Implement mechanism for custom (i.e. URL) encodings of model data

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.3
  • Fix Version/s: 0.4
  • Component/s: Commons
  • Labels:
    None

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

Activity

Hide
Marc Palmer added a comment -

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)}"/>
Show
Marc Palmer added a comment - 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)}"/>
Hide
Marc Palmer added a comment -

Common encodings could include:

URL
HTML Escaping
XML Escaping
JavaScript Escaping
Localisation of dates and numbers
Base64
UUEncoding

Show
Marc Palmer added a comment - Common encodings could include: URL HTML Escaping XML Escaping JavaScript Escaping Localisation of dates and numbers Base64 UUEncoding
Hide
Marc Palmer added a comment -

Not forgetting:

MD5Digest
SHA-1Digest

Show
Marc Palmer added a comment - Not forgetting: MD5Digest SHA-1Digest

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: