XPages – Passing Managed Beans as parameter

I ‘m currently working on an XPages project where I’m using Managed Beans and POJO’s to keep the code structured.

In one of my Java classes I had to retrieve Lotus Notes data.  When you define this class as a Managed Bean (MB) you can pass XPages global objects as parameter using Expression Language e.g. a Notes Session:  #{session}.

Define your MB as follows in faces-config.xml

<managed-bean>
     <managed-bean-name>bo</managed-bean-name>
     <managed-bean-class>invoice.BO</managed-bean-class>
     <managed-bean-scope>request</managed-bean-scope>
     <managed-property>
          <property-name>session/property-name>
          <value>#{session}</value>
     </managed-property>
</managed-bean>
Note
– The scope of your Managed Bean can’t be higher than the scope of the MB you pass as a parameter. The scope of session is request so the scope of bo must be request too.
 
The property name of the parameter is session. To have it set in you MB you have to define a setter setSession(Session session):
@SuppressWarnings("serial")
public class BO implements Serializable, Manageable {
     private Database session;
     private Database db;
     private View v;
     private Document doc;

     public void setDb(Session session) {
          this.session = session;
     }

     // Other methods

}

I’m not 100% sure but I believe I don’t have to recycle the Notes objects because session and it descendents are recycled by XPages itself.

 
For more information please see: .http://goo.gl/rUqKwW
 
Comments
6 Responses to “XPages – Passing Managed Beans as parameter”
  1. I’ve never used the parameter stuff. I don’t get the use cases for that functionality at all. I know Russ Maher has talked about that before in some presentations but again it’s not clicked with me yet. I’ve just never needed them.

    That being said, I absolutely think you DO need to recycle lotus objects from Java/managed beans. No one has ever said it’s not needed. Even the documentation for old Java agents included recycle() calls. The OpenNTF API – which is made by much smarter people to me has a lot of code designed to recycle those objects for you. That’s really why that project started I think. So they obviously feel like things should be recycled.

    I use the OpenNTF API these days and it takes care of the recycling for me. If I didn’t use that I would be recycling everything as soon as I’m done with it. Often times it might not matter – But loops especially can kill your server. Oh and dates also. Since they come from the session so they live much longer then you might think.

  2. Rob Bontekoe zegt:

    I was hoping for these kind of reactions.

    I’m still doubting. Because session, database and so on are also Managed Beans in XPages there should be some internal mechanism that recycle them after each request. And according to Domino the documentation (but not particular XPages) when you recycle them also their descendents are recycled. Who could we ask David?

    • Mark Leusink zegt:

      You should never recycle the session or database object. Only worry about recycling in loops: that’s were you can run into trouble.

      This gives some more insights into the subject of recycling: http://www.intec.co.uk/the-perils-of-getcolumnvalues-get0/

      Instead of passing the session in as a bean parameter, you can also get it using ExtLibUtil.getCurrentSession() (assuming the ExtLib is installed; if it’s not, you need to ‘resolve’ the session variable yourself in Java).

      (BTW: I assume that the first line in your BO class should read private Session session)

      • Rob Bontekoe zegt:

        Thanks Mark. Sure, I use the session to create handles to other databases to retrieve documents. I will publish more about what I’m doing with XPages en Java.

  3. How does the code NOT fail with putting a Session object in a Database type variable?
    private Database session;
    public void setDb(Session session) {
    this.session = session;
    }

Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen.

WordPress.com logo

Je reageert onder je WordPress.com account. Log uit / Bijwerken )

Twitter-afbeelding

Je reageert onder je Twitter account. Log uit / Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit / Bijwerken )

Google+ photo

Je reageert onder je Google+ account. Log uit / Bijwerken )

Verbinden met %s

%d bloggers op de volgende wijze: