I have a pretty complex form with lots of inputs and validators. For the user it takes pretty long time (even over an hour) to complete that, so they would like to be able to save the draft data, even if it violates rules like mandatory fields being not typed in.
I believe this problem is common to many web applications, but can't find any well recognised pattern how this should be implemented. Can you please advise how to achieve that?
For now I can see the following options:
But as you see no one is really reasonable. Is there really no simple solution to the problem?
It's indeed not that easy. Validation is pretty tight coupled in JSF lifecycle.
I would personally go for option 1. True, dirty work, but you can just hide that away in an utility class or so. Just grab the <h:form>
in question from the viewroot, iterate over its children recursively, hereby testing if component instanceof EditableValueHolder
is true, store the found id-value pair in sort of Map
and finally persist it.
As a fourth alternative, you could save all the data independently using ajaxical powers. jQuery is helpful in this.
$.post('/savedraft', $('#formid').serialize());
It only requires Javascript support at the client side.
Update: the JSF utility library OmniFaces has a <o:ignoreValidationFailed>
taghandler for the exact purpose. It was indeed not a simple solution as it requires a custom <h:form>
as well. It does its job by providing a custom FacesContext
instance during the validations and update model values phases which does a NOOP in the validationFailed()
and renderResponse()
methods. So the components are still invalidated and the messages are still attached, but it would still proceed to the update model values and invoke application phases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With