I would like to implement form handling for web apps. I'd like to implement PRG (post-redirect-get), as I believe it is the way to go in form handling (plays very nicely with reload and back button). However, I'm seeing that it complicates validation.
Basically, when you post, you have the form state (as post parameters). However, if you validate and redirect back to the form, you lose your form state (your redirect is a GET; you could encode all the form parameters in GET, but that's not always possible, due to URL length restrictions. Also, it looks ugly as hell).
I'm thinking about the following:
- User is in the form view (
/addUserDetails.html
) - POST to action url (
/addUser
) /addUser
executes the relevant action. If it fails, it stores the form state, assigns an id to it and redirects to the form view, with the id as a get parameter (/addUserDetails.html?state=2313ab2
)- The view validates the state and displays the relevant information
Depending on how you store the form state, you might also let the user continue working on the form even if their browser blows up or something bad happens.
Thoughts? Also, is there any Java web framework that does this or can be coerced into doing it?