Development Requirements
In oaf development, there may be such a requirement. When you select the Save button, if there is changed data, commit the transaction and save it to the database;
If no changed data exists, the system prompts you that no data can be changed.
Solution
Determine whether the view object used in the page has been changed
Method 1: Call the oadbtransaction. isdirty () method
This method is used to determine whether the view object has changed in the current transaction. However, this method is only valid for Object-based view objects. If a query-based view object exists, you need to call PL/SQL to change the database.
Method 2: Call oaviewobject. isdirty ()
This method can be used to determine whether a single view object has been changed, whether it is a view object based on an object or a view object based on a query.
Method 3: Call the getpoststate () method of the object to determine
Sometimes oaviewobject. isdirty () is restricted. If the query is re-executed, the dirty flag of the view object is reset. In this case, you cannot use this method to determine whether a change exists. Instead, you need to use the following method or the fourth method.
CallViewrowimpl. getentity (0). getpoststate ()You can determine whether the object corresponding to the View row has been changed, so that the dirty flag can be reset regardless of whether the View row is re-queried.
Method 4: Use Data Cache
Before entering the page, cache the data to transaction. When saving the button event, compare whether each attribute of the row of the object saved by transaction is consistent with that of the row of the current view object.
The reason for using Method 4 is that if insertrow () exists and the row. Remove () is deleted, the system considers that the view object has unsaved changes. The fourth method can be used to avoid this situation (in general, the customer should be persuaded to accept this situation ).
In addition, if the view object created based on the query is saved to the database using PL/SQL, and the temporary attribute changes exist (row is called. setattribute (), even if the attribute does not need to be saved to the database), you can only use the fourth method.