How to submit a form and show the result on the same page using the Play platform?

I have been playing the Play Framework for several days and it seems really cool. However, I had problems when I wanted to have a form on the page, publish the form and show the results on the same page (with the form on the page). Does anyone know if this is possible on Play, and if so: how?

EDIT: I should have explained better. A form is a search-style form, not a save-style form. I want to be able to search for something, the results appear under the form and still have values โ€‹โ€‹filled in by the user in the form (as if you entered what was not checked. I tried to set the values โ€‹โ€‹of the params object directly in the search action but it disappears when the search action triggers a new action.

+4
source share
2 answers

The second response attempt has not been verified, hope this matches your problem.

public static void search(String criteria1, String criteria2) { .... params.flash(); } 

search.gsp

  <p id="criteria1-field"> <label for="criteria1">&{'criteria1'}</label> <input type="text" name="criteria1" id="criteria1" value="${flash.criteria1}" /> </p> <p id="criteria2-field"> <label for="criteria2">&{'criteria2'}</label> <input type="text" name="criteria2" id="criteria2" value="${flash.criteria2}" /> </p> 
+4
source

Well, thatโ€™s pretty simple. You put in routes.conf a

 GET /myPageWithForm MyController.read POST /myPageWithForm MyController.save 

In the read, you read the data and compose your page using the form. In save mode, you save data and redirect it to read through read() ;

Hope this answers your question.

+1
source

All Articles