Reputation: 413
i have popup form that insert data in adf table , i can insert row by pressing add button, and i can edit the inserted rows . and this is the code : Add Button :
JSFUtils.setExpressionValue("#{pageFlowScope.status}", "add");
RichPopup.PopupHints hints = new RichPopup.PopupHints();
ResetUtils.reset(getmyPopup());
getmyPopup().show(hints);
OperationBinding createOp = ADFUtils.findOperation("CreateInsert");
createOp.execute();
and the add popup has 2 button ok and cancel :
the ok button :
getmyPopup().hide();
the problem is the popup has some LOV that clear some input text , when i open the popup in the edit mode , and change LOV value , and press cancel button i try to restore the old row : and this the code for edit button :
rowimpl currentRow = (rowimpl )ADFUtils.findIterator("iterator").getCurrentRow();
rowimpl backupRow=(rowimpl )ADFUtils.findIterator("iterator").getCurrentRow();
JSFUtils.setExpressionValue("#{pageFlowScope.value1}",currentRow.getValue1();
.
.
. // for all values
and this is the cancel button code :
DCIteratorBinding dciter = ADFUtils.findIterator("itertaor");
dciter.getRowSetIterator().setCurrentRow(backupRow);
the problem is the backup row is not set properly to old values
Upvotes: 0
Views: 1331
Reputation: 1583
Sounds like you want to do a partial rollback when the user cancels the edit operation. For this, you could write some methods for that specific VO, expose them as client interface and just bind them to the Cancel button. Easiest way I remember doing this is to:
Create a transient attribute in you VO that is linked with an EO, that will indicate the current row state. Make it an Integer and call it RowStatus or whatever you like.
In the ViewObjectRowImpl class of your VO, find the getter method of the transient attribute you create above and replace it with:
public Integer getRowStatus() {
/*
2-Modified
0-New
1-Unmodified
-1-Initialized
*/
byte entityState = this.getEntity(0).getEntityState();
return new Integer(entityState);
}
Create a method inside the ViewObjectImpl that will revert one row:
public void revertChangesCurrentRow(Row row) {
if (row!= null) {
row.refresh(Row.REFRESH_UNDO_CHANGES | Row.REFRESH_WITH_DB_FORGET_CHANGES);
}
}
Create another method inside ViewObjectImpl that will rollback only this VO, by removing new rows or undoing changes, based on each row status (which you get from the transient attribute):
public void revertOrRemoveRowValues() {
ViewObject myVo = this;
RowSetIterator myVoIterator = myVo.createRowSetIterator(null);
while (myVoIterator.hasNext()) {
Row nextRow = myVoIterator.next();
if (nextRow.getAttribute("RowStatus") != null) {
Integer rowStatus = (Integer) nextRow.getAttribute("RowStatus");
if (rowStatus == 2) {
//modified rows
revertChangesCurrentRow(nextRow);
} else if (rowStatus == 0) {
//new row (added by create)
nextRow.remove();
}
}
}
this.executeQuery();
}
Finally, expose the method revertOrRemoveRowValues in the client interface of the VO, and then just drag and drop it as a button on your page. This will bind the function that you wrote above to the button and every time it gets clicked it will do a partial rollback, a rollback performed only on that VO. It does this by either removing new rows that were added or undoing edits to existing rows and also it will refresh the VO with the values from DB (due to the this.executeQuery() command, and as such the user should see it as it was before any edits occured).
Upvotes: 1