It is quite easy to delete records in the FORM, because the FORM can delete the current record based on the row where your cursor is located, as long as you simply write delete_record in the Trigger.
However, in OAF, the deletion I currently know is a little troublesome (it is not ruled out that there are convenient methods that need to be studied ).
Why bother? In OAF, it seems that the corresponding record is not deleted based on the row where your cursor is located, but deleted based on the Record Pointer, which is irrelevant to your cursor position,
We need to use code to precisely locate records. Therefore, when deleting records, we need to write some code for implementation.
The User's Guide provides a standard deletion method to locate the records to be deleted by looping through pointers in the current record set (in this example, only one record is deleted ).
I found it quite troublesome. I looked for it again and summarized several methods.
Delete a single record: it does not need to be processed cyclically. It can be implemented in combination with the SPEL ("Simplest Possible Expression Language") Language.
Batch Record deletion: There are several methods, and I think the most troublesome (maybe the most rigorous) in the User's Guide ).
No matter how you delete it, the general implementation idea is as follows:
First, mark the record to be deleted: either check and select, or put an icon button on the line to ignition. In short, there are many methods.
Secondly, the record pointer is precisely located based on tags: a single location is deleted, and multiple records need to be located multiple times.
It is best to pop up confirmation to prevent accidental deletion.
Execute Delete and submit.
Well, let's take a look at the deletion of a single record:
Implementation Method:
Create a FormParameter on PageLayout. The name is "WantToDeleteId". The primary key ID to be used to store the row to be deleted.
Create a pseudo column in VO. The value is Null and the name is Deleteflag. It is used to generate the delete button.
Add an icon to the record row to trigger the delete action and extract the Primary Key of the row to be deleted as follows:
ID: DeleteFlag
Item Style.: Image
Image Url: deleteicon_enabled.gif (that is, the classic small garbage bin)
View Instance: <your VO name>
View Attribute: Deleteflag
Action Type: FireAction
Event: delete (custom name)
Submit: True
Parameters:
Name: "WantToDeleteId"
Value: $ {oa. <your VO name>. <Primary Key name >}for example: $ {oa. OrderLineVO. LineId} This is the SPEL language.
When you click this icon, OAF extracts the Primary Key value and sends it to Form. parameter.
Write the code for deleting records in AM as follows:
Import oracle. jbo. Row;
...
Public void removedata (String deleteId)
{
OAViewObjectImpl vo1 = this. getOrderLineVO1 (); // instantiate VO
Int delid = Integer. parseInt (deleteId); // convert the input primary key ID to the int type.
Row row = vo1.getFirstFilteredRow ("LineId", new Number (delid); // obtain the Row queried by ID.
Row. remove (); // Delete
GetTransaction (). commit (); // submit
}
Note that the primary key is generally Number type, and the parameters passed through CO are generally String, so conversion is required.
Write code in CO to ignition and call AM, as follows:
Import java. io. Serializable;
...
If ("delete". equals (pageContext. getParameter (EVENT_PARAM) // identifies the event name
{
String aa = pageContext. getParameter ("WantToDeleteId"); // obtain the value of Form. parameter
Serializable [] parameters = {aa}; // define parameters
Am. invokeMethod ("removedata", parameters); // call the AM method and input parameters
}
The execution result is that the row is deleted when you click the delete icon of a row.
Let's take a look at the deletion of batch records.
Implementation Method:
Create a pseudo column in VO. The value is Null and the name is Deleteflag. used to generate the check box.
Create a code in AM to delete the selected records. The Code is as follows:
Method 1: refer to the User's Guide and use RowIndex to traverse
Method 2: Use the record filtering function and use array pointer Traversal
Method 3: traverse by recording the pointer displacement
Call the am method in co to delete it.
Method 1: This method uses RowIndex to traverse the record set. The pseudo code is as follows:
Import oracle. jbo. RowSetIterator;
...
Public void deletedata ()
{
OAViewObjectImpl vo1 = this. getOrderLineVO1 (); // instantiate VO
OrderLineVORowImpl row = null; // does this line matter...
Int rowcount = vo1.getFetchedRowCount (); // gets the number of records of the currently extracted record set
RowSetIterator deleteIter = vo1.createRowSetIterator ("deleteIter"); // create a record set indicator
If (rowcount> 0)
{
DeleteIter. setRangeStart (0); // sets the starting point of the loop, which is equivalent to moving the pointer to the first record.
DeleteIter. setRangeSize (rowcount); // you can specify the number of cycles.
For (int I = 0; I <rowcount; I ++)
{
Row = (OrderLineVORowImpl) deleteIter. getRowAtRangeIndex (I); // get the current record
String primaryKey = (String) row. getDeleteflag (); // obtain the primary key value for deletion.
If ("Y". equals (primaryKey) // determines whether to delete
{
Row. remove ();
GetTransaction (). commit ();
Rowcount = rowcount-1; // This line is important because the total number of cycles is reduced by 1 after a row is deleted; otherwise, overflow occurs.
I = I-1; // This line is also very important, because after deleting a record, the original one will be supplemented, index is the index of the deleted record.
}
}
}
DeleteIter. closeRowSetIterator ();
}
I personally feel that this method is a bit annoying. I don't know what kind of considerations Oracle has to consider when using this method, because I have tested many methods to delete multiple records.
Method 2: This method uses the record array to traverse. The pseudo code is as follows:
Import java. jbo. Row
...
Public void deletedata ()
{
OAViewObjectImpl vo1 = this. getOrderLineVO1 (); // instantiate VO
Row [] row = vo1.getFilteredRows ("Deleteflag", new String ("Y"); // generate the record set to be deleted
For (int I = 1; I <= row. length; I ++) // loops based on the number of records in the record set
{
Row [I]. remove (); // Delete
GetTransaction (). commit (); // submit
}
}
This method is to determine the record set based on the delete tag, and then delete all the records of the set, the effect is similar to the above...
Method 3: This method traverses the recorded pointer displacement. The pseudo code is as follows (not tested yet ):
Public void deletedata2 ()
{
OAViewObjectImpl vo1 = this. getOrderLineVO1 (); // instantiate VO
Vo1.first (); // locate the record pointer to the first
Int rowcount = vo1.getFetchedRowCount (); // gets the number of records
For (int I = 0; I <rowcount; I ++)
{
Row row = vo1.getCurrentRow (); // gets the current record
If ("Y". equals (row. getAttribute ("Deleteflag") // you can determine whether the object can be deleted.
{
Row. remove ();
GetTransaction (). commit ();
Rowcount = rowcount-1; // number of records minus 1 after deletion
}
Else
{
Vo1.next (); // move the pointer (if the deletion is successful and the subsequent records are supplemented, you do not need to move the pointer.
}
}
}
Author: "Soy Milk"