Thursday, April 8, 2010

ViewObject.createRow(); Or ViewObject.createAndInitRow(AttributeList); ?

There are many posts over the internet regarding how to open a page in Insert Mode.
Invoke Insert operation that is.
There are also many ways of doing this.
In this post I would like to show you a small, but very big, difference between VO.createRow() and VO.createAndInitRow(AttributeList attrList) methods.

Download Sample Application.

The difference can be found in this specific and yet very common case:
In the form to be created we have an LOV which besides the codeId returns also another value to another Attribute of the ViewObject: see the following Image:

Yes, it is a common case in every day programming...

In the sample application I have implemented 3 Different methods with the same result (not quite the same result as you will see...).




The Whole purpose is those methods to be called before entering the page. se the flow below:

On the main.jspx I have placed 3 buttons for each action. The result to this is the following:

For the first two (2) methods the result is the same and as expected: the second attribute of the LOV is returned correctly.

For the third (3d) method, the result is not as expected: The New Row is created but the second attribute is not returned at all!

Actually I did a bit more of investigation.

I created another 3 button with the same actions for a different page. This page does not have the LOV case as the previous one.
It has an attribute from a referenced Entity.
So when the LOV has a value the referenced attribute will have value.
After testing, I saw that all actions have exactly the same correct behaviour: Referenced Attribute is calculated correctly.

Download Sample Application.

According to the API:
-createRow() : Creates a new Row object, but does not insert it into the Row Set.
Returns: a new Row object..

-createAndInitRow(AttributeList nvp): Creates and initializes a new Row object, but does not insert it into the Row Set. This method differs from createRow() mainly in that this method allows the user to pass in a list of name-value pairs with which row attributes are initialized.
nvp is a named value pair. When building an nvp from scratch, use NameValuePairs to build a new nvp. Here is an example:
NameValuePairs nvp = new NameValuePairs();
nvp.setAttribute("EmpTyp", "C");

Row row = voEmp.createAndInitRow(nvp);

This method is particularly useful when creating a subclass View Row or Entity Row. You can include polymorphic discriminator attribute values in nvp and correct subclass row object will be created.
When this method is called, underlying entities are created. After the new entities are created, a new view row is created. After that ViewRowImpl.create(oracle.jbo.AttributeList) is called with this nvp. ViewRowImpl.create(AttributeList) walks thru the list of entities and calls EntityImpl.create(AttributeList) with the same nvp for each entity in the view row.
Parameters: nvp - a list of name-value pairs.
Returns: a new Row object.

Conclusion: createAndInitRow method does not have expected behaviour when it comes to LOV or Choice List attributes that return more than one attributes.


  1. Is it possible to create all rows at once and then insert them in bulk, It would be great help if you show me any links regards this.

  2. where does the method getEntity define for this method
    public EntityImpl getEmployees() {
    return (EntityImpl)getEntity(0);

  3. Hi Anonymous... I am not sure I understand the question..

    Can you elaborate a bit more?

    Thank you,



Related Posts Plugin for WordPress, Blogger...