Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos


I have seen many postings in the Web Dynpro forum regarding
importing complex JavaBeans in Web Dynpro.Many of us
are
facing the same problems in creating the relationships for
the model classes.If we use the Adaptive RFC or a Web
Service
then the relationships will be created automatically.
However in the case of the JavaBean model we have to manually create
the relationships for the model classes.


This weblog explains the step-by step procedure for importing complex JavaBeans into a Web Dynpro by creating the
relationships manually.

I have taken the Employee Bean having different methods, which perform operations on the Employee
table using the Entity bean.

Some of the methods are


EmpDetails [] getEmpList ();
Void createEmployee ();



We will use these two methods for explaining the procedure.

We have assumed that whoever will take up this tutorial, knows
how to develop Session Beans and Entity Beans. Our concentration is on developing the Command Bean and using that one
in the Web Dynpro through the Java-Bean model.




Steps for developing Command-Bean.


1. Create a class

EmpCommandBean.



Public Class EmpCommandBean {
Public EmpCommandBean(){
}
}



2. Declare collection type reference in EmpCommandBean class.

This collection is filled with employee records returned from Session Bean
Method. These records are displayed in the WebDynpro screen.


private Collection empDetailsList=null;
private EmpDetailsHelperClass empdetails=null;



3. Declare one more reference to EmpSession bean local interface

Since both client and bean are running on the same virtual machine we can

take Local interfaces (home and component). If you want to run the client
and bean in different servers(jvms), declare a reference to RemoteComponent Interface.

the Dialog Box.

3.     Specify the model name and model package then select
local Jar file option.

4. Specify the path of the jar file where you have Exported Your
Command Bean and Helper class jar file.

Add both classes.

5.     It will show all the attributes in the property list of the
helper class.

6. Click on the ‘Model relation View’ tab of command bean, it will
show the relationship between command bean and collection class. Uncheck
the relationship. We need to create the relations manually in WebDynpro
  Application.

7.     Click on finish.

cardinality is 0..1.

6.     Click on finish.

Now relation is created and from now the procedure is same as
adaptive RFC.

Map the component context to model and view context to component context.

This view creates employee and retrieves all employee details by calling
model methods.

Bind the component context to model context using the bind method



EmpCommandBean bean = new EmpCommandBean();
wdContext.nodeEmpCommandBean().bind(bean);
/*this is for creating element for EmployeeNode which
contains data of Employee and this data will be inserted
into database through sessionbeans and entitybeans.*/
EmpDetailsHelperClass obj = new
EmpDetailsHelperClass();
bean.setEmpdetails(obj);
wdContext.nodeEmpdetails()
.bind(wdContext.createEmpdetailsElement
(obj));


Call getAllEmployeedetails() method in the eventhandler of
‘getEmployees’ button and it retunes employee records and these records
will be stored as elements in the WebDynpro.


wdContext.currentEmpCommandBeanElement()
.modelObject()
.getEmpDetailsList();


call createEmployee() method of model in the eventHandler of ‘createEmploye’ button.
This will insert data into database.


wdContext.currentEmpCommandBeanElement
.modelObject()
.createEmployee();



15 Comments