Ok, let's say we have created custom Create form using a method in Application Module class. At the same time, Edit form functionality is developed based on the same View object as for Create form, but only with one difference - it is developed in declarative way, using JDeveloper wizards. Let's make a test and see what we will get. Create form:
When Creat button is pressed, Edit form is opened, but displayed data isn't correct:
Developed sample application - SetCurrentRowWithKeyValue.zip, handles this action correctly. Sample is based on LOCATIONS table from standard HR schema. Data from DEPARTMENTS table is used in Detail part of Master-Detailed relationship implemented in Edit form.
Value for primary key column is generated by database sequence, so for primary key column is assigned DBSequence type. So, how to open correct data in Edit form after Create operation is performed? Needed steps:
- From createLocation method implemented in Application Module class, you should return primary key value for newly created row - newLocation.getLocationId().getSequenceNumber();
- In Create form JSPX page Backing bean implemented action method binding, store returned primary key value into managed bean - JSFUtils.setManagedBeanValue("valueHolder.locationId", ((Number)result).stringValue()); Please, notice that oracle.jbo.domain.Number is converted to java.util.String, it is because setCurrentRowWithKeyValue accepts java.util.String type values
- In page definition file for Edit form, define setCurrentRowWithKeyValue action, in developed sample it looks similar:
- Don't foget to add in the same page definition file invokeAction element for defined setCurrentRowWithKeyValue:
When Create button is pressed, Edit form is opened with correct data:
When running sample application, don't forget to add adf-faces-impl.jar and jsf-impl.jar to application's WEB-INF\lib directory.