XEO API – Loading, Listing and Iterating

Hi

Today I’d like to showcase a bit of XEO’s API to load, list and iterate instances of XEOModels, which are really basic activities while using the API, so let’s get started:

Loading an instance

You have the following choices when loading an instance

EboContext ctx = boApplication.currentContext().getEboContext();

//Load a specific BOUI, bypasses securities
boObject.getBoManager().loadObject(ctx, "1234"); 
//Load a specific BOUI, respect securities
boObject.getBoSecurityManager().loadObject(ctx,"1234");
//Load using a BOQL Query (query must return a single result)
boObject.getBoManager().loadObject(ctx, "select Example where name = ?",new Objct[]{"name"});
//Load using the BOUI with the ObjectManager
boApplication.getDefaultApplication().getObjectManager().loadObject(ctx, boui);
//Instantiate the ManagerBean and load the object
new boManagerBean().loadObject(ctx, boui);

Be aware that usually there are two paths when loading a boObject. Using the SecurityManager (which respects security policies) and the normal Manager (which bypasses security)

For listing you can do the following:

EboContext ctx = boApplication.currentContext().getEboContext();

//Select without arguments
boObjectList.list(ctx, "select Example");
//Select with arguments
boObjectList.list(ctx, "select Example where name = ?", new Object[]{"name"});
//Select with multiple options
boObjectList.list(ctx, boql, args, page, pageSize, orderBy, fullText, letter_filter, userQuery, useSecurity, useCache);
//Select using a Builder
new boObjectListBuilder(ctx, "select Example where name = ? and other = ?").argsList("arg1","arg2").cache(false).pageSize(3).build();
//Use the builder without the new
boObjectList.builder("select Example where name = ?").arg("name").build();

Listing functions also have a parameter to apply security policies or not.

In case you want to iterate a list you do the following.

boObjectList list = boObjectList.list(ctx, "select Example");
list.beforeFirst();
while (list.next()){
	boObject current = list.getObject();
}

In case you want to iterate a collection attribute, do one of the following

bridgeHandler bridge = obj.getBridge("collection"); 
//Using a bridge handler directly
bridge.beforeFirst();
while (bridge.next()){
	boObject current = bridge.getObject();
}

//Using an "iterator"		
boBridgeIterator it = bridge.iterator();
while (it.next()){
	boObject current = it.currentRow().getObject();
}

That will be all, happy coding!

Dealing with JSF ids in CSS and Javascript (JQuery)

Hi everyone,

If you ever had the opportunity to work with JSF applications (or JSF’ish applications like XEO Applications) you may have noticed that most elements in the page have these weird ids like form:input

Imagine the following example in a XEO Application:

<xvw:form id='form'>
   <xvw:attribueText id='name' objectAttribute='username'>
</xvw:form>

The resulting HTML would create a div for the input like the following:

<div id='form:name'>
 ...
</div>

Now, if you want to use Jquery to do something to this element, you would probably do it like this:

$("#form:name")

The problem is that you can’t do this, because in Jquery selectors the colon “:” is a special character and cannot be used like this to select an id. In order for the jquery selector to work you have to escape the colon with a double backslash, like the following:

$("#form\\:name")

But that is one ugly piece of code… you can do the following to ease the pain:

$(document.getElementById('form:name'))

Document.getElementById does not interpret selector, as such there’s no problem having the colon, and since the jQuery selector accepts a DOM element, all is well. If you’re using the XEO Framework, you can do the following as well:

$(XVW.get('form:name'))

And what about CSS? 

Well with CSS the problem is the same, you cannot have the colon in identifiers, so you have to escape it, like the following:

/* Wrong */
#form:name{
 color : red;
}

/* Correct */
#form\:name{
 color : red;
}

There’s just one little problem… this doesn’t work in IE6/7 (shocking, I know). In order to have a compatible solution you need the following:

/* Correct! Compatible with IE 6/7 */
#form\3A name{
  color : red;
}

And I think this pretty much nails it 🙂 Hope it helps someone!
Happy coding!

Creating users in a XEO Application

When building any web application, one of the first requirements is to have the concept of a user who can login to the application. In order create users in a new XEO Application you can do the following:

If you only need a user without any application-specific attributes, you can use Ebo_Perf instances (a model that comes bundled with the XEO Framework). To create users, login with the SYUSER with the XEO Administration Profile and click on the “Users” menu.  It will list the current users and let you create new ones.

Now, if you want to create new users, but you want them to have application-specific attributes? XEO comes bundled with an interface iXEOUser.ixeomodel that you can implement in your models. Whenever a Model implements the iXEOUser interface its instances become a user (the iXEOUser interface provides a username and password attribute).

So, how do you implement an Interface? In Eclipse, open the Model that you want to make a user from and under the “general” section click the “edit” button. In the right pane find the implemented interfaces section and click the plus button, save and build.

Interfaces

Interfaces

After this you should probably use the Scaffolding tool to generate (or re-generate) the list/edit viewer for this Model (don’t forget to check the “Include attributes from interfaces”). Create a new instance, give it a username and password and save. Logout and login with the newly created username

Happy coding!