Flex 无疑是RIA第一位得选择,而JAVA 可以是Enterprise application 的第一选择。 结合二者来开发Web App 无疑是一种走向流行的方案。 前端Flex+后端JAVA的简单架构如图:
在实际得开发中实现上述结构的方法非常之多。我只是将自己开发的渐变过程记录下来。希望对后来者有所借鉴。
这个系列blog包括:
一。混沌未开-Flex-all-in-one
二。中央管理-Flex Central Managerment
三。MVC框架-Flex Cairngorm
四。咔嚓Front Controller的Cairngorm
五。轮回转世-Mate
样例。
为简洁起见,用一个非常简单的样例来演示开发过程:密友列表
系统只有二个画面:
登录-LoginView:
输入用户名和密码并登录, 进入密友列表画面(BuddyListView):
由于这个系列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">
- <?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">- 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代码- 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 ...