I am new to both web application and the play framework, and the problem I am asking might be very naive. However, I googled around for a little while and couldn't find a good answer to it, so please bear with me.
First, my platform is play-2.1.1 + java 1.6 + OS X 10.8.3.
A short version of the problem: I have a form of submit button with action="hello?id=100". However, when I click the button, the request being sent seems to be hello?
rather than hello?id=100
. The action for this request expects the parameter id
, so I get an error for hello?
.
Here is the full setup.
conf/routes:
GET / controllers.Application.index()
GET /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 is an index page.
<form name="helloButton" action="hello?id=100" method="get">
<input type="submit" value="Hello">
</form>
According to the play documentation, the id
is supposed to be extracted from the query string ?id=100
. However, when I click the submit button, the request becomes hello?
rather than hello?id=100
, and thus I get an error like this:
For request 'GET /hello?' [Missing parameter: id]
Can someone tell me why this is happening, please? Thank you in advance.