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 It's a bit difficult to understand my title.
What am I trying to achieve?
My Controller:
Public Fixed Results addSomething () {Return getSomething (SOME_FORM); } Public static results addSomething (form of & lt; SomeFormDetails & gt; someForm) {// Do complex things to get someObject and someOtherObject returned is OK (com.me.views.html.pages.AddSomething .render (someObject, someOtherObject , SomeForm)); } Public stable results postFromSomeForm () {form & lt; SomeFormDetails & gt; FillForm = SOME_FORM.bindFromRequest (); SomeForm Details Description = refresh.get (); // Check some if (database.adstaff (details)) {return redirect (com.me.controllers.routes.Get.index ()); } Else {// #### This important BIT #### // this is not possible as the next line (form of someForm) // method // add / s is not possible in the map / /, But what you call me badRequest Return (com.me.controllers.routes.get.add something .render (fillForm)); // #### This is important ####}
route
get some com.me.controllers. Get addSomething ( ) Post / Something / Com.me.controllers.Get.postFromSomeForm () Adding
What I want to avoid is having lots of unnecessary code to get the bar -Bar is someObject
and someOtherObject
under the postFromSomeForm ()
method.
I am aware that I can move a little shown by I can add I just can not change the important bit in: Because it is not supported (i.e. without using reverse gate) FIIi gives it I am pretty sure that I am trying to get something easier but using this framework is not an easy way to achieve it because all the reversegate bits generated from the routes are due to controlling methods Do not return the same type of form (which I know is definitely the case and it understands it is necessary) Can anyone tell me what to do? Shish is, it is a simple supported way to accomplish this? Please tell me that the question does not make sense. / am doing it SomeFormDetails & gt; / SomeObject and someOtherObject
in some other way, but two things do not make it complicated due to the nature of the nature
addSomething ; SomeForm) In the routes, if I change the name (overloaded methods are not allowed), but this is not desirable because it will cause many other problems.
Change badRequest (com.me.controllers.Get.addSom ething.render (filledForm));
results in method (result) is not applicable for badRequest (content) argument (results)
.
You can get what you want to achieve, return the provided template instead of the action one Results of:
Do the complex stuff to get public static string addSomething (form & lt; SomeFormDetails & gt; someForm) {// someObject and someOtherObject com.me.views come back . Html.pages.AddSomething .render (some objects, some other objects, someForm) .body (); } // later badRequest (com.me.controllers.routes.Get.addSomething.render (fillForm));
Comments
Post a Comment