cancel
Showing results for 
Search instead for 
Did you mean: 

EJB Model Java ArrayList ->ClassCastException

Former Member
0 Kudos

Hello all,

i do have following problem in my Web Dynpro project, with included EJB model.

Following EJB Method is should be used in Web Dynpro:


public List<Qualifier> getCurrentValidQualifier(long generalContainerId, List <Long> chosenQualifierIds)

In Web Dynpro it is implemented:



Request_ContainerServiceLocal_getCurrentValidQualifier req_currentValidQ = new Request_ContainerServiceLocal_getCurrentValidQualifier(model);
	  req_currentValidQ.setGeneralContainerId((long)9101);
	  
	  List <Long> value = new ArrayList<Long>();
	  value.add((long)11351);
	  value.add((long)11352);
	  req_currentValidQ.setChosenQualifierIds(value);
	  
	  wdContext.nodeRequest_ContainerServiceLocal_getCurrentValidQualifier().bind(req_currentValidQ);

But when I deploy this I get a ClassCastException in the line:

req_currentValidQ.setChosenQualifierIds(value);

I already tested it with String, Integer and also with an Array instead of List.

Do someone know how to cast here correctly?

Best Regards

Torsten Meurer

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

could u please tell me what is the type of parameter ur method takes

req_currentValidQ.setChosenQualifierIds(value);

if u think the method above takes any of the List and subclass of the List implemention then i feel there is nothing wrong

Answers (8)

Answers (8)

Former Member
0 Kudos

Hello Pavan,

I thank you for your help,

This morning i talked to another colleague and we tested the application on her computer.

And it worked so it's seems to be something wrong somewhere else not in the Web Dynpro code.

Bye

Former Member
0 Kudos

Hello Pavan,

I thank you so much.

But in my case it's unfortunately not working like this.

Because a ArrayList<Long> is a java.util object - so Web Dynpro do not give me a model class for that.

For Long_Item I do have a model class but not for testList,

I think thats the problem in this case.

Is it so unusual to use an ArrayList as parameter in a method?

Regards

Torsten

Former Member
0 Kudos

Hi Torsten,

you must have the testList model class as per the context_and_model.JPG attachment you have sent

Regards

Pavan

Former Member
0 Kudos

Hello Pavan,

it seemed like the solution, but it's not possible to build an instance of testList directly.

it's only possible to do something like:

ITestListNode list = wdContext.nodeTestList;

list.addElement(Long_Item);

But then it's not possible to add the ITestListNode

to the node above (Request_....) so no values are given to the bean.

Best Regards

Torsten

Former Member
0 Kudos

Hi,

donot take it from the context ,

u have to create a new instance of the testList and set it to the request object in the wdInit

ex:

EmployeeData model = new EmployeeData();

Request_ViewActiveEmp modelview = new Request_ViewActiveEmp(model);

ViewActiveEmp viewmodel = new ViewActiveEmp(model);

modelview.setViewActiveEmp(viewmodel);

wdContext.nodeRequest_ViewActiveEmp().bind(modelview);

Edited by: Pavan Patil GC on Jun 26, 2008 2:22 PM

Former Member
0 Kudos

Hi Pavan,

sorry it's a bit larger, I only

added now some tesmethods and view to find the issue.

The link is working now..

Thanks a lot!

Former Member
0 Kudos

Hi

instead of

ArrayList<Long_Item> list = new ArrayList<Long_Item>();

use

testList list = new testList();

Long_Item items = new Long_Item(model);

// u can set value for items.item here

list.setLong_Item(items);

then proceed

Regards,

Pavan

Former Member
0 Kudos

Here's a link to the pictures:

Link: [https://sapmats-de.sap-ag.de/download/download.cgi?id=GBC005W8IPR0ZSSEJNA2S6IGYY6VJR5NTKP2U4HSZO3BOFS7H8]

Former Member
0 Kudos

Hello Pavan,

thanks a lot for your replies.

Sorry that i make you so much work.

I did what you recommended and changed everything to ArrayList. The Result is that I get no Error: "Model Object is not a complex type" anymore.

But when the request reaches the bean the arrayList items are still null. The size is right and when I debug the values are all right until the model is executed.

It's seems that the object values get lost somwhere in the web dynpro framework

I'll post some pictures of the EJB, model, and code in the view may be then you can see the error in once.

Former Member
0 Kudos

Hello Torsten,

If the project ur working is a dummy project (i mean ur learning project) then send it to me through mail so i can analyze and give u the solution for it,

if not then send me some screen shots of the model in wd and ejb ws vi file

so that i can help u faster in resolving ur problem

Regards

Pavan

Former Member
0 Kudos

Hello Pavan,

the EJB is expecting a normal ArrayList: List<Long>.

But normal List can not be executed from the model because of classCastException.

The Web Dynpro model created also a node Long_Item.

If i look at the properties for Node where, which should get the list, the item is described:

ReferencedProperty: xyzModel.Long_Item.item

Type: longObject

ListNode does have the description:

ModelClass: xModel.Long_Item

But if I use a list of <Long_Item> Objects - the objects are null at the EJB and in the ServerLogs it says:

Model Object is not a complex type

Regards

Torsten

Former Member
0 Kudos

Hi,

Instead of List use arraylist as below

List<Long_Item> list = new ArrayList<Long_Item>();

ArrayList<Long_Item> list = new ArrayList<Long_Item>();

and ur model is through webservice(EJB), open the EJB virtual interface and see ur arraylist in the types tab, expand the tree u will see Extending types, for that u add the Long_Item to it,

then reimoprt the model in wd project

I hope this solve the purpoes

Former Member
0 Kudos

Hello Pavan,

it seems that the method wants to have a type, the model built.

Long_item with an "item" from type long.

If i do following coding:


Long_Item item = new Long_Item(model);
	  item.setItem((long)11351);
	  List<Long_Item> list = new ArrayList<Long_Item>();
	  list.add(item);
	  req_testList.setTestList(list);

There's no classCastExcption anymore, but the EJB receives null as value.

Thanx for your help.

Best Regards.

Torsten

Former Member
0 Kudos

Hi,

can you tell me is ur EJB expecting List object of Ling_Item Elements

if yes then u have to take care at the ejb

else

ur req_testList.setTestList(XYZ); may be exepecting array of Long_Item as parameter, verify it

then create array of Long_Item object and then set it to the above method

Best Regards.

Pavan