Getting To The Java Roots of XPages – Part 6

So we now have a java class that can be used as a bean. From a java point of view it is still just a java class, the bean bit comes into play over on the xpage side of things.

You may have heard of both managed and unmanaged beans when it comes to XPages. While there are some differences at the end of the day they both point to a java class and do pretty much the same thing. A Managed bean is basically a bean that has been given a name and scope before your xpage runs and is available from any page whereas an unmanaged bean is given it’s name and scope on a specific xpage. I’m over simplifying it for now but eventually I’ll go into more details on that.

Lets use this bean as an unmanaged bean for the moment beans need a scope to be stored in, In ssjs you know these as applicationScope, sessionScope, viewScope and requestScope. For beans there is one more scope called ‘none’ as in no scope, it is not stored and will be discarded after each use.

A quick and dirty way to setup your unmanaged bean is to add a DataContext on your Xpage, here is an example of how to do that


This is not the best way to add a bean to an xpage, it is just being used as a quick and dirty example.

Now for my link i don’t need to use ssjs. I can now use Expression Language. I just reference the unmanaged bean’s name and the method that needs to be called on it.


One thing to note is that the method in the java class is called getMyInternetAddress while the expression language version just uses myInternetAddress. It automatically adds the get and capitalizes the first letter. There is a very valid reason for this that I’ll talk about later.

In the next part, however, we will look at how to setup the java class as a managed bean instead.

Advertisements
Tagged with: ,
Posted in None
Archives
%d bloggers like this: