cancel
Showing results for 
Search instead for 
Did you mean: 

have an object as return type in a method in the WebDynproComponent

Former Member
0 Kudos

Hello together.

I've wrote an EJB in which is a method that read out a DB Table XYZ. In this EJB also are methods to search a single entry.

In my WebDynpro applixcation i have a method in the Component that access the EJB and retrive the single entry for example. In the View implemantation i call the method from the "WEbDynPro component" which have a string as return type.

Is it possible to have an object as return type?

public java.lang.String sr( int KVNR )
  {
    //@@begin sr()
    KVNummerDTO kvnrObject = new KVNummerDTO();
    String Kasse = "";
	 try 
	 {
		KVNRSessionLocal kVNummerSessionLocal = kVNRSessionLocalHome.create();
		kvnrObject = kVNummerSessionLocal.getKVNummer(KVNR);
		Kasse = kvnrObject.getKasse();
	 }
	 catch (Exception e)
	 {
		 e.printStackTrace();
		 wdComponentAPI.getMessageManager().reportException(e.getMessage(), true);
	 }
	 return Kasse;
    //@@end
  }

I want to return kvnrObject and not only a string!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Micheal,

While Creating a method in front of the return type click on the browse and select Java Native Type Radio Button and again click on the browse button available there. Type the name of the class in the class in it and you can select the return type. If it is a user made class then first the required Java files under the path Resources>src>packages><create a folder>java file. Then build the project so that the class name is visible in list while selecting the return type.

Regards,

Ardhendu

Former Member
0 Kudos

Oh yeah the java native type selct in my package was the right way thx

Former Member
0 Kudos

What ca i do , if I want to return an list of my objects? myObject[]

Former Member
0 Kudos

You could use java.util.List.

Armin

Former Member
0 Kudos

What a stupid question but:

List<MyObject> = new List<myObject>(); dosn't work?!... I don't see the error.. aaaahhhhhhhhhh

Former Member
0 Kudos

In WD release 7.0, you still have to use JDK 1.4, that means you cannot use generics. Apart from that the code should be


List list = new ArrayList();

List is only an interface and you forgot the identifier.

Armin

Former Member
0 Kudos

I have read this some minutes ago in web. .. mhh what is with a Array of my object. Whats the bist way?

If I have myobject[] a do not have to cast. If I have a ArrayList i have to cats to my object. Any tip?

Former Member
0 Kudos

You can put any object type into such a generic list. For example


List list = new ArrayList();
for (int i = 0; i < 3; ++i)
{
  MyObject obj = new MyObject();
  list.add(obj);
}
MyObject second= (MyObject) list.get(1);

Armin

Former Member
0 Kudos

Thx but this is what I know.

With a generic List I have to cast to the object which is in tne List. With an Array of my object i havn't to cast. What is better?

Former Member
0 Kudos

You can use both. If you get the list from some method it's probably a good idea to work with the list instead of copying it into an array and work with the array. And if you have to insert elements inside the list, an array is not useful.

Armin

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello Micheal,

When you select the return type of type Object in NWDS 7.1 there is Check Box available to determine whether it is a array Type. Just Check the box the return type will be array of that object. Check if same is available in NWDS 7.0

Regards,

Ardhendu

Former Member
0 Kudos

Hello Micheal,

Yes you can have an Object of return type. Just select the Java Class name while creating a return type and you can have object of that class as the return from method. Either way you can set the value to the Context Attribute of that type in the Method and the same can be used in the Other method within the Web Dynpro application.

Regards,

Ardhendu

Former Member
0 Kudos

How?

I have to declatre the method in the WebDynpor Component "method" tab. And in this i can not define an java Class object as retun type....

Former Member
0 Kudos

Maybe that was not supported in older releases (which release are you using?). Isn't there a "Browse..." button at the "Return Type" selection of your method editor?

As an alternative you could also define a context attribute of your Java native type and put the method result into that attribute. Using context mapping, a view controller can then access this value.

Armin

Former Member
0 Kudos

i work with NW 7.0 SPS19 and NWDS Version: 7.0.11

Former Member
0 Kudos
As an alternative you could also define a context attribute of your Java native type and put the method result into that attribute. Using context mapping, a view controller can then access this value.

What is the best way? Best practise?