Oracle ADF Rest - overridden prepareForDML method is not called when there is no change in attribute - oracle-adf

In my EOImpl class , I have overridden prepareForDML method to call an external API and based on external API response I have to update an attributes value.
In case of PATCH API call with change in attribute value it works fine , but PATCH API call without any change in attribute's value prepareForDML method is not executed.
Is it possible to call prepareForDML method when there is no change in attribute's value.
Or is there any alternative approach to implement this ?

Related

React-table - Force refresh os data using onFetch

I'm trying to use component react-table in my ReactJS project. I'm using external data source (server processing) and it's working. To get data, i'm using prop called onFetchData, which call's my function called fetchData(state, instance). This is working fine. But what I need now is to force refresh os this data. Let me explain: data from my table is coming from state property called 'data'. Whe I change anything in react-table, react-table itself call function declared in 'onFetchData' and send his (table) internal state as parameter. This state has filters and sorting props.....this is fine.
When my 'fetchData(state, instance)' execute, it call's my external script and get data, save this data to state and refresh my table. All this is working fine!
But now I have 3 external filters in my screen (not in react-table!) and when I change these filter, I would like to call 'fetchData(state, instance)' again to force refresh os data......but I can't because I don't have current table 'state' (which contains current table filters and ordering).
I can call my 'fetchData(state, instance)' when I change any filter on my screen, but I lose any filter set in mu react-table.

DeepStateRedirect in angular ui-router 1 - how to reset the deep state?

I'm using angularJS and migrating to ui-router v1. I'm trying to get deep state redirects working like they used to in the previous version of ui-router.
I've successfully implemented the DSRPlugin in my config modules, and deep state redirects are firing and work as expected. However, I'm unable to reset the deep state. I need to be able to reset the deep state on a button click, which means logic within my component. Previously I could inject $deepStateRedirect into my controllers and simply call $deepStateRedirect.reset({}), but I'm no longer able to inject $deepStateRedirect. How can I access the reset method in ui-router v 1?
I have also noticed that when using DSR as a config object you can specify a function to determine if the redirect occurs. I could alternatively use this to determine whether to do the redirect or not, but the documentation is lacking. It shows that I should return a truthy value to do the redirect or a falsey value to prevent the redirect. In testing, returning true or false only causes a transition error: "i.state is not a function".
I'm not using a build process, just plain script includes.
Anyone have any ideas on how to make this work through either of the above methods?
This may not be the best practice way of doing the reset, but I found a solution after logging out various ui-router objects.
Inside of your controller you must inject the $uiRouter object. Then, you can set a variable to $uiRouter._plugins["deep-state-redirect"]. The reset() and other methods are available on the plugin's prototype.
You can then use that object and call those methods similar to how it worked in the previous version when injecting $deepStateRedirect.
var $deepStateRedirect = $uiRouter._plugins["deep-state-redirect"];
$deepStateRedirect.reset({});
I found this only in the source code and then in the documentation: https://ui-router.github.io/ng1/docs/latest/classes/core.uirouter.html#getplugin
The more correct way is to use UIRouter#getPlugin(pluginName), that is
var $deepStateRedirect = $uiRouter.getPlugin('deep-state-redirect');
$deepStateRedirect.reset(...);

reset AngularJS Material Design custom component to pristine

I have an AngularJS custom component that essentially wraps around a Material Design mdSelect, but provides easy configuration of available, default, and current values via its bindings.
But the component functions as a general editing component in an mdDialog that can change its options based upon the thing being edited. Thus is a "Next" button to go to the next "thing" to be edited. When the button is pressed the custom component will have new available, default, and current values—something like this:
<foo-component default-value="dialog.getDefaultFoo()" current-foo="dialog.currentFoo">
</foo-component>
Note that the component, if a list of available values is not given (as in the example above), the component assumes a list of values with only one value, the "default-value" indicated.
So when a user selects "Next", the list of values in the mdSelect will change, because the value returned by dialog.getDefaultFoo(). The new selected value will be dialog.currentFoo.
But if dialog.currentFoo is null, I want the control to automatically select the indicated default value, or if no default is indicated, the first available value. That's easy enough when the component is created using $onInit. But once it is created, how do I know (inside the component) that the user has selected "Next" and the list of available values has changed?
In the code for the "Next" button, I call this.fooForm.$setPristine(). According to the documentation, the when this method is called the form controller will "propagate to all the controls contained in this form." So I considered having my custom control hook detect that $setPristine() is being called, so that it can automatically select a default value from the list if the new value is null. But how now I'm back in the same situation: how does my custom component detect that $setPristine() is being called on the form?
In essence, my custom component needs to detect when one of its bound values changes, and perform some custom update of other values under certain conditions. I know that I can use a getter/settter from outside the custom component, but how does the custom component detect that one of its bound values has changed?
To make matters more complicated, dialog.currentFoo is actually a function, which my component recognizes as a getter/setter function which will return/update the correct value based upon the state of the dialog. So I can't even detect that this value has changed, because the actual function never changes—only the value that it returns will change.
And it's actually even more complicated than that, because the mdSelect is only one piece of the object that gets sent to dialog.currentFoo; otherwise it isn't propagated outside the component.
Trying to summarize, I need to know in a custom component if the binding dialog.currentFoo, which is really a getter/setter method, would now return null so that the custom component could select a default value (also dynamic) based upon the current items (also dynamic) listed in the internal mdSelect. I would accept workarounds, such as detecting that $setPristine() has been called on the enclosing form. I would even accept a hack, such as forcing AngularJS to recreate the custom component when some external state changes.
This is tricky, because AngularJS is tricky, and because it's exceedingly hard to track information on custom AngularJS control/input components.
Above all the first thing that needs to be done is to make the custom component use the normal ngModel framework; trying to "fake" it using a two-way bound currentValue doesn't cut it for this complexity, and besides, ngModel is the "correct" AngularJS way to do it. To pull this off you'll need to use NgModelController. Finding out how to do this with a component is difficult in itself, although one page gave the magic formula. It goes something like this:
require: {
ngModelCtrl: "ngModel"
},
bindings: {
ngModel: "<"
//TODO add defaultValue or whatever other properties here
},
Then you don't access the two-way value directly; you use the NgModelController interface:
//get the current value
const foo = this.ngModelCtrl.$modelValue;
//set the current value
this.ngModelCtrl.$setViewValue(foo);
As best I can tell, if you add ng-model-options="{getterSetter:true}" to the component, the ngModelOptions will automatically get applied to your model, and getters/setters will be called automatically.
Now you are hooked into the whole ngModel framework, and use NgModelController to add/access validators and all sorts of advanced features.
Getting back to my needs, where I need to "reset the component" in certain conditions, I can patch into NgModelController#$setPristine(). The form controller recognizes my component is part of the ngModel framework, and calls $setPristine() when the form is reset to its pristine state.
this.$onInit = () => {
this.ngModelCtrl.$setPristine = () => {
myInternalValue1 = null;
myInternalValue2 = this.defaultValue;
};
this.ngModelCtrl.$setPristine(); //initialize default value
};
This explains the doubt I had about the form controller "propagat[ing $setPristine()] to all the controls contained in this form", which I mentioned in my original question. The secret is that the component must become part of the real ngModel system so that it can interact as AngularJS is expecting, as well as to gain access to important internal methods.

How to share api response throughout angular 2 application?

I am calling REST API through service and using that service to get response in root component. So now I have api response(JSON object) in my root component and I want share that object in child component. How can I use that object in child component without calling service again?
In short, I don't want to call sever many times for same data (call api only once) and use that response throughout angular 2 application.
Could you please suggest how we can achieve this?
You can do this by using get and set. Create a public variable with get and set.
Fisrt time when you get response simply set into that variable and after that call get method to retrieve same data.
public listData;
set listData(value){
this.listData = value;
}
get listData(){
return this.listData;
}

in Backbone model, which method gets executed first, success or parse?

I am making a AJAX call using something like:
model.fetch(
dataType: "jsonp",
success: function(data){}
)
My question is if I want to modify the data return from the server, should I do it in success or model.parse(). Also, which method gets executed first?
WARNING: I am a backbone newbie :)
Thank you in advance!
Parse will be triggered first.
The backbone official documentation its not clear about it. It says:
parse is called whenever a model's data is returned by the server, in fetch, and save. The function is passed the raw response object, and should return the attributes hash to be set on the model. The default implementation is a no-op, simply passing through the JSON response. Override this if you need to work with a preexisting API, or better namespace your responses.
It doesn't talk about who is triggered first.
But i test it by my self, and parse was triggered first.
You can test it by yourself, if you don't have an API for test, Use dataType:"jsonp" and try to find a web site that is using REST.You'll see that JsonP is triggered first. :)

Resources