Saturday, March 15, 2014

Creating Transient View Object

Transient View Objects are very useful to build data entry forms when you don't necessarily want to create instances of Entity based View Objects till later time. In my projects, i have always tried to use Transient View Objects instead of POJO Databeans to bind to UI components. I have also used such Transient View Objects to collect search terms, when not using Query component, then i create and apply View Criteria in my Application Module method based on data entered by User which is collected from Transient View object.

Here is how you can create  Transient View Object.
  • Create New View Object, make sure to create View object in default views package. We will re-factor into different package later. This is done as JDeveloper at times creates Java files in wrong package otherwise.
  • Use consistent suffix for View Object Name to indicate that it is Transient View Object.
  • Select Programmatic option for Data Source in View Object wizard.
  • Add attributes as needed.
  • Make sure all Attributes are always updatable and set to be persisted. Also, Make sure to define a Primary Key attribute (one or more) for View object.

  • Finish View Object creation wizard.
  • Go to general tab, expand Tuning and Make sure No Rows is selected for Retrieve from the Database section.
  • Save your work.
  • Refactor Transient View Object in to a different package of your choice. For example, views.trans package.
  • Open View Object's Java file, generate if you don't have it and implement beforeRollback and afterRollback methods as shown below.