I have an event handler that runs perfectly fine on a repository. However once I add a controller into the mix and call the repository method directly, the EventHandler seems to be skipped over.
Has anyone encountered this "issue"? If so, what can I do to get the event handler to start running again?
So you expect that your event handler is called when you use a custom controller. I think this expectation is false. The event handler is just called when spring data rests RepositoryEntityController is in control. It is not an entity event listener on JPA level.
What you could do is call the event handler manually. The spring-data-rest RepositoryEventHandler is a using normal spring application events. So your controller could implement ApplicationEventPublisherAware and publish one of the spring-data-rest application events. These are all subclasses of org.springframework.data.rest.core.event.RepositoryEvent
applicationEventPublisher.publishEvent(new AfterCreateEvent(myEntity));
See the spring documentation for details.
Related
I am getting the warning like "Added non-passive event listener to a scroll-blocking 'mousewheel' event." and suggesting me to "Consider marking event handler as 'passive' to make the page more responsive." It quite hard to understand for newbie like me. I am using Axios, mixins, auto-complete in element-ui. The page is working fine, but the loading time is lazy.
It just means you are handling mousewheel events. If the handlers are doing something instead of the normal event, you can ignore the message. If you're doing something in addition to the normal event, you should add the passive option to the listener so the default processing can happen without blocking.
https://developers.google.com/web/tools/lighthouse/audits/passive-event-listeners
In general, add the passive flag to every wheel, mousewheel,
touchstart, and touchmove event listener that does not call
preventDefault().
If it's a package that is doing the event handling and not your own code, just ignore it.
In WPF, for most UI events, we have PreviewX event as well. How come there is no such a thing in Universal Apps? Is the events system fundamentally different from that of WPF that there is no need for it?
Found the answer, the system has changed from bubbling and tunneling. Now it works with Routed Events. More information can be found here. Here is the important excerpt:
Earlier we said that setting Handled to true prevents most handlers from being called. But the AddHandler method provides a technique where you can attach a handler that is always invoked for the route, even if some other handler earlier in the route has set Handled to true in the shared event data.
So instead of adding the event handler as usual, you'll need to call AddHandler to add your "Preview" handler.
Something to note: the documentation does not say that these special handlers are executed before the regular ones, so it is not exactly the same as the PreviewX method.
I have a rather serious problem trying to get a Telerik radTreeView to show changes in the underlying database and therefore datasource. My scenario is as follows.
In the Load event hander, the radTreeView is initialized as in the following example code:
radCommentTreeView1.DataSource = Nothing
// Initialize custom data object from custom hierarchical data source class
cdsPubCommentDataSource = New CommentDataSource(1)
radCommentTreeView1.DataSource = cdsPubCommentDataSource
// Configure radTreeView from datasource fields
radCommentTreeView1.DataFieldID = "ID"
radCommentTreeView1.DataFieldParentID = "ParentID"
radCommentTreeView1.DataTextField = "Content"
// Bind radTreeView to datasource
radCommentTreeView1.DataBind()
The page loads with radTreeView rendered correctly
User attempts to add or delete a node by clicking a button with a server-side handler ....
... so that the postback cycle begins in the server-side code, with the Load handler from (2) above running again, to rebind the radTreeView
... only after which the server-side button handler is run, successfully running an SQL command through another BLL business object (i.e., the SQL database is successfully modified ) ....
However, when the page renders after the postback, the radTreeView still reflects the original node hierarchy from (4) above, before the node was deleted in (5).
Could someone indicate how this process ought to be achieved within the cycle of a single postback - if I call DataBind on the radTreeView at the end of the server-side button handler, this does seem to pick up the database changes, but unfortunately it destroys the radTreeView's formatting with the node template, and as a result, no node databound content is rendered in any of the nodes. Obviously, the node template needs to be instantiated at the start of the page life-cycle, and if, as in this case, databinding late in the cycle disrupts the template, I cannot tell the page to 'go back' and instantiate the template again. But calling DataBind at the end of the handler would seem to me to be the intuitively correct way to approach the issue, it's just that the resulting loss of the node template prevents it from working.
I am aware of the idea of using the INotifyPropertyChanged interface for the datasource object, and already have the event in question being successfully fired up from the DataSource object, namely a PropertyChanged event that is fired at (4) when the radTreeView first rebinds on the postback, but I am not sure how a PropertyChanged event handler can help in the scenario I describe - the PropertyChanged event handler in the page is still invoked before the button handler, and so the database has not been changed at that stage. Is the PropertyChanged event the correct way forward, or is there another approach better suited for refreshing the radTreeView within a single postback cycle?
Thanks if someone can point me in the right direction with this problem.
Regards
One of the stated SpineJS goals is to make the entire UI non-blocking (i.e. display the change to the user, even though it might have not been updated successfully on the server side yet).
Can it be used in a standard "blocking" manner?
Yes it can. Look here under "callbacks":
http://spinejs.com/docs/ajax
You can basically block the UI at any point, and I do it for things that just can't be deferred to the server. Note that I don't even use the ajaxSucess() event, but just custom bindings for events. Here is an example use case in meta programming:
Bind 'clickHandlerFinish' event to clickHandlerFinishWork()
Bind 'click' event on button a to clickHandler()
User clicks on button a
clickHandler() gets fired
clickHandler disables the button and blocks the UI
clickHandler makes an AJAX call to the server to do work
(Remember UI is still blocked)
AJAX call finally returns, and fires the clickHandlerFinish() callback
clickHandlerFinish() unblocks the UI, re-enables the button, and presents the new changes
I've used this successfully on a few instances. Works great for me!
I have seen others with a similar issue but not quite what I was looking for. In the backgrounderworker class dowork event I create an instance of a new class and call one of it's function. Previously, I had this code in a windows.form.timer tick event and would pass a delegate in as one of the parameters which would allow the function and other functions it calls within the class to call a method on the form to update a datagrid on the GUI. Is there a way to do this within the dowork event? I need this because the function I call from dowork calls other functions and I want each of those functions to log information in the GUI datagrid.
The BackgroundWorker.ReportProgress() method was intended to do that. You implement the ProgressChanged event to update the UI, it will run on the main thread. You're not restricted to report just a progress percentage, you can pass any object as well to pass info to the event handler by using the overload that accepts the userState argument. Beware that you have to use proper locking if you do that.
Apart from ReportProgess mentioned in Hans' answer, you can alternatively use Control.Invoke on one of the UI elements to exeute code in the UI thread.
You can send progress data back to the UI thread, you will get an event for that on the UI thread, then you can update the screen. It is highly preferred that the objects you send back to the UI thread are immutable. Besides calling the ReportProgress and handling the event you need to opt-in by setting WorkerSupportsProgress property to true.