Thanks for the quick response.
index.scala.html...................................
@(form: Form[Seed])
@main("Welcome") {
<script src="@
routes.Assets.at("javascripts/index.min.js")" type="text/javascript"></script>
@helper.form(action = routes.Application.addSeed) {
@helper.inputText(form("name"))
@helper.inputText(form("url"))
<input type="submit" value="Add seed"/>
}
<ul id="seeds"></ul>
}
....................................................................................................
and in the controller (Application.java)
import play.core.j.PlayMagicForJava;
import play.data.Form;
import play.libs.Json;
import play.mvc.Result;
import services.SeedService;
import views.html.index;
@org.springframework.stereotype.Controller
public class Application{
@Autowired
private SeedService seedService;
public Result index() {
return play.mvc.Controller.ok(index.render(play.data.Form.form(Seed.class)));
}
public Result addSeed() {
Form<Seed> form = play.data.Form.form(Seed.class).bindFromRequest();
Seed seed = form.get();
seedService.addSeed(seed);
return play.mvc.Controller.redirect(controllers.routes.Application.index());
}
public Result listSeeds() {
return play.mvc.Controller.ok(Json.toJson(seedService.getAllSeeds()));
}
}
.................................................................................................................
I know the view use play.api.data.Form while Controller use play.data.Form. To use one data type in the both places is the issue as i dont know how to render the Fom without using play.data.Form.form as play.api.data.Form doesnt have a form() method. I m stuck here.
Thanks a lot again.
Rajiv