Flex 开发架构渐变

http://www.javaeye.com/wiki/flex/1472-flex-development-framework-for-gradual-change

Flex 无疑是RIA第一位得选择,而JAVA 可以是Enterprise application 的第一选择。 结合二者来开发Web App 无疑是一种走向流行的方案。 前端Flex+后端JAVA的简单架构如图:

flex and java

在实际得开发中实现上述结构的方法非常之多。我只是将自己开发的渐变过程记录下来。希望对后来者有所借鉴。

这个系列blog包括:

一。混沌未开-Flex-all-in-one

二。中央管理-Flex Central Managerment

三。MVC框架-Flex Cairngorm

四。咔嚓Front Controller的Cairngorm

五。轮回转世-Mate

样例。

为简洁起见,用一个非常简单的样例来演示开发过程:密友列表

系统只有二个画面:

登录-LoginView:

login view

输入用户名和密码并登录, 进入密友列表画面(BuddyListView):

buddylist

由于这个系列blog焦点在Flex应用开发方式,所以只选择Remote Object 作为和后端通讯的方式。AMF的实现使用Adobe 的opensource data service-BlazeDS。Java代码非常简单。仅限于配合这个blog系列。

相关得配置文件和JAVA class 如下:

1。remot-config.xml:

Xml代码 <embed height="15" width="14" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="always" quality="high" flashvars="clipboard=%3C%3Fxml%20version%3D%E2%80%9D1.0%E2%80%B3%20encoding%3D%E2%80%9DUTF-8%E2%80%B3%3F%3E%0A%3Cservice%20id%3D%E2%80%9Dremoting-service%E2%80%9D%0A%20%20%20%20class%3D%E2%80%9Dflex.messaging.services.RemotingService%E2%80%9D%3E%0A%0A%20%20%20%20%3Cadapters%3E%0A%20%20%20%20%20%20%20%20%3Cadapter-definition%20id%3D%E2%80%9Djava-object%E2%80%9D%20class%3D%E2%80%9Dflex.messaging.services.remoting.adapters.JavaAdapter%E2%80%9D%20default%3D%E2%80%9Dtrue%E2%80%9D%2F%3E%0A%20%20%20%20%3C%2Fadapters%3E%0A%0A%20%20%20%20%3Cdefault-channels%3E%0A%20%20%20%20%20%20%20%20%3Cchannel%20ref%3D%E2%80%9Dmy-amf%E2%80%9D%2F%3E%0A%20%20%20%20%3C%2Fdefault-channels%3E%0A%20%20%20%20%3Cdestination%20id%3D%E2%80%9DflexmvcRO%E2%80%9D%3E%0A%20%20%20%20%20%3Cproperties%3E%0A%20%20%20%20%20%20%3Csource%3Ecom.ny.blog.flex.mvc.accessor.DummyAccessor%3C%2Fsource%3E%0A%20%20%20%20%20%20%3Cscope%3Esession%3C%2Fscope%3E%0A%20%20%20%20%20%20%3C%2Fproperties%3E%0A%20%20%20%20%20%3Cadapter%20ref%3D%E2%80%9Djava-object%E2%80%9D%20%2F%3E%0A%20%20%20%20%3C%2Fdestination%3E%0A%0A%3C%2Fservice%3E%0A%0A" src="http://www.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" lk_mediaid="lk_juiceapp_mediaPopup_1234751055932" lk_media="yes">
  1. <?xml version=”1.0″ encoding=”UTF-8″?>  
  2. <service id=”remoting-service”  
  3.     class=”flex.messaging.services.RemotingService”>  
  4.   
  5.     <adapters>  
  6.         <adapter-definition id=”java-object” class=”flex.messaging.services.remoting.adapters.JavaAdapter” default=”true”/>  
  7.     </adapters>  
  8.   
  9.     <default-channels>  
  10.         <channel ref=”my-amf”/>  
  11.     </default-channels>  
  12.     <destination id=”flexmvcRO”>  
  13.      <properties>  
  14.       <source>com.ny.blog.flex.mvc.accessor.DummyAccessor</source>  
  15.       <scope>session</scope>  
  16.       </properties>  
  17.      <adapter ref=”java-object” />  
  18.     </destination>  
  19.   
  20. </service>  
<?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=”flexmvcRO”> <properties> <source>com.ny.blog.flex.mvc.accessor.DummyAccessor</source> <scope>session</scope> </properties> <adapter ref=”java-object” /> </destination> </service>

2.DummyAccessor.java:

