I've a little problem, i want to create a web app and i learn PlayFramework with java documentation of
This sample code :
public Result hello() {
DynamicForm requestData = formFactory.form().bindFromRequest();
String firstname = requestData.get("firstname");
String lastname = requestData.get("lastname");
return ok("Hello " + firstname + " " + lastname);
}
The ''formFactory'' doesn't exist.
Why I don't have this field ?
And when i want to create a model, i don't have the model class
Thanks you so much if you resolve my problem ! :)
You will have to inject your formFactory like this:
First make sure to import these 2 libaries in your Play Controller:
import javax.inject.Inject; import play.data.FormFactory;
After that before using the Form Builder, inject it into your code:
Your code should work fine after this.
From the documentation:
Play already knows about
FormFactory
, so just add a constructor parameter for it:I'm guessing the
Model
you mention is that of EBean. You need to enable EBean for your project, and then you'll have the necessary classes on your classpath.In
project/plugins.sbt
:build.sbt
:More information is available in the relevant docs.