URL generation wierd in Playframework

30 views
Skip to first unread message

CP

unread,
Feb 1, 2011, 1:43:34 PM2/1/11
to play-framework
Hi,

I am facing a wierd issue regarding in URL generation in
Playframework.

Here is my code snippet in template:

> @{Rooms.list(customerId?:customerId, location?:location, roomId?:roomId)}

Obviousely I wanna to generate a the URL like this:

> /rooms/list?customer=1&location=asdf&roomId=1

But finally I got this:

> /rooms/list?customer=1&location=asdf&roomId=1

I traced down the play source code and found this in "GroovyTemplate":

> if (template.template.name.endsWith(".html") || template.template.name.endsWith(".xml")) {
> def.url = def.url.replace("&", "&");
> }

Could anybody tell what's the purpose of this replacement? How can I
get my URL correctly?

Thanks

Steve Chaloner

unread,
Feb 1, 2011, 2:56:18 PM2/1/11
to play-framework
How are you viewing the output - in a browser, or in a log, or as an
email, or...? When rendered as HTML output, they should be decoded
correctly to &.

- Steve

CP

unread,
Feb 9, 2011, 1:58:35 AM2/9/11
to play-framework
Hi Steve,

I used in HTML to render a <a/> tag. And I thought that should be the
most case to call this @{} tag. So I used @{} tag everywhere to adpet
to route configuration automatically and make my code consistent. To
escape the generated URL, I will have to replace the simple @{} to
piece of groovy code by calling Router.reverse(valabala).... Is there
any simple way in @{} routine?

Thanks

CP

unread,
Feb 17, 2011, 3:29:16 AM2/17/11
to play-framework
Solved by using @{Rooms.list().add("customerId",
customerId).add("location", location).add("roomId", roomId)}.

http://stackoverflow.com/questions/4866521/url-generation-wierd-in-playframework

Guillaume Bort

unread,
Feb 25, 2011, 1:29:27 PM2/25/11
to play-fr...@googlegroups.com
In the latest trunk version you can also write it as:

@{Rooms.list(customerId:customerId, location:location, roomId,roomId)}

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> 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.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com

Marc van Kempen

unread,
Feb 25, 2011, 6:07:15 PM2/25/11
to play-framework

Hi

I also ran into this issue the other day and was highly surprised. Is
this the expected behaviour of @{}? If so what is the rationale?

Marc

On Feb 25, 7:29 pm, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> In the latest trunk version you can also write it as:
>
> @{Rooms.list(customerId:customerId, location:location, roomId,roomId)}
>
>
>
>
>
> On Thu, Feb 17, 2011 at 9:29 AM, CP <true...@gmail.com> wrote:
> > Solved by using @{Rooms.list().add("customerId",
> > customerId).add("location", location).add("roomId", roomId)}.
>
> >http://stackoverflow.com/questions/4866521/url-generation-wierd-in-pl...
> Guillaume Bort,http://guillaume.bort.fr
>
> For anything work-related, use g...@zenexity.fr; for everything else,
> write guillaume.b...@gmail.com

Guillaume Bort

unread,
Feb 26, 2011, 2:35:28 PM2/26/11
to play-fr...@googlegroups.com
Well it is required to have &amp; instead of simple & for XHTML, but I
think we should remove it for html template since Play now promotes
usage of HTML5.

> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,

write guillau...@gmail.com

sas

unread,
Feb 26, 2011, 2:39:46 PM2/26/11
to play-framework
and in current play, I you can try with

@{Rooms.list().add("customerId", customerId).add("location",
location).add("roomId", roomId)}

The new syntax it's very nice... it would also be very useful to be
able to pass a map, for example, supossing I have a map with ( "page" -
> 2, "pageLen" -> 10, "order" -> name)

Map<String, String> params = newHashMap<String, String>();

params.put("page", "2");
params.put("pageLen", "10");
params.put("order", "roomId");

doing

@{Rooms.list().add(params)}

or

@{Rooms.list(_params:params)}

to get

/rooms/list?page=2&pageLen=10f&order=roomId

saludos

sas

ps: welcome back, guillaume


In the latest trunk version you can also write it as:
@{Rooms.list(customerId:customerId, location:location,
roomId,roomId)}

On 25 feb, 15:29, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> In the latest trunk version you can also write it as:
>
> @{Rooms.list(customerId:customerId, location:location, roomId,roomId)}
>
>
>
>
>
>
>
>
>
> On Thu, Feb 17, 2011 at 9:29 AM, CP <true...@gmail.com> wrote:
> > Solved by using @{Rooms.list().add("customerId",
> > customerId).add("location", location).add("roomId", roomId)}.
>
> >http://stackoverflow.com/questions/4866521/url-generation-wierd-in-pl...
> > For more options, visit this group athttp://groups.google.com/group/play-framework?hl=en.
>
> --
> Guillaume Bort,http://guillaume.bort.fr
>
> For anything work-related, use g...@zenexity.fr; for everything else,
> write guillaume.b...@gmail.com

Marc van Kempen

unread,
Feb 28, 2011, 1:07:48 AM2/28/11
to play-framework

Hi,

If I understand correctly then should the result not depend on the
kind of html you are generating?
I.e. &amp; for xhtml and & for html(5). I'm just not sure if play
knows about the HTML you're generating.

If you need to set it manually it could be a directive per template,
or a global setting. But maybe parsing the doctype is not that
difficult?

Cheers
Marc.

On Feb 26, 8:35 pm, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> Well it is required to have &amp; instead of simple & for XHTML, but I
> think we should remove it for html template since Play now promotes
> usage of HTML5.
>
Reply all
Reply to author
Forward
0 new messages