This is a way of converting a given date as a string to oracle.jbo.domain.Date.
/**
*Converts a String to oracle.jbo.domain.Date
* @param aDate
* @return oracle.jbo.domain.Date or null.
*/
public oracle.jbo.domain.Date castToJBODate(String aDate){
DateFormat formatter;
java.util.Date date;
if(aDate!=null){
try {
formatter = new SimpleDateFormat("dd/MM/yyyy");
date = formatter.parse(aDate);
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
oracle.jbo.domain.Date jboDate = new oracle.jbo.domain.Date(sqlDate);
return jboDate;
} catch (ParseException e) {
e.printStackTrace();
}
}
return null;
}
Friday, April 9, 2010
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...).
1)
2)
3)
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..
Source: http://download.oracle.com/docs/cd/E12839_01/apirefs.1111/e10653/oracle/jbo/RowIterator.html#createRow()
-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.
Source: http://download.oracle.com/docs/cd/E12839_01/apirefs.1111/e10653/oracle/jbo/RowIterator.html#createAndInitRow(oracle.jbo.AttributeList)
Conclusion: createAndInitRow method does not have expected behaviour when it comes to LOV or Choice List attributes that return more than one attributes.
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...).
1)
2)
3)
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..
Source: http://download.oracle.com/docs/cd/E12839_01/apirefs.1111/e10653/oracle/jbo/RowIterator.html#createRow()
-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.
Source: http://download.oracle.com/docs/cd/E12839_01/apirefs.1111/e10653/oracle/jbo/RowIterator.html#createAndInitRow(oracle.jbo.AttributeList)
Conclusion: createAndInitRow method does not have expected behaviour when it comes to LOV or Choice List attributes that return more than one attributes.
Subscribe to:
Posts (Atom)