gpt4 book ai didi

java - 访问 Flex BlazeDS 中的 Java 对象字段

转载 作者:行者123 更新时间:2023-12-01 14:46:48 26 4
gpt4 key购买 nike

我正在使用 BlazeDS 将 Flex 与 Java 连接起来。当我尝试访问 Flex 中的 java 对象字段时遇到问题

这是我的 Java 类路径:

package intetech;

public class Path {

public Path(){

}
public Path(double x1, double y1, double x2, double y2){
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}

public double getX1(){
return x1;
}
public double getY1(){
return y1;
}
public double getX2(){
return x2;
}
public double getY2(){
return y2;
}

private double x1;
private double y1;
private double x2;
private double y2;
}

Java 类 PathsService 在 getPaths 方法中返回 Path 的 ArrayList:

package intetech;

import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class PathsService {
public PathsService(){}

public List<Path> getPaths(){
File svgFile = new File("D:\\work\\blazedsTurnkey\\blazeds-turnkey-4.0.0.14931\\tomcat\\webapps\\blazeds\\WEB-INF\\classes\\intetech\\test.svg");
try{
SvgParser svgp = new SvgParser(svgFile);
listOtr = svgp.getList();
} catch (SAXException ex) {

} catch (ParserConfigurationException ex) {

} catch (IOException ex) { }

return listOtr;
}

private static List<Path> listOtr;
}

所以我尝试从flex中的ArrayList获取一条路径的坐标。 Main.mxml:

  <fx:Declarations>
<!--setup the connection to the Java class-->
<mx:RemoteObject
id="PathsService"
destination="pathsservice"
showBusyCursor="true"
>

<mx:method name="getPaths"
result="resultGetPaths(event)"
fault="faultGetPaths(event)"/>



</mx:RemoteObject>
</fx:Declarations>



<fx:Script>
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.ObjectUtil;



private var aPath:Path ;
private var pathsArrCol:ArrayCollection;
private var otr:Path;


public function resultGetPaths(event:ResultEvent):void {

pathsArrCol = event.result as ArrayCollection;
**otr = pathsArrCol.getItemAt(0) as Path;
Alert.show(ObjectUtil.toString(otr.getX1()));**
}


private function faultGetPaths(event:FaultEvent):void{

Alert.show( ObjectUtil.toString(event.fault) );


}

</fx:Script>

和 Path.as 文件:

package
{
[RemoteClass(alias="intetech.Path")]

[Bindable]
public class Path
{

private var ax1:Number;
private var ay1:Number;
private var ax2:Number;
private var ay2:Number;




public function getX1():Number {
return ax1;
}
public function getY1():Number {
return ay1;
}
public function getX2():Number {
return ax2;
}
public function getY2():Number {
return ay2;
}



public function setX1(data:Number): void{
ax1 = data;
}
public function setY1(data:Number): void{
ax1 = data;
}
public function setX2(data:Number): void{
ax1 = data;
}
public function setY2(data:Number): void{
ax1 = data;
}

}
}

当我运行此应用程序时,我得到 NaN 结果,请帮忙

最佳答案

您的 Flex 对象中没有任何公共(public) setter/getter:

package {

[RemoteClass(alias="intetech.Path")]
[Bindable]
public class Path {

private var ax1:Number;
private var ay1:Number;
private var ax2:Number;
private var ay2:Number;

public function get x1():Number {
return ax1;
}

public function get y1():Number {
return ay1;
}

public function get x2():Number {
return ax2;
}

public function get y2():Number {
return ay2;
}

public function set x1(data:Number):void {
ax1 = data;
}

public function set y1(data:Number):void {
ay1 = data;
}

public function set x2(data:Number):void {
ax2 = data;
}

public function set y2(data:Number):void {
ay2 = data;
}

}
}

结果是 BlazeDS 无法使用 Java 中的序列化数据正确初始化新的 Flex 对象。

关于java - 访问 Flex BlazeDS 中的 Java 对象字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15364305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com