Java代码 <embed height="15" width="14" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="always" quality="high" flashvars="clipboard=package%20com.ny.blog.flex.mvc.accessor%3B%0A%0Aimport%20java.util.ArrayList%3B%0Aimport%20java.util.List%3B%0A%0Aimport%20com.ny.blog.flex.mvc.pojo.Friend%3B%0A%0Apublic%20class%20DummyAccessor%20%7B%0A%0A%20public%20DummyAccessor()%20%7B%0A%20%7D%0A%20%0A%20public%20boolean%20login(String%20userName%2CString%20password)%7B%0A%20%20return%20true%3B%0A%20%7D%0A%20%0A%20public%20%20List%3CFriend%3E%20getAllFriends(String%20userName)%7B%0A%20%20List%3CFriend%3E%20myBuddy%20%3D%20new%20ArrayList%3CFriend%3E()%3B%0A%20%20Friend%20dummy1%20%3D%20new%20Friend()%3B%0A%20%20dummy1.setFirstName(%E2%80%9DJohn%E2%80%9D)%3B%0A%20%20dummy1.setLastName(%E2%80%9DSmith%E2%80%9D)%3B%0A%20%20myBuddy.add(dummy1)%3B%0A%20%20%0A%20%20Friend%20dummy2%20%3D%20new%20Friend()%3B%0A%20%20dummy2.setFirstName(%E2%80%9DAndy%E2%80%9D)%3B%0A%20%20dummy2.setLastName(%E2%80%9DJones%E2%80%9D)%3B%0A%20%20myBuddy.add(dummy2)%3B%0A%20%20%0A%20%20Friend%20dummy3%20%3D%20new%20Friend()%3B%0A%20%20dummy3.setFirstName(%E2%80%9DMichael%E2%80%9D)%3B%0A%20%20dummy3.setLastName(%E2%80%9DNiu%E2%80%9D)%3B%0A%20%20myBuddy.add(dummy3)%3B%0A%20%20return%20myBuddy%3B%0A%20%7D%0A%0A" src="http://www.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" lk_mediaid="lk_juiceapp_mediaPopup_1234751055934" lk_media="yes">
  1. package com.ny.blog.flex.mvc.accessor;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import com.ny.blog.flex.mvc.pojo.Friend;  
  7.   
  8. public class DummyAccessor {  
  9.   
  10. public DummyAccessor() {  
  11. }  
  12.    
  13. public boolean login(String userName,String password){  
  14.   return true;  
  15. }  
  16.    
  17. public   List<Friend> getAllFriends(String userName){  
  18.    List<Friend> myBuddy = new ArrayList<Friend>();  
  19.    Friend dummy1 = new Friend();  
  20.    dummy1.setFirstName(”John”);  
  21.    dummy1.setLastName(”Smith”);  
  22.    myBuddy.add(dummy1);  
  23.     
  24.    Friend dummy2 = new Friend();  
  25.    dummy2.setFirstName(”Andy”);  
  26.    dummy2.setLastName(”Jones”);  
  27.    myBuddy.add(dummy2);  
  28.     
  29.    Friend dummy3 = new Friend();  
  30.    dummy3.setFirstName(”Michael”);  
  31.    dummy3.setLastName(”Niu”);  
  32.    myBuddy.add(dummy3);  
  33.   return myBuddy;  
  34. }  
package com.ny.blog.flex.mvc.accessor; import java.util.ArrayList; import java.util.List; import com.ny.blog.flex.mvc.pojo.Friend; public class DummyAccessor { public DummyAccessor() { } public boolean login(String userName,String password){ return true; } public List<Friend> getAllFriends(String userName){ List<Friend> myBuddy = new ArrayList<Friend>(); Friend dummy1 = new Friend(); dummy1.setFirstName(”John”); dummy1.setLastName(”Smith”); myBuddy.add(dummy1); Friend dummy2 = new Friend(); dummy2.setFirstName(”Andy”); dummy2.setLastName(”Jones”); myBuddy.add(dummy2); Friend dummy3 = new Friend(); dummy3.setFirstName(”Michael”); dummy3.setLastName(”Niu”); myBuddy.add(dummy3); return myBuddy; }

3.相关 pojo Friend.java:

Java代码
  1. public class Friend {  
  2. private String firstName;  
  3. private String lastName;  
  4. private String nickName;  
  5.   
  6. public Friend() {  
  7. }  
  8.   
  9. //getter and setters  
  10. …  
  11. }  
public class Friend { private String firstName; private String lastName; private String nickName; public Friend() { } //getter and setters … }

Lets go :混沌未开-Flex-all-in-one

说明:本人很久不打中文,速度较慢,也会词不达意。而且基本是保持英文版本的中文重写。请耐心和指正。

谈页面跳转的路由技术 | Flex 开发架构(一): 混沌未开-Flex-all ...

posted on 2009-02-16 10:22  dhj  阅读(150)  评论(0编辑  收藏  举报

导航