Wednesday, April 9, 2008

Casting ArrayCollection items when using DataServices

Here's another thing I discovered along the way. When casting from an ArrayCollection in Flex 2.0 filled by the Live Cycle DataServices you cannot use the var item:Contact = Contact(collection[i]) syntax. You have to use var item:Contact = collection[i] as Contact in order to get it to cast the right object.

Here a limited example:

Flex object:
============
package object
{
[Managed]
[RemoteClass (alias="com.ds.object.Contact")]
public class Contact
{
public var id:Number;
public var firstName:String;
public var lastName:String;

public function Contact() {
super();
}
}

Java object:
============
package com.ds.object;

import java.io.Serializable;

public class Contact implements Serializable{

private long id;
private String firstName;
private String lastName;

public FlexContact() {
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

}

Assembler:
==========
public Collection<Contact> fill(List fillParameters) {
Collection<Contact> retValue = new ArrayList<Contact>();
//...fill list with Contact Objects

return retValue;
}


Mxml file:
==========
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:comp="global.mxml.CalendarItems.*"
xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="vertical"
creationComplete="initApp()">

<mx:ArrayCollection id="collection"/>

<mx:Script>
<![CDATA[
import mx.event.ListEvent;
import mx.controls.DataGrid;

private function initApp(): void{
//dataservice object ds
ds.fill(collection);
}
private function doChange(event:ListEvent): void {
var dg:DataGrid = DataGrid(event.target);
/* do not cast this using Contact(dg.selectedItem)!!*/
var contact:Contact = dg.selectedItem as Contact;
}
]]>
</mx:Script>

<mx:DataGrid dataProvider="{collection}" change="doChange(event)">
<mx:columns>
<mx:DataGridColumn headerText="Contact Id" dataField="id"/>
<mx:DataGridColumn headerText="First Name" dataField="firstName"/>
<mx:DataGridColumn headerText="Last Name" dataField="lastName"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>

Monday, April 7, 2008

ANY_HOST_CONFIGURATION error in booting

I spend a whole day trying to figure out why the Abobe LiveCycle
DataServices did not run on our Jboss 4.0.4.GA. I kept getting "Field
ANY_HOST_CONFIGURATION not found" as a ClassLoader error. It turned out
that the version of commons-httpclient.jar that ships with Jboss is an
older version that what Flex requires. As the older jar is located in
the class path of Jboss ([jboss]/server/default/lib), this older version
is used and not the jar that comes with Flex.

These steps makes the flex applications deploy:
1. Unpack flex.war from the LiveCycle DataServices
2. Stop Jboss
3. Delete commons-httpclient.jar from Jboss classpath
([jboss]/server/default/lib)
4. Copy commons-httpclient-3.0.1.jar to Jboss classpath
5. Restart Jboss
6. Deploy flex.war