At the first sight we thought of extending the ViewObject and adding a transient attribute.But that seems to be very complex process as this ViewObject is based on 5 EntityObjects.
So we thought of some workaround and come to a solution by adding a ViewAttribute in ViewObect dynamically.Here is the approach …
We have extended the Controller and add a ViewAttribute dynamically in the ViewObject and created a MessageStyledText bean through personalization.
public void processRequest(OAPageContext pageContext, OAWebBean webBean) { super.processRequest(pageContext, webBean); OAApplicationModule am = (OAApplicationModule)pageContext.getApplicationModule(webBean); OAViewObject vo = (OAViewObject)am.findViewObject("AllocationsVO1"); if (vo != null) { vo.addDynamicAttribute("XXSalary"); //Adding ViewAttribute to VO } vo.reset(); vo.next(); //Starting do-while for setting value in all the table row... do { //Doing some calculation... int xxnumber = Integer.parseInt(vo.getCurrentRow().getAttribute("Empno").toString()); double d = xxnumber*(17.5/100)/2; String aString = Double.toString(d); //Setting the calculated derived value in the newly created VO Attribute vo.getCurrentRow().setAttribute("XXSalary", aString); vo.next(); } while (vo.hasNext()); vo.first(); //Finally adding ViewAttribute and ViewInstance with MessageTextInput bean which we have created through personalization OAMessageTextInputBean mst = (OAMessageTextInputBean)webBean.findChildRecursive("Salary"); mst.setViewUsageName("AllocationsVO1"); mst.setViewAttributeName("XXSalary"); mst.setReadOnly(true); }
Thanks
--Anil
Hi Anil,
ReplyDeleteThanks for such a wonderful article. I used this code today. First time the output comes properly (data shows up in messageStyleText). from second time it throws an error "oracle.jbo.NameClashException: JBO-25001: Name ExpAcct of object type Attribute already exists". Any idea why it comes, please let me know.
Please Help me Even I am also facing the same problem
ReplyDeleteHi,
ReplyDeleteIn above IF condition i.e. if (vo != null), handle the exception by using try ..catch block as shown below:
try
{
String l_att= vo.findAttributeDef("XXSalary").toString();
}
catch(Exception exception)
{
vo.addDynamicAttribute("XXSalary"); //Adding ViewAttribute to VO
}
- L.Nishanth, Apps Associates
Thanks Nishanth for your input. Yes, I mistakenly forget to check that while adding dynamic attribute we have to check its existence first.
ReplyDeleteThanks
--Anil
Here is what dev guide says about it:
ReplyDelete// Check whether the attribute with the same name exists or not.
// Note that for attributes, we need to use try-catch clause.
If (vo.lookupAttributeDef("MyAttr") == null)
{
vo.addDynamicAttribute("MyAttr");
}
Hi Anil,
ReplyDeleteI used your code to check the existence of attribute.
If (vo.lookupAttributeDef("MyAttr") == null)
{
vo.addDynamicAttribute("MyAttr");
}
In my case It is throwing OA exception.
When I tried with Nishanth's solution it is working fine.
Thank you,
Keshav
Keshav,
ReplyDeletePlease read my reply properly you have to use this in Try catch block.....
great addition in my knowledge Anil
ReplyDeletereally it is a nice example |
ReplyDeleteHi Anil it's very good post so informative.
ReplyDeleteIf possible I need your help,
Scenario comes under OAF Extensions.
user would enter data on 2 fields on say page x and I need to display that data on say page z so for that I need to create those fields. But then how to handle VO ??
How to achieve this task ??
you can mail me at sudhirbhilar@gmail.com
Please give your valuable wordings