[xwiki-users] Server side validation / block save
Hello all, I'm hoping someone can give me a suggestion to save my skin. When I was brand new to xwiki I quickly created an application for "ticketing" using AppWithinMinutes because it seemed like the easiest way for a newbie to create an application. In doing so I created a form which had several controls on it (e.g.. around 20 or so). In order to maintain business logic I wrote EXTENSIVE JavaScript which enforces business rules and prevents a save (basically cancelling the postback through JavaScript) if they aren't met. Admittedly this isn't that great of a solution as now I'm having problems with JavaScript failures (mostly with other libraries being loaded with xwiki which prevents my JavaScript from running) which then allow the pages to be saved despite validation failures. What I'm hoping is that there is some way to "shim" some server side code in using an event listener, or some sort of "before save" event in velocity or groovy that can evaluate the submitted page and prevent a save if the business logic rules are broken. I don't really have the luxury of re-writing or refactoring the solution I've written because it's in production at this point and works 95% of the time, but I definitely need to do more in relation to validation since broken rules cause downstream impacts to other applications relying on clean data. So, any help is GREATLY appreciated. I have seen this http://platform.xwiki.org/xwiki/bin/view/DevGuide/Creating+a+form+with+valid ation+and+tooltips and reviewed it, but I can't really figure out how I would use it with an existing page or with AppWithinMinutes. Also, I already have an event listener configured which does some stuff that I might be able to use for this purpose.. but I think those events (DocumentCreatedEvent() and DocumentUpdatedEvent()) happens AFTER the save and I haven't really been able to find a way to "block" the save if it does happen before anyway.. I would need to invoke validation on save and update of documents too.. I'm hoping there might be some way of adding code to the AppWithinMinutes generated page that can do some post save validation and stop the save if it fails. So help !!! :)
bump...please help :)
On Jan 30, 2015, at 10:50 AM, Jason Clemons <[email protected]> wrote:
Hello all,
I'm hoping someone can give me a suggestion to save my skin. When I was brand new to xwiki I quickly created an application for "ticketing" using AppWithinMinutes because it seemed like the easiest way for a newbie to create an application. In doing so I created a form which had several controls on it (e.g.. around 20 or so). In order to maintain business logic I wrote EXTENSIVE JavaScript which enforces business rules and prevents a save (basically cancelling the postback through JavaScript) if they aren't met. Admittedly this isn't that great of a solution as now I'm having problems with JavaScript failures (mostly with other libraries being loaded with xwiki which prevents my JavaScript from running) which then allow the pages to be saved despite validation failures.
What I'm hoping is that there is some way to "shim" some server side code in using an event listener, or some sort of "before save" event in velocity or groovy that can evaluate the submitted page and prevent a save if the business logic rules are broken.
I don't really have the luxury of re-writing or refactoring the solution I've written because it's in production at this point and works 95% of the time, but I definitely need to do more in relation to validation since broken rules cause downstream impacts to other applications relying on clean data.
So, any help is GREATLY appreciated. I have seen this http://platform.xwiki.org/xwiki/bin/view/DevGuide/Creating+a+form+with+valid ation+and+tooltips and reviewed it, but I can't really figure out how I would use it with an existing page or with AppWithinMinutes.
Also, I already have an event listener configured which does some stuff that I might be able to use for this purpose.. but I think those events (DocumentCreatedEvent() and DocumentUpdatedEvent()) happens AFTER the save and I haven't really been able to find a way to "block" the save if it does happen before anyway..
I would need to invoke validation on save and update of documents too.. I'm hoping there might be some way of adding code to the AppWithinMinutes generated page that can do some post save validation and stop the save if it fails.
So help !!! :)
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
On 02/03/2015 04:57 PM, Jason Clemons wrote:
bump...please help :)
On Jan 30, 2015, at 10:50 AM, Jason Clemons <[email protected]> wrote:
Hello all,
I'm hoping someone can give me a suggestion to save my skin. When I was brand new to xwiki I quickly created an application for "ticketing" using AppWithinMinutes because it seemed like the easiest way for a newbie to create an application. In doing so I created a form which had several controls on it (e.g.. around 20 or so). In order to maintain business logic I wrote EXTENSIVE JavaScript which enforces business rules and prevents a save (basically cancelling the postback through JavaScript) if they aren't met. Admittedly this isn't that great of a solution as now I'm having problems with JavaScript failures (mostly with other libraries being loaded with xwiki which prevents my JavaScript from running) which then allow the pages to be saved despite validation failures.
What I'm hoping is that there is some way to "shim" some server side code in using an event listener, or some sort of "before save" event in velocity or groovy that can evaluate the submitted page and prevent a save if the business logic rules are broken.
I don't really have the luxury of re-writing or refactoring the solution I've written because it's in production at this point and works 95% of the time, but I definitely need to do more in relation to validation since broken rules cause downstream impacts to other applications relying on clean data.
So, any help is GREATLY appreciated. I have seen this http://platform.xwiki.org/xwiki/bin/view/DevGuide/Creating+a+form+with+valid ation+and+tooltips and reviewed it, but I can't really figure out how I would use it with an existing page or with AppWithinMinutes.
There is no inherent magic in AppWithingMinutes created pages, you can edit the generated pages the same as manually created ones. (There is no guarantee these modifications will survive if you change the data structure via AppWithinMinutes; I remember there is a step in the wizard which asks you if the wizard can update the sheets - this is the place where the wizard lets you know the changes get lost ;)) So, anyway, ou should have a space containing your "AppCode" ... and there should be the "Sheet" page containing the code for viewing your items, which includes the edit view. If looking in the DocumentIndex for the page, it is one of these ending with Sheet ;) and yes, it is hidden, so fix up your settings first. There you can add a <input type="hidden" name="xvalidation" value="AppName.ValidationGroovy" /> in the part which has a #if($xcontext.action =='edit') and then create your AppName.ValidationGroovy script "as advertised" in the tutorial.
Also, I already have an event listener configured which does some stuff that I might be able to use for this purpose.. but I think those events (DocumentCreatedEvent() and DocumentUpdatedEvent()) happens AFTER the save and I haven't really been able to find a way to "block" the save if it does happen before anyway..
There is also a DocumentCreatingEvent and DocumentUpdatingEvent However listening to these event will not prevent the creation / update from happening, I think; i.e. you cannot prevent saving a document from an event listener, but only update some values that need to be "automagically" set before saving.
I would need to invoke validation on save and update of documents too.. I'm hoping there might be some way of adding code to the AppWithinMinutes generated page that can do some post save validation and stop the save if it fails.
So help !!! :)
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
hth Clemens
Hey Clemens, Thanks so much for the response I really appreciate it. Ok.. I have the first part working which I think is the "plumbing" but I'm not sure of the next step. So far I've implemented this in my "sheet" page: $doc.setValidationScript("ValidationSample.ValidationGroovy") $doc.validate() I've validated that the page is returning a value from ValidationSample.ValidationGroovy because when I explicitly change the values in the ValidationSample.ValidationGroovy page, I see the value reflected on my sheet when it is instantiated. I definitely understand that the "meat" of my validation logic goes in the ValidationSample.ValidationGroovy page, and I understand how to return a value from that page.. but how do I stop/intercept the actual save of the page? Currently regardless of the value I return (e.g.. true of false) the page save happens the same. I think the part I'm missing is in the "How to validate and save the document in CreateDoc" section of the tutorial listed here ==> http://platform.xwiki.org/xwiki/bin/view/DevGuide/Creating+a+form+with+valid... although, I'm having some trouble understanding WHERE that code should live and what exactly its function is. Does the CreateDoc implementation live in my application sheet, or does it live in it's own sheet named CreateDoc? (which is how it is implemented in the example). Is the CreateDoc essentially the code that is "shimed" in between the save event and the actual save? If so, how is it called? Thanks again for all your help
On Feb 5, 2015, at 3:33 AM, Clemens Klein-Robbenhaar <[email protected]> wrote:
On 02/03/2015 04:57 PM, Jason Clemons wrote: bump...please help :)
On Jan 30, 2015, at 10:50 AM, Jason Clemons <[email protected]> wrote:
Hello all,
I'm hoping someone can give me a suggestion to save my skin. When I was brand new to xwiki I quickly created an application for "ticketing" using AppWithinMinutes because it seemed like the easiest way for a newbie to create an application. In doing so I created a form which had several controls on it (e.g.. around 20 or so). In order to maintain business logic I wrote EXTENSIVE JavaScript which enforces business rules and prevents a save (basically cancelling the postback through JavaScript) if they aren't met. Admittedly this isn't that great of a solution as now I'm having problems with JavaScript failures (mostly with other libraries being loaded with xwiki which prevents my JavaScript from running) which then allow the pages to be saved despite validation failures.
What I'm hoping is that there is some way to "shim" some server side code in using an event listener, or some sort of "before save" event in velocity or groovy that can evaluate the submitted page and prevent a save if the business logic rules are broken.
I don't really have the luxury of re-writing or refactoring the solution I've written because it's in production at this point and works 95% of the time, but I definitely need to do more in relation to validation since broken rules cause downstream impacts to other applications relying on clean data.
So, any help is GREATLY appreciated. I have seen this http://platform.xwiki.org/xwiki/bin/view/DevGuide/Creating+a+form+with+valid ation+and+tooltips and reviewed it, but I can't really figure out how I would use it with an existing page or with AppWithinMinutes.
There is no inherent magic in AppWithingMinutes created pages, you can edit the generated pages the same as manually created ones. (There is no guarantee these modifications will survive if you change the data structure via AppWithinMinutes; I remember there is a step in the wizard which asks you if the wizard can update the sheets - this is the place where the wizard lets you know the changes get lost ;))
So, anyway, ou should have a space containing your "AppCode" ... and there should be the "Sheet" page containing the code for viewing your items, which includes the edit view. If looking in the DocumentIndex for the page, it is one of these ending with Sheet ;) and yes, it is hidden, so fix up your settings first.
There you can add a <input type="hidden" name="xvalidation" value="AppName.ValidationGroovy" /> in the part which has a #if($xcontext.action =='edit') and then create your AppName.ValidationGroovy script "as advertised" in the tutorial.
Also, I already have an event listener configured which does some stuff that I might be able to use for this purpose.. but I think those events (DocumentCreatedEvent() and DocumentUpdatedEvent()) happens AFTER the save and I haven't really been able to find a way to "block" the save if it does happen before anyway..
There is also a DocumentCreatingEvent and DocumentUpdatingEvent However listening to these event will not prevent the creation / update from happening, I think; i.e. you cannot prevent saving a document from an event listener, but only update some values that need to be "automagically" set before saving.
I would need to invoke validation on save and update of documents too.. I'm hoping there might be some way of adding code to the AppWithinMinutes generated page that can do some post save validation and stop the save if it fails.
So help !!! :)
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
hth
Clemens
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
On 02/06/2015 11:04 PM, Jason Clemons wrote:
Hey Clemens,
Thanks so much for the response I really appreciate it.
Ok.. I have the first part working which I think is the "plumbing" but I'm not sure of the next step.
So far I've implemented this in my "sheet" page:
$doc.setValidationScript("ValidationSample.ValidationGroovy") $doc.validate()
I think the option you have choose is only useful if you programatically call "doc.save()" - in that case you are also expected to do the validation and stuff by yourself. However that is not your use case; you want to have a validation callback that gets called implicitly from the normal document save action. To do that you should add the hidden input fields: <input type="hidden" name="xvalidate" value="1" /> <input type="hidden" name="xvalidation" value="ValidationSample.ValidationGroovy" /> in the edit view of the sheet. Probably this means that you have to wrap these two entries around an #if ($xcontext.action=="edit") ... #end or the like to avoid having them in the normal view. In that case the save action should figure out from the submitted form values: a) that it should do a custom validation of form submit (as xvalidate=1) b) and being told where to look for the validation script (by loading xvalidation=ValidationSample.ValidationGroovy) In this case you should not need to add velocity code by your own to trigger the validation. However you might need custom code to display the validation errors, as show in the next section of the tutorial, or your users will never know what the problem is with their inputs ... hope this helps, Clemens
I've validated that the page is returning a value from ValidationSample.ValidationGroovy because when I explicitly change the values in the ValidationSample.ValidationGroovy page, I see the value reflected on my sheet when it is instantiated.
I definitely understand that the "meat" of my validation logic goes in the ValidationSample.ValidationGroovy page, and I understand how to return a value from that page.. but how do I stop/intercept the actual save of the page?
Currently regardless of the value I return (e.g.. true of false) the page save happens the same. I think the part I'm missing is in the "How to validate and save the document in CreateDoc" section of the tutorial listed here ==> http://platform.xwiki.org/xwiki/bin/view/DevGuide/Creating+a+form+with+valid... although, I'm having some trouble understanding WHERE that code should live and what exactly its function is.
Does the CreateDoc implementation live in my application sheet, or does it live in it's own sheet named CreateDoc? (which is how it is implemented in the example). Is the CreateDoc essentially the code that is "shimed" in between the save event and the actual save? If so, how is it called?
Thanks again for all your help
participants (2)
-
Clemens Klein-Robbenhaar -
Jason Clemons