Skip to content

www.rolfje.com

Tapestry/OGNL: Could not find an adaptor for class XYZ

Posted on 2006-02-07 By rolfje No Comments on Tapestry/OGNL: Could not find an adaptor for class XYZ
Getting the “Could not find an adaptor for class Foo” Mesage in Tapestry? You probably forgot to make your class Serializable. A simple description of a possible problematic situation follows: 

Suppose you have some simple class, like so:

public class MyItem {
    private String itemname;

  public String getItemname() {
       return itemname;
  }
}

And somewhere in your Tapestry page or component, you iterate a list of these items to produce directlinks for each of them:

<span jwcid="@Foreach" source="ognl:myItems" value="ognl:loopItem">
  <a jwcid="@DirectLink" listener="ognl:listeners.myItemListener"
        parameters="ognl:new java.lang.Object[] {loopItem}">
      <span jwcid="@Insert" value="ognl:loopItem.itemname"/>
  </a>
</span>

In your page definition, you have created a nice listener method which you expect to be called:

public void myItemListener(IRequestCycle cycle){
  MyItem item = (MyItem)cycle.getServiceParameters()[0];

  System.out.println(
    "Hi, you have pressed the link for "
    + item.getItemname());
}

You start everything up, but when loading the page, Tapestry complains:

org.apache.tapestry.ApplicationRuntimeException:
  Could not find an adaptor for class MyItem.

… and a horrific stacktrace follows, which you can’t read or understand because it is all about AbstractComponent.renderbody and other internals of Tapestry and your webserver. Although the error is terrible, and does not point you anywhere, the fix is rather simple. You forgot to make your class Serializable! Changing it to :

public class MyItem implement Serializable {
  private String itemname;

  public String getItemname() {
    return itemname;
  }
}

fixes the problem, because now Tapestry can serialize your object into the session, and pass it as a parameter to the listener.

Software Tags:Java, programming, Tapestry

Post navigation

Previous Post: 195Nm Victory!
Next Post: Google Talk with your browser!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

           

Recent Comments

  • rolfje on Methode Buijs uitgelegd
  • LinkedIn is at Peak Enshittifaction – Will Chatham's Blog on Linked-In not really Opt-in?
  • Hans j on 1N4148 diode as RF switch
  • Roaming Rhonda on DLNA on OSX, done right
  • Frans on How to fix a Krups XN2001 Nespresso machine

Tags

Anonimatron Apple backup design DIY DRM eclipse environment Fun gmail google hacking hamradio Hardware helicopter iphone ipod iTunes Java Keynote maven modelling motorcycle music news opinion oracle osx photo photography programming repair review security Software Steve Jobs T-Mobile technology Time Machine Ubuntu usability Utilities vacation windows Workshop

Categories

  • Apple (105)
  • Divorce (1)
  • Electronics (3)
  • Fun (57)
  • Games (7)
  • Hardware (72)
  • Microsoft (18)
  • Racing (14)
  • Software (134)
  • Uncategorized (65)
  • Workshop (20)

Archives

Copyright © 2025 www.rolfje.com.

Powered by PressBook WordPress theme