The examples in playframework seem to be lacking my example. The booking is the closest but it is an example of CRUD module and uses this parent() call which I am not sure what that does either. Is there an example without the CRUD module?
Also, all the validation sample examples call "render" on the methods for the http POSTs...is that the preferred method instead of redirect to a GET with the errors in the page?
The specific example I am looking for that would answer all these questions would be
- create new object with editentity.html
- rerender with errors
- AND edit old object with editentity.html (same html page as above obviously).
Is there a good example of this?
MORE notes here... We have this from the calling page(or different calling pages) For adding a project
<a href="@{Project.editProject(null)">Add Project</a>
For editing a project
<a href="@{Project.editProject(project.name)">Edit</a>
BUT now if I do that, I struggle with the post now as I have
public static void postProject(ProjectDbo project) {
if(validation.hasErrors()) {
Validation.keep();
params.flash();
Project.editProject(???????/???); //I need to pass in the project to refill in the form AND the project.name for the routes file???
}
SomePage.pageXXXXX();
}
NOTE: the ???? is where I need to pass in projectDbo, but the method only accepts the projectName only. How to get the stuff to render back in the page again?
I think there must be a way to call editProject and set that projectDbo needs to be accessed by the page too or is there not a way to do this? How to do this pattern?
TRY #5: I did try using params.flash and calling Project.editProject(project.name) but unfortunately, none of my form is filled back in and the user loses ALL of his work that he filled in. The only thing I have working is using render(action, {params list not matching the action arguments})
(The booking example is lots of ajax so hard to see the example there).
this is such a common use case, I would have thought there would be an example for it.
thanks, Dean
I have built exactly that example for a presentation at the Java User Group in Buenos Aires.
It's just a basic crud application, featuring validations, one-to-many relationship, fixtures, tests, tags, twitter bootstrap, and deployment to several PaaS cloud computing.
This is the github repo: https://github.com/opensas/play-demo
A detailed step by step tutorial: https://github.com/opensas/play-demo/wiki
The application is up and running on
Openshift, Google application engine, heroku, Cloudbees
Is is based on the zencontact example, which is also what you are looking for.
And about using the same form, this is the code from the app:
I hope it's useful...
Saludos
Sas
About the "redirect after post" approach, I wrote an article on that subject (in spanish, sorry, you can try with google translate)
https://github.com/opensas/RedirectAfterPost/blob/master/README.md
And here's the git repo of a sample application: https://github.com/opensas/RedirectAfterPost
Basically there are two approaches:
Render again the same page without redirecting (like it's done on zentalk example)
pros:
cons:
Save all the data and errors in flash, and force a redirect
pros:
to test the sample just issue:
I ended up doing my own example that I can steal from with ajax included here
https://github.com/deanhiller/timecardz/blob/master/app/controllers/OurPattern.java
The view https://github.com/deanhiller/timecardz/tree/master/app/views/OurPattern
The important routes for POST are all generic so they can be used for ALL controllers not just this one
The GET route for the page is the only specific route then.
which for a bit of time I have a live version running at
http://myextremestore.com/ourpattern
The only thing that is kind of missing from that example is validation of the owning entity on POST calls(notice in my controller, methods that are post are called postXXX)
Is there a reason why
http://www.playframework.org/documentation/1.2.4/validation
Does not tell you everything you need to know regarding this? In particular the "validation.keep()" method.