Skip to Content

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.

image

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.

image

Add both classes.

image

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.

image

7.     Click on finish.

cardinality is 0..1.

image

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.

image

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

image

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();

To report this post you need to login first.

15 Comments

You must be Logged on to comment or reply to a post.

  1. Mehnaaz Zahir
    I implemented exactly like you have described, but fetching the records is not working. It comes back empty.

    Where do we put the line below:

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

    An early pointer would be greatly appreciated.
    Thanks
    Mz

    (0) 
    1. Mehnaaz Zahir
      And one more Q, after adding the line
      wdContext.currentEmpCommandBeanElement()
                   .modelObject().getEmpDetailsList();

      in the right place, do we need to also iterate through the whole Collection and addElement() one by one?

      Thanks
      Mz

      (0) 
      1. Balaram Naidu Bankuru Post author
        HI Zahir,

           you need to write the wdContext.curretnEmployeeList().modelobject().getEmployeeList() in the Event handler of ‘getEmplist’ or in the wdinit() of view controller.

          You no need to iterate through the collection.since we have created relations for the model classes,the elements in the webDynpo are automatically created.
        still if u have any doubts feel free to ask me.

        With Regards
        Balaram Naidu

        (0) 
        1. Subash Mathews Thomas
          You need to add the invalidate method also in the event handler of the action button. This will refresh and populate the view with the result data.

          wdContext.currentEmpCommandBeanElement()
                        .modelObject()
                              .getAllEmpDetails();

          wdContext.nodeEmpDetailsList().invalidate();

          (0) 
  2. Padmashree B
    Hello,
       I think it is not required to create Model Relations manually.
       But you will have to specify the target Model Class in one of the steps during the model import.
       In the above article in the step 6, it is required to resolve the Target Model class if it involves a collection. In the drop down of the column Model Class, all the selected JavaBeans are listed out. Select the class ‘EmpDetailsHelperClass’ from the list and click finish. This is because the method ‘getEmpDetailsList()’ in the implementation returns a collection of the ‘EmpDetailsHelperClass’ objects. Please keep the status as checked.
      This is required because if the relation is of type collection, it is not possible to identify the target model class. But in the first relation since the return type of the method was ‘EmpDetailsHelperClass’, the target class was identified automatically.
      Hope this will help you.
    Kind Regards,
    Padma
    (0) 
  3. Krishna Kumar Jayakumar
    Hi Balaram,

    I am facing problem working with this example.
    So, can u pls send me the complete source code of this Employee Project example.

    Atleast complete src of EmpDetailsHelperClass.

    Thanks in advance,
    Krishna

    (0) 
    1. Nikhil Tapkir
      Hi Krishna,

              Did balaram send u the code u asked for if yes kindly send the code to me to. Its urgent.
      Thanks in advance. Or if U dont have it right now a similar application code would do…

      (0) 
  4. Anonymous
    Hi Balaram,

    wlog is very good,But if we update model,suppose we added some bussiness methods in EJB,That methods will be getinto Helper class noproblem,but in the view in the webdynpro we already bind model context into view context,In this case we need to create new model or how we update the model(reload the java bean model).

    Thanks in Advance
    Balaji

    (0) 
  5. bk kim
    hi~

    I have read “    Importing Complex JavaBean model into WebDynpro by creating relationships for the model classes ” in your blog.

    I would like to have the example sample source which is offered in your blog, If it could be possible.

    I have some problem in Web Dynpro programming.

    1.There is a table.

    2.Check the checkBox.

      2.1.1  Then, client event happens.
      2.1.2  Whenever Checking a checkbox,
             it communicates with server due to life-         cycle of Web Dynpro.

      2.1.3     Instead of commuication everytime with   server when I select an each checkbox,
    I would like to modify the checkbox information in Context by single communication
    with the server after selecting several check boxes.
                                  
           3.    JavaScript  could  solve this problem in  an Web programming environment, but Web Dynpro does not support JavaScript. To solve this problem, I want to use groovy  to do that.

    4.   Is It possible  to solve this proble by using groovy ? otherwise is there any solution

    To solve this problem by using AJAX, I request the sample source from you.
    If you give an answer to me, I will appriciate that.
    I will look forward to hearing from you.
    Also I want to receive my mail.
    My Email address is bkkim@bsgglobal.com

    Have a good day!

    From B.K KIM

    (0) 
  6. Dheerendra Shukla
    Hi Balaram,
    Really u posted this blog in nice way. But i have a problem regarding importing javaBean Model.
      As you shown in urs second diagram that when u importing the local Jar File u shown there are two Radio Button(i.e. Design Time and Deploy Time) i m also doing the same thing but not able to get these two radio button …..also i m not able to do the manupulation in the Model Relation View …can u explain me in some detail so that i can do my Job…
    Thanks

    Regard’s
    Dheerendra

    (0) 
  7. Xinhua Xu
    Hi Balaram,

    your example is very interesting. I have tried, but I have not understand all what you mean. Can you send me the whole example project? thank you very much

    best reqards

    Xu

    (0) 
  8. Jan Michael Jaudian
    Hello,

    This is a very helpful WebBlog, sir. But would you happen to know if there should be a different approach when it comes to developing under CMR-based EJBs? The wrapper classes have inner wrapper classes — they would contain other objects.

    When I import it as a Java Bean Model together with the command bean, the input fields for the ones under the inner wrapper classes are inactive.

    Please advise.

    -Jan

    (0) 
  9. Subash Mathews Thomas
    This was a very helpfull webblog.. But I wasted a weeks time because of one simple modifications required in this blog. After following the steps carefully I was able to do an insert, update and delete to the database. But retrieving a collection object was still a problem. I would suggest to modify the blog as below so that any new user will not have any similar problems in the future.
    The call in the view controller event handler should be
    wdContext.currentEmpCommandBeanElement()
    .modelObject().getAllEmpDetails();

    and you should call the invalidate method just after it. then only the view will be populated with the result.
    wdContext.nodeEmpDetailsList().invalidate();

    So the resultant code in the event handler of the action button will be

    wdContext.currentEmpCommandBeanElement()
    .modelObject().getAllEmpDetails();
    wdContext.nodeEmpDetailsList().invalidate();

    (0) 

Leave a Reply