Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//Oracle ADF ActionEvent to duplicate a row
public void duplicateRowLine(ActionEvent e) {
ViewObject vo = this.getViewObjectFromIterator("YOUR_ITERATOR_NAME");
Row currentRow = vo.getCurrentRow();
Row duplicatedRow = vo.createRow();
AttributeDef[] voKeyAttributes = vo.getKeyAttributeDefs(); //List of the primary keys that need to be unique
String[] currentRowAttributes = currentRow.getAttributeNames();
for (String attributeName : currentRowAttributes) {
int attributeIndex = duplicatedRow.getAttributeIndexOf(attributeName);
//Check if the attribute is updatable
if (duplicatedRow.isAttributeUpdateable(attributeIndex)){
//Check if the attribute is a Primary Key
if (!this.attributeIsPrimaryKey(voKeyAttributes, attributeName)) {
//If it's not, copy the attribute value to the duplicated row
duplicatedRow.setAttribute(attributeName, currentRow.getAttribute(attributeName));
}
//Mandatory: Add an else here to set the primary key with a unique value in java
}
}
//Add the duplicated row to your View Object
vo.insertRow(duplicatedRow);
//Optionnal : Commit the VO to add row in database
//Optionnal : Refresh the table AdfFacesContext.getCurrentInstance().addPartialTarget("YOUR_TABLE_ID");
}
private boolean attributeIsPrimaryKey(AttributeDef[] voKeyAttributes, String currentAttributeName) {
for (AttributeDef voKeyAttribute : voKeyAttributes) {
if (voKeyAttribute.isPrimaryKey() && currentAttributeName.equals(voKeyAttribute.getName())) {
//If one of the primaryKey attribute is the current attribute
return true;
}
}
return false;
}
/*** This function is usually a public available in your ADFUtils package and should be reusable ***/
private static ViewObjectImpl getViewObjectFromIterator(String nomIterator) {
_Logger.log(Level.INFO, "" + nomIterator);
ViewObjectImpl returnVO = null;
DCBindingContainer dcb = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
if (dcb != null) {
DCIteratorBinding iter = dcb.findIteratorBinding(nomIterator);
if (iter != null) {
returnVO = (ViewObjectImpl)iter.getViewObject();
}
}
return returnVO;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.