Thursday, February 7, 2008

Mapping AS objects to Server-Side Java Objects

Such mappings can be useful when you are using a value object ie an object containing values.

AS class:
/*we mark a class we want to map with RemoteClass tag. alias is the exact location of the class*/
package valueObjects
{
[RemoteClass(alias="valueObjects.SampleVo")]
public class SampleVo{
public var val1:String = "val1";
public var num1:int = 1;

public function getServerVal(obj:SampleVo):SampleVo{
return new SampleVo();
}
}
}

Java class (you will have to configure it as a remote object):
package valueObjects;

public class SampleVo {
public String val1 = "val2";
public int num1 = 2;

public SampleVo getServerVal(SampleVo obj){
return new SampleVo();
}
}

If you have this, you can do this in flex while handling result on calling getServerVal function:
var vo:SampleVo = event.result as SampleVo;
resultTxt.text = vo.val1+vo.num1;

No comments: