playframework - Query string lost from a submit button -
i new both web application , play framework, , problem asking might naive. however, googled around little while , couldn't find answer it, please bear me.
first, platform play-2.1.1 + java 1.6 + os x 10.8.3.
a short version of problem: have form of submit button action="hello?id=100". however, when click button, request being sent seems hello?
rather hello?id=100
. action request expects parameter id
, error hello?
.
here full setup.
conf/routes:
get / controllers.application.index() /hello controllers.application.hello(id: long)
app/controllers/application.java:
package controllers; import play.*; import play.mvc.*; import views.html.*; public class application extends controller { public static result index() { return ok(index.render()); } public static result hello(long id) { return ok("hello, no. " + id); } }
app/views/index.scala.html
this index page. <form name="hellobutton" action="hello?id=100" method="get"> <input type="submit" value="hello"> </form>
according play documentation, id
supposed extracted query string ?id=100
. however, when click submit button, request becomes hello?
rather hello?id=100
, , error this:
for request 'get /hello?' [missing parameter: id]
can tell me why happening, please? thank in advance.
the problem form:
<form name="hellobutton" action="hello?id=100" method="get"> <input type="submit" value="hello"> </form>
as form method set get, it's changing query string. method="get"
tells browser add contents of form query string means current query string gets removed.
you can add id hidden field in form this:
<form name="hellobutton" action="hello" method="get"> <input type="hidden" name="id" value="100"> <input type="submit" value="hello"> </form>
that tell browser add hidden field query string resulting in hello?id=100
. alternatively change form method post.
Comments
Post a Comment