Hi Josh,
you should use the automatic mapping between Java ValueObjects and
ActionScript ValueObjects. For that your ActionScript VO should look
like this:
/***
AS class
***/
// ActionScript Document
class Person {
var name:String;
var birthdate:String;
public static var registeredClass:Boolean =
Object.registerClass("[full path in WEB-INF / java class name]",Person);
}
Don't use a constructor in the AS VO, the constructor is called AFTER
FLEX filled the attributes from the Java VO.
Your MXML file could look like this:
/***
MXML File
***/
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:RemoteObject id="peopleObject" source="People">
<mx:method name="getPerson"
result="handleResults(event.result)"/>
</mx:RemoteObject>
<mx:Script>
<![CDATA[
import Person;
var my_person:Person;
function handleResults(event){
my_person = event.result;
}
]]>
</mx:Script>
<mx:Panel width="800" height="600">
<mx:HBox>
<mx:Form>
<mx:FormItem label="Person name">
<mx:Label text="{my_person.name}" />
</mx:FormItem>
<mx:FormItem label="birthday">
<mx:Label text="{my_person.birthdate}" />
</mx:FormItem>
</mx:Form>
<mx:Button label="Get Person"
click="{peopleObject.getPerson()}" />
</mx:HBox>
</mx:Panel>
</mx:Application>
I coded everything in my mail app, so I'm not totally shure if the code
runs at once.
Greetings
Christoph
Josh Noland wrote:
> I am having trouble accessing any Java objects that return something
> other
> than the Java types flex will implicitly convert. I am using the
> RemoteObject tag. The first time I try to access the result from the pojo
> function call I get "Error:
> org/apache/commons/collections/FastHashMap" in
> the JRun console. Each successive call will throw "Error: null". I am
> using JRun4.
>
> The code is below. I have stripped all of the functionality to try
> and get
> rid of the error and to try to get Flex to recognize my remote object
> returned.
>
> For now all I want to do is successfully call the function that
> returns my
> person and display one of the fields from the object.
>
> Has anybody else experienced this type of problem?
>
> Josh
>
>
>
>
> /****
> Java Class I am trying to use in Flex
> ****/
> public class Person implements Serializable {
>
> private String name;
> private String birthdate;
>
> public Person (){
> }
>
> public Person (String name, String birthdate) {
> this.name = name;
> this.birthdate = birthdate;
> }
>
> public void setName(String name) {
> this.name = name;
> }
>
> public String getName() {
> return name;
> }
>
> public void setBirthdate(String birthdate) {
> this.birthdate = birthdate;
> }
>
> public String getBirthdate() {
> return birthdate;
> }
> }
>
>
> /*****
> Java Function Call that returns an Object to Flex and resides in People
> Object
> *****/
> public Person getPerson(){
> return new Person("Josh", "8/8/2005");
> }
>
> /***
> MXML File
> ***/
> <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
>
> <mx:RemoteObject id="peopleObject" source="People">
> <mx:method name="getPerson"
> result="handleResults(event.result)"/>
> </mx:RemoteObject>
>
> <mx:Script>
> <![CDATA[
> function handleResults(eventResult){
> var p1:Person = new
> Person(eventResult.getProperty('name'),
> eventResult.getProperty('birthdate'));
> }
> ]]>
> </mx:Script>
>
> <mx:Panel width="800" height="600">
> <mx:HBox>
> <mx:Button label="Get Person"
> click="{peopleObject.getPerson()}" />
> </mx:HBox>
> </mx:Panel>
> </mx:Application>
>
> /***
> AS class
> ***/
> // ActionScript Document
> class Person implements DataProvider{
> var name:String;
> var birthdate:String;
>
> function Horse(myName:String, myBirthdate:String){
> this.name = myName;
> this.birthdate = myBirthdate;
> }
>
> function getName(){
> return(name);
> }
> function getBirthdate(){
> return(birthdate);
> }
> }
>
>
>
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
>
>
>
> SPONSORED LINKS
> Computer software testing
> <http://groups.yahoo.com/gads?t=ms&k=Computer+software+testing&w1=Computer+software+testing&w2=Macromedia+flex&w3=Development&w4=Software+developer&c=4&s=93&.sig=kh2CguJwmatU5oBXjFo9Rg>
>
> Macromedia flex
> <http://groups.yahoo.com/gads?t=ms&k=Macromedia+flex&w1=Computer+software+testing&w2=Macromedia+flex&w3=Development&w4=Software+developer&c=4&s=93&.sig=dAUcEV7do91-wrRtVS641g>
>
> Development
> <http://groups.yahoo.com/gads?t=ms&k=Development&w1=Computer+software+testing&w2=Macromedia+flex&w3=Development&w4=Software+developer&c=4&s=93&.sig=AlxNUQBOI7Io7S7nhmxV0Q>
>
>
> Software developer
> <http://groups.yahoo.com/gads?t=ms&k=Software+developer&w1=Computer+software+testing&w2=Macromedia+flex&w3=Development&w4=Software+developer&c=4&s=93&.sig=QWIit8JayomoIHLVkV3FDg>
>
>
>
>
> ------------------------------------------------------------------------
> YAHOO! GROUPS LINKS
>
> * Visit your group "flexcoders
> <http://groups.yahoo.com/group/flexcoders>" on the web.
>
> * To unsubscribe from this group, send an email to:
> [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>
>
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/>.
>
>
> ------------------------------------------------------------------------
>
--
****************************************
Christoph Guse
Löhstraße 34
41747 Viersen
Tel. 0 21 62 / 50 24 066
Mobil 01 72 / 160 74 84
VoIP 0 12 12 / 39 64 48 831
****************************************
------------------------ Yahoo! Groups Sponsor --------------------~-->
<font face=arial size=-1><a
href="http://us.ard.yahoo.com/SIG=12hocnclq/M=362329.6886308.7839368.1510227/D=groups/S=1705007207:TM/Y=YAHOO/EXP=1123500869/A=2894321/R=0/SIG=11dvsfulr/*http://youthnoise.com/page.php?page_id=1992
">Fair play? Video games influencing politics. Click and talk back!</a>.</font>
--------------------------------------------------------------------~->
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/