aliases for form object and fields

82 views
Skip to first unread message

tazmaniac

unread,
Nov 11, 2011, 4:18:35 PM11/11/11
to play-fr...@googlegroups.com
Hello, I'm using the @valid annotation on my controller method for a JPA entity model to automatically bind and validate the form parameters. This relies on the name of the parameter matching what is on the form and likewise the parameter names have to match the object field names. This means my internal names are exposed to the public domain. What if I want to mask or shorten those names. Is there a mechanism to assign aliases to the entity variable name and it's field names such that the names using in the form are not the same as the ones I use inside my code? The alias mapping would be applied as the form is rendered and then mapped back during the request handling. Does this exist?

thanks

jbtbnl

unread,
Nov 11, 2011, 4:59:07 PM11/11/11
to play-fr...@googlegroups.com
Maybe you'd like to explain why you think it's important to hide/change the internal names for the public domain?

tazmaniac

unread,
Nov 11, 2011, 5:13:09 PM11/11/11
to play-fr...@googlegroups.com
the main reason is to shorten the names. I like verbose names in code but the form in question is submitted using a GET so the request ends up being quite long. I would like to create 2-3 character long aliases so the request URL is shortened but the verbose code names remain as they are.

tazmaniac

unread,
Nov 11, 2011, 5:21:30 PM11/11/11
to play-fr...@googlegroups.com
jbtnl, was your question enquiring about the orientation of my moral compass?

jbtbnl

unread,
Nov 11, 2011, 5:51:55 PM11/11/11
to play-fr...@googlegroups.com
Tazmaniac, it's common practice to create CRUD applications with play.
Saving or updating data by means of a GET request goes against that, you should use a POST request instead.

If you are not saving or updating data then it doesn't make sense to bind the request parameters to a model.

Chris Webb

unread,
Nov 11, 2011, 6:13:55 PM11/11/11
to play-fr...@googlegroups.com
jbtbnl, I take your point regarding the use of GET and POST but I'm implementing a search function and not standard CRUD. I was binding the submitted search query to a JPA model to save the search query. Possibly a slight bending of the rules but if it's good enough for Google... :)

In any case this is getting a bit away from the original question and perhaps I muddied the waters by specifying the parameter was a JPA entity. Assuming that the controller parameter is just a plain POJO which will be the result of the form submit, the same issue of internal POJO variable and field names exposed as is still exists.


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/iTTlbUTNc_4J.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


jbtbnl

unread,
Nov 12, 2011, 5:45:02 AM11/12/11
to play-fr...@googlegroups.com
tazmaniac, in that case you'd be using the routes file to create a clean url, for example:

GET /search/{query} Application.search
Reply all
Reply to author
Forward
0 new messages