Re: [play-framework] Parameters with default values in routes with ?=

486 views
Skip to first unread message

Julien Richard-Foy

unread,
Dec 20, 2012, 10:37:27 AM12/20/12
to play-fr...@googlegroups.com
The routes file is compiled separately by Play and uses a custom
syntax. The expression at the right of the “?=” sign must be a valid
Scala expression, though.

Matthew Neeley

unread,
Dec 20, 2012, 12:12:54 PM12/20/12
to play-fr...@googlegroups.com
Is there any reason why ?= was chosen over = which would be consistent
with proper scala code? It would seem that this question (and I'm
sure it will be asked again) could be avoided by reusing the scala
syntax.
> --
>
>

Julien Richard-Foy

unread,
Dec 20, 2012, 12:17:23 PM12/20/12
to play-fr...@googlegroups.com
= is used to fix the value of an action parameter.
?= is used to set a default value if the parameter is not found in the
querystring.

Anyway, in Scala = is used to define default parameter values in
method *definitions*. A route definition is not like method
definition.

numan bdr

unread,
Feb 25, 2013, 3:02:00 PM2/25/13
to play-fr...@googlegroups.com
This has been bugging me too.

On Thursday, December 20, 2012 3:47:20 PM UTC+1, numan bdr wrote:
I am new to scala and playframework but have gone through basic syntax of scala. So fat what i know is for default parameters to a method in scala, the default value is put after = in method definition like

def doSomething(x:Int = 5) = ......

Whereas in the tutorial for playframework in routing section it says like

Parameters with default values

You can also provide a default value that will be used if no value is found in the incoming request:

# Pagination links, like /clients?page=3
GET   /clients              controllers.Clients.list(page: Int ?= 1)


So my question is how does ?= is handled. Because in scala-doc there is nothing about it as far as i have searched. Is it the magic pulled out by framework or scala syntax for default parameters.
Reply all
Reply to author
Forward
0 new messages