cancel
Showing results for 
Search instead for 
Did you mean: 

Returning data from Ejb

Former Member
0 Kudos

Hi,

Here i am creating a J2ee application. In this we accessing BAPIs in stateless session bean using JCO.Now the BAPI is returning the return Table and return Structure to the EJB.

I am coding the following code in one of the Ejb Method as follows:

<b>JCO.Table returnTable = null;

JCO.Structure returnStructure = null;

JCO.ParameterList paramList = siteBAPI.getExportParameterList();

JCO.ParameterList paramList2 = siteBAPI.getTableParameterList();

returnTable = paramList2.getTable("SITE_SUBSITE_INSTL");

returnStructure = paramList.getStructure("BAPIRET2");</b>

Now i want to sent this data( returnTable & returnStructure) to front end application where front end developer accessing this returned data using Jsp.

My scenario is that , first i want to convert this returnTable & returnStructure in a single collection and then return this collection.

My aim is that at the front end the application should not receive the Data, using JCO.table Variable but as Collection

I am using NWDI-2004s sps10.

i need urgent help on this issue and i would really appreciate if somebody can put the answer with some sample code.

Accepted Solutions (1)

Accepted Solutions (1)

former_member193726
Active Participant
0 Kudos

Hi Bimalendu,

As you are trying to pass the Table and the Structure in the form of collection to the JSP page, you can create a javabean with the structure similar to that of the table/Structure.

Lets assume you have a table called Employee with Emp_Name, Emp_Age, Emp_Sal as three columns, create a java class by name Employee which implements Serializable and attributes as Emp_Name, Emp_Age and Emp_Sal. Generate the setters and getters for the same. In your EJB code, create an instance of this Employee class and set the attributes and save it in a HashMap in the form of key value pair, Value being your Employee class instance and key be your Employee Name. Return the HashMap in your EJB code.

Use the HashMap in your JSP. Get the Iterator for the HashMap and Loop through the keys to get the values.

Hope this helps.

Regards,

Rekha Malavathu

Former Member
0 Kudos

Hi Rekha,

Thanks a lot for your answer. It's has been very helpful .

But i have an query that you have mentioned to sent the Hashmap to the Jsp code .

<b>Here my questions is why do i need to sent the Hashmap?

cann't i sent the instance of the employee class(i.e. java bean ) to access my required data?</b>

Is there any advantage of returning the Hashmap instead of instance of Java Bean?

kindly reply as soon as possible with your valuable explanation.

Former Member
0 Kudos

Hi,

I agree to Rekha, but to generalize this we can implement a table model with JCO.Table as parameter to the constructor. Retrieve the columns using table.fields() method, column values using table.getString(field), store the details in a Vector and pass to the front end.

Hope this helps.

Regards,

Sunil.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Bimalendu,

I assume that the JCO.Table and the JCO.Structure is not a single instance. If that was the case then we would have gone for a Javabean. As it is a table with multiple instances it will be good if we use HashMap. With a single instance of HashMap you may loop through and get the entire list of data.

Regards,

Rekha Malavathu

Former Member
0 Kudos

Hi,

I agree with Rekha.

if there can be multiple instance of employees at any point of time then the options is to return the collection else passing on the employee class instance.

Regards,

Nitin