java - Play Framework 2.3.4 - How to call Results.badRequest() on a POST request and direct to method in controller not mapped by routes? -
java - Play Framework 2.3.4 - How to call Results.badRequest() on a POST request and direct to method in controller not mapped by routes? -
ok title bit hard understand.
what trying accomplish following.
my controller:
public static result addsomething() { homecoming getsomething(some_form); } public static result addsomething(form<someformdetails> someform) { // complicated stuff someobject , someotherobject homecoming ok(com.me.views.html.pages.addsomething .render(someobject, someotherobject, someform)); } public static result postfromsomeform() { form<someformdetails> filledform = some_form.bindfromrequest(); someformdetails details = filledform.get(); // checks if (database.addstuff(details)) { homecoming redirect(com.me.controllers.routes.get.index()); } else { // #### of import bit #### // next line not possible not have // method addsomething(form<someformdetails> someform) mapped // in routes, mean homecoming badrequest(com.me.controllers.routes.get.addsomething .render(filledform)); // #### of import bit #### } }
routes
get /something com.me.controllers.get.addsomething() post /something/add com.me.controllers.get.postfromsomeform()
what want avoid doing having lots of unnecessary code repeated someobject
, someotherobject
objects under postfromsomeform()
method.
i aware can move bit denoted // complicated stuff someobject , someotherobject
method, due nature of 2 objects not simple.
i add together addsomething(form<someformdetails> someform)
routes, if rename (overloaded methods don't seem allowed), not desirable cause lots of other problems.
i cannot alter of import bit to:
return badrequest(com.me.controllers.get.addsomething.render(filledform));
as not supported (ie without using reverseget). fyi gives the method badrequest(content) in type results not applicable arguments (result)
.
i'm pretty sure trying accomplish easy there doesn't sem easy way accomplish in using framework because of reverseget bits generated routes not having same homecoming types controller methods (which know of course of study case , understand required)
can allow me know if there simple supported way accomplish trying achieve? please allow me know if question doesn't create sense.
you can accomplish want making action homecoming rendered template instead of result:
public static string addsomething(form<someformdetails> someform) { // complicated stuff someobject , someotherobject homecoming com.me.views.html.pages.addsomething .render(someobject, someotherobject, someform).body(); } // latter homecoming badrequest(com.me.controllers.routes.get.addsomething.render(filledform));
java playframework playframework-2.3
Comments
Post a Comment