# Error in findAdapter() ?!?

**URL:** <https://techcommunity.softwareag.com/t/error-in-findadapter/57122>\
**Category:** Forum\
**Tags:** Former-Crossvision-Products, Application-Composer\
**Created:** [December 19, 2005, 3:15pm UTC](https://techcommunity.softwareag.com/t/error-in-findadapter/57122 "2005-12-19T15:15:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Bauer](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@Martin\_Bauer](https://techcommunity.softwareag.com/u/Martin_Bauer)\
**Post date:** [December 19, 2005, 3:15pm UTC](https://techcommunity.softwareag.com/t/error-in-findadapter/57122/1 "2005-12-19T15:15:24Z")

</div>

Hi folks,

having the following code (in an adapter-class called “SOAMaint1”):

```
public void onCheck()   
{
            
    
    SOAMaint1 meinAdapter = (SOAMaint1) findAdapter(SOAMaint1.class,this.findSessionId());
    System.err.println(" *****************");
	System.err.println(this.toString()+" ist meine ObjektInstanz");
	System.err.println(this.getClass().getName()+" wurde gerade neu erzeugt !");
	System.err.println(this.findSessionId()+" ist die verwendete SessionID");
    System.err.println(" ********---------------*********");
    System.err.println(meinAdapter.toString()+" ist die ermittelte ObjektInstanz ");
	System.err.println(meinAdapter.getClass().getName()+" ist die ermittelte Klasse!");
	System.err.println(meinAdapter.findSessionId()+" ist die verwendete SessionID ");        
	   System.err.println(" *****************");
       
}

```

I’ll get this output:

* * *

SOAMaint1@1631573 ist meine ObjektInstanz  
SOAMaint1 wurde gerade neu erzeugt !  
CASA1\_1134985173706 ist die verwendete SessionID  
**---------------** \*  
SOAMaint1@119db9e ist die ermittelte ObjektInstanz  
SOAMaint1 ist die ermittelte Klasse!  
CASA1\_1134985173706 ist die verwendete SessionID

* * *

In other words: I will get for each call to findAdapter a new instance of  
the wanted class !!!

Of course this piece of code is sensless, but if i call this findAdpater in another class it will behave as this.

---

<div class="post-metadata">

**Author:** ![Bjoern\_Mueller](https://avatars.discourse-cdn.com/v4/letter/b/e9bcb4/32.png) [@Bjoern\_Mueller](https://techcommunity.softwareag.com/u/Bjoern_Mueller)\
**Post date:** [December 20, 2005, 9:58pm UTC](https://techcommunity.softwareag.com/t/error-in-findadapter/57122/2 "2005-12-20T21:58:12Z")

</div>

Hi Martin,

a 1:1 translation of what you do from German to English could be: the way you shout into the forest is the way the forest shouts at you! 😉

The second parameter of findAdapter (the one following the class) is the “adapterId”: a session is subdivided into sub-sessions (typically done by the workplace). Inside a sub-session you typically have one adapter object per adapter class - but you might also have multiple, each one separated by the “adapterid”. In all page operations (e.g. findAdapter(), switchToPage()…) you - if using the adapterid - have to clearly specify the id.

In your scenario you specify the session-id of the current adapter to be used as adapterid of the other adapter. The adapter will be created in the same session, the same sub-session, but as different adapter object (because of different adapterid).

Only use adapterid’s when you really have good reason to do it, i.e. if you want to explicitly define two adapter objects (of same class) inside one sub-session. In “normal” scenarios use findAdapter(class) instead of findAdapter(class,adapterid).

Hope, this helps…

Bjoern

---

<div class="post-metadata">

**Author:** ![Martin\_Bauer](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@Martin\_Bauer](https://techcommunity.softwareag.com/u/Martin_Bauer)\
**Post date:** [December 21, 2005, 1:33pm UTC](https://techcommunity.softwareag.com/t/error-in-findadapter/57122/3 "2005-12-21T13:33:11Z")

</div>

Hi,

first of all: you are right but it does not help us.

The original problem was using findAdapter(\*.class) from another CAI-Adapter-Class. There we get allways not the expected instance back.

Imagine the following case:

User calls via workplace a page (-\> SOAMaint1.class). After using this page the user navigates through the workplace-menu to another topic  
and calls again another page (-\> Report1.class)

In the SOAMain1.class the following code was placed and were executed by a button-klick-event:

public int onCheck()  
{   
System.err.println(this.toString()+" ist die aktive ObjektInstanz “);  
System.err.println(this.getClass().getName()+” ist die aktive Klasse!");

```
}

```

In the Report1.class the following code was placed:

public void init() {   
SOAMaint1 meinAdapter = (SOAMaint1) findAdapter(SOAMaint1.class);   
System.err.println(meinAdapter.toString()+" ist die ermittelte ObjektInstanz “);  
System.err.println(meinAdapter.getClass().getName()+” ist die ermittelte Klasse!");  
}

The answer on command-line was:

SOAMaint1@b83be0 ist die aktive ObjektInstanz  
SOAMaint1 ist die aktive Klasse!  
SOAMaint1@7787a5 ist die ermittelte ObjektInstanz  
SOAMaint1 ist die ermittelte Klasse!

The problem exist as you can see. we expect to stay in the same session but if we try to obtain the automatically build adapter (SOAMain1.class) we get a complete new object … having not the values set we nedd to process … urrrgggssssss…

---

<div class="post-metadata">

**Author:** ![Martin\_Bauer](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@Martin\_Bauer](https://techcommunity.softwareag.com/u/Martin_Bauer)\
**Post date:** [December 21, 2005, 4:43pm UTC](https://techcommunity.softwareag.com/t/error-in-findadapter/57122/4 "2005-12-21T16:43:47Z")

</div>

Hi,

after reading the fucking manual i got my error. Using the workplace leads always to a new subsession, and this means a new adapter is created …

cu martin

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:38pm UTC](https://techcommunity.softwareag.com/t/error-in-findadapter/57122/5 "2021-04-02T14:38:25Z")

</div>


