cancel
Showing results for 
Search instead for 
Did you mean: 

EJB and WebDynrpo

Former Member
0 Kudos

Hi, How can I do to retreive my Session Beans from a WebDynpro View?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Pablo,

The following links will help you:

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/webdynpro/us... ejbs in web dynpro applications.pdf

Best Regards,

Nibu.

Answers (2)

Answers (2)

former_member335005
Participant
0 Kudos

Hi Pablo,

I'll explain it to you using an example. Lets say the name of the session bean that you want to retrieve is QuickOrderProcessorBean. This is a part of the sample Quick Car Rental Application. This bean has 3 methods, namely,

viewActiveBookings(),

saveBooking(), and

cancelBooking().

We will be calling these methods from our WebDynpro Application.

Follow these steps:

1. Create a new Webdynpro Project

2. To resolve bean classes at design time, add a project reference to QuickCarRentalEJB to the Java Build Path in Project Properties.

3. To resolve bean classes at runtime, add a sharing reference named “sap.com/QuickCarRentalApplication” to the Web Dynpro Reference in the project properties.

4. In the wdDoInit() of the view, add the following lines:

try {

InitialContext ctx = new InitialContext();

QuickOrderProcessorLocalHome localHome =

(QuickOrderProcessorLocalHome) ctx.lookup(

"localejbs/sap.com/QuickCarRentalApplication/QuickOrderProcessorBean");

QuickOrderProcessorLocal local = localHome.create();

QuickBookingModel[] result = local.viewActiveBookings();//HERE WE ARE CALLING THE METHOD OF THE SESSION BEAN

} catch (Exception e) {

wdComponentAPI.getMessageManager().reportException(

"exception is : " + e.toString(),

true);

e.printStackTrace();

}

The context should be defined accordingly and mapped to the UIElement.

5. Build, Deploy and Run the application.

Hope this helps.

Regards,

Sangeeta

Former Member
0 Kudos

Perfect, thank you so much for your help. It is working now, but I would like to tell some hints just in case that some body read this.

1. I prefered NOT to USE the JavaBean Model Importe from WebDynpro: it is very complex and there is no enough documentation, unless you are using very simple types (string, int, etc) and not more complex classes (Lists, Iterators other Beans) because you will have to deal with the mapping and the relations. I found it easier to deal with the code than with the SAP Documentation.

2. When you create the EJB and EAR, use the default setting, otherwise your beans or information will be stored in a place which you will never find.

3. Use the Visual Administrator to find the JNDI name of your EJB's ( Under JNDI Registry and EJB Container).

4. Follow the links showed above, there are VERY HELPFUL.

Regards.

Amey-Mogare
Contributor
0 Kudos

Hi Sangeeta / Pablo,

Thanks alot for that perfect explanation..

I am not able to perform Step No.-3 !!! When I am trying to add Sharing reference, i am not able to understand what string to enter in there??

I have created a EJB DC and J2EE Application DC as EAR for it. Can you please tell me where do i get this sharing reference?

And about JNDI String, what is to be entered there?

Moreover, When I am trying to build the web dynpro DC, it is failing. It is unable to resolve imports for session beans, DTOs.

Pls help.

Thanks and regards,

Amey Mogare

Former Member
0 Kudos

Hi Pablo,

Write following code to lookup your ejb from webdynpro application.

initialcontext ctx = new initialcontext();

<EJB remote interface name> bean = (<EJB remote interface name>) ctx.lookup("EJB JNDI name");

<EJB bean name> ejb = bean.create();

Now, to call your business method of EJB write following line of code:

ejb.<business method>();

You also need to make sharing reference for your EJB in properties of webdynpro project.

Regards,

Bhavik