Change By: Federico Grilli (11/Dec/13 6:25 PM)
Description: Suppose you're creating a new node and doing some additional validation in an action, besides that done by the validator proper. 
If such additional validation fails for some reason, you are presented again with the form to fix the data you entered before. Now data are correct, you hit the submit button and no validation error will occur.
However, the action will fail again, this time with NPE. What happened is that each time you call {{JcrNewNodeAdapter.applyChanges()}} to get
 the  an  actual  underlying  jcr Node  updated to its  in synch with the  latest status  of the adapter . The first time that jcr Node is created on the fly and is a transient one as the session it is contained in hasn't been saved yet (it will be saved once all validation passes). The second time the jcr node will be no longer created on the fly, rather fetched from the current JCR session as if it were no longer a new node rather an existing one,  hence  but since the session wasn't saved due to the validation errors, subsequent calls to {{  applyChanges() }}  will return null.
We should take into account that a new node adapter isn't always saved on first attempt
 and validation errors may occur , therefore we must be able to reuse the adapter until it is  either  valid  (hence saved to a jcr repository)  or discarded. What we could do in  {{  info.magnolia.ui.vaadin.integration.jcr.JcrNewNodeAdapter.applyChanges()  keep }} is keeping  on creating the node on the fly as long as needed .
{code}
 // If changes were already applied, behave like a JcrNodeAdapter
        if (appliedChanges) {
            Node node = super.applyChanges();
            if (node != null) {
                isNew = false;
                return node;
            }
            // else validation errors probably occurred, so we need to recreate the new node on the fly
        }
{code}
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira



----------------------------------------------------------------
For list details, see: http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to