`
JavaCrazyer
  • 浏览: 2991313 次
  • 性别: Icon_minigender_1
  • 来自: 河南
社区版块
存档分类

Flex4之与后台服务器通信方式:blazeDS【JAVA方式】

阅读更多

还是以那个登录例子来说,登录请求在blazeDS来看不是直接发送URL串来请求,而是通过AS代码与web-info下的

remoting-config.xml配合使用

mxml中重要代码片段

<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
 <s:RemoteObject id="myFlex" destination="mytest" result="myFlex_resultHandler(event)"  /></fx:Declarations>

 那么这个destination所指的名字就是remoting-config.xml中配置好的名称,具体内容是

 

<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service" 
    class="flex.messaging.services.RemotingService">
    <adapters>
        <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
    </adapters>

    <default-channels>
        <channel ref="my-amf"/>
    </default-channels>

<!--这个代码片段指定处理登录的具体类全限定名-->
    <destination id="mytest" >
     <properties>
        <source>com.imgold.test.Login</source>
     </properties>
     </destination>

</service>

 mxml中光有这个还不行,既然是登陆,肯定有点击发送及处理结果的方法

    下面来看下程序的点击登录按钮处理方法

  

protected function loginBtn_clickHandler(event:MouseEvent):void
{
myFlex.getUser(userName.text,passWord.text);		
}

    这个getUser方法可是JAVA后台处理类程序中的具体方法

   上面remoteObject那个result方法是处理程序返回结果的

    

protected function myFlex_resultHandler(event:ResultEvent):void
{
	str=event.result as String;
	//Alert.show(str);
	if(str=='success'){
	currentState='mainState';
	}else{
	shake.play();   
	}
}

 

其他MXML代码我上次发的那个登录示例中有

    最后就看下程序处理类的具体代码

 

public class Login {

    public String getUser(String userName,String passWord){
    	ApplicationContext 
		context = new ClassPathXmlApplicationContext("applicationContext.xml");


		UserServiceImpl sf = (UserServiceImpl) context.getBean("userService");
		User user=sf.login(userName, passWord);
		System.out.println(user);
		if(user!=null){
			return "success";
		}else{
			return "fail";
		}
    }

		
}

 

   大功告成,blazeDS最基本的示例可以运行了

    

2
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics