`
shihuan830619
  • 浏览: 574306 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Flex Java Spring

    博客分类:
  • Flex
阅读更多
Flex 对Java端返回Collection的处理方法
将Flex与Spring集成后(BlazeDS 与Spring集成指南 ),第一个面临的问题就是:对于Java端返回的各种Java类型的对象,Flex中能否有相应的数据类型来映射。

处理,尤其是List、Set、Map及POJO对象值。

    在 BlazeDS 与Spring集成指南 例子的基础上,调整相关的测试代码如下:
1、Java端
1.1、com.yeeach.HelloWorldService:
package com.yeeach; 

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.HashSet; 
import java.util.List; 
import java.util.Map; 
import java.util.Set; 

public class HelloWorldService { 
    public String hello(String var1) { 
        return "hello " + var1; 
    } 
    public String world(String var1) { 
        return "world " + var1; 
    } 
    public Map<String,List<String>> getMap() { 
        ArrayList<String> list1=new ArrayList<String>(); 
        list1.add("value11"); 
        list1.add("value12"); 
        list1.add("value13"); 
        ArrayList<String> list2=new ArrayList<String>(); 
        list2.add("value21"); 
        list2.add("value22"); 
        list2.add("value23"); 
        ArrayList<String> list3=new ArrayList<String>(); 
        list3.add("value31"); 
        list3.add("value32"); 
        list3.add("value33");        
        HashMap<String,List<String>> map=new HashMap<String,List<String>>(); 
        map.put("key1", list1); 
        map.put("key2", list2); 
        map.put("key3", list3);        
        return map; 
    } 
    public ArrayList<Person> getList() { 
        ArrayList <Person> list=new ArrayList<Person>(); 
        Person p1=new Person(); 
        p1.setName("name1"); 
        p1.setPass("pass1"); 
        Person p2=new Person(); 
        p2.setName("name2"); 
        p2.setPass("pass2"); 
        Person p3=new Person(); 
        p3.setName("name3"); 
        p3.setPass("pass3"); 
        list.add(p1); 
        list.add(p2); 
        list.add(p3); 
        return list; 
    } 
    public Set<Person> getSet() { 
        HashSet<Person>  set=new HashSet<Person>(); 
        Person p1=new Person(); 
        p1.setName("name1"); 
        p1.setPass("pass1"); 
        Person p2=new Person(); 
        p2.setName("name2"); 
        p2.setPass("pass2"); 
        Person p3=new Person(); 
        p3.setName("name3"); 
        p3.setPass("pass3"); 
        set.add(p1); 
        set.add(p2); 
        set.add(p3); 
        return set; 
    }    
} 

1.2、com.yeeach.Person
package com.yeeach; 

public class Person { 

        public String getName() { 
            return name; 
        } 
        public void setName(String name) { 
            this.name = name; 
        } 
        public String getPass() { 
            return pass; 
        } 
        public void setPass(String pass) { 
            this.pass = pass; 
        } 
        private String name; 
        private String pass; 

}

2、Flex 端
2.1、helloworld.mxml:
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                layout="vertical"> 
    <mx:RemoteObject destination="test1" 
                     id="test1"> 
        <mx:method name="hello" 
                   result="sayHelloResult(event)"/> 
        <mx:method name="world" 
                   result="sayWorldResult(event)"/> 
        <mx:method name="getMap" 
                   result="getMapResult(event)"/> 
        <mx:method name="getList" 
                   result="getListResult(event)"/> 
        <mx:method name="getSet" 
                   result="getSetResult(event)"/> 
    </mx:RemoteObject> 
    <mx:HBox> 
        <mx:Label text="输入:"/> 
        <mx:TextInput id="inputStr"/> 
        <mx:Button label="say hello" 
                   click="sayHello(event);"/> 
        <mx:Button label="say world" 
                   click="sayWorld(event);"/> 
        <mx:Button label="get map" 
                   click="test1.getMap()"/> 
        <mx:Button label="get list" 
                   click="test1.getList()"/> 
        <mx:Button label="get set" 
                   click="test1.getSet()"/>                   
    </mx:HBox> 
    <mx:HBox> 
        <mx:Label text="结果:"/> 
        <mx:TextArea id="result"/> 
    </mx:HBox> 

    <mx:Script> 

        <![CDATA[ 
            import mx.collections.ArrayCollection; 
            import mx.rpc.events.FaultEvent; 
            import mx.controls.Alert; 
            import mx.rpc.events.ResultEvent; 
            import com.yeeach.Person; 
            [Bindable] 
            public var person:Person; 
            [Bindable] 

            public var map:ArrayCollection=null; 

            function sayHello(event:Event):void 
            { 
                var inputVar:String=inputStr.text; 
                test1.hello(inputVar); 

            } 

            function sayWorld(event:Event):void 
            { 
                var inputVar:String=inputStr.text; 
                test1.world(inputVar); 

            } 

            private function sayHelloResult(event:ResultEvent):void 
            { 
                result.text=event.result.toString(); 
                Alert.show(event.result.toString(), "返回结果"); 
            } 

            private function sayWorldResult(event:ResultEvent):void 
            { 
                result.text=event.result.toString(); 
                Alert.show(event.result.toString(), "返回结果"); 
            } 

            private function getMapResult(event:ResultEvent):void 
            { 
                for (var key:String in event.result) 
                { 
                    var list:ArrayCollection=event.result[key] as ArrayCollection; 
                    for (var key1:Object in list) 
                    { 
                        Alert.show("map item key is: " + key + " value is: " + key1); 
                    } 

                } 
            } 

            private function getList():void 
            { 
                test1.getList(); 
            } 

            private function getListResult(event:ResultEvent):void 
            { 
                var ac:ArrayCollection=event.result as ArrayCollection; 
                for (var i:int=0; i < ac.length; i++) 
                { 
                    var p1:Person=ac.getItemAt(i) as Person; 
                    Alert.show("list item name is: " + p1.name+" \n another usage : "+ac.getItemAt(i).name); 
                } 

            } 
            private function getSet():void 
            { 
                test1.getSet(); 
            } 

            private function getSetResult(event:ResultEvent):void 
            { 
                var ac:ArrayCollection=event.result as ArrayCollection; 
                for (var i:int=0; i < ac.length; i++) 
                { 
                    var p1:Person=ac.getItemAt(i) as Person; 
                    Alert.show("set item name  is: " + p1.name); 
                } 

            }            
        ]]> 
    </mx:Script> 
</mx:Application>

2.2、com.yeeach.Person.as:
package com.yeeach 
{ 
    [Bindable] 
    [RemoteClass(alias="com.yeeach.Person")] 
    public class Person 
    { 
        public var name:String; 
        public var pass:String; 
    } 
}

3、总结:
    1、JavaBean从Java端返回给Flex,可以通过Flex的Meta Tag [RemoteClass (alias=” “)]来标识服务器端对应的Java的类(一般为POJO对象)。

注意位置,是在class声明前。

    2、Java Collection返回给Flex,都可以通过转化为mx.collections.ArrayCollection来进行处理。

    3、Flex对于服务器端返回的java其他类型的处理,相对简单,可以参考

http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_4.html

BlazeDS 与Spring集成指南:
Springsource与Adobe合作发布了Spring与BlazeDS集成的项目Spring BlazeDS Integration,通过Spring BlazeDS Integration可以把Spring的Bean暴露为BlazeDS的Flex Remoting Service,这样Flex客户端就能够通过AMF调用Spring 暴露出来的Bean,有效简化BlazeDS配置及开发难度。

1、配置好BlazeDS的开发环境
参考“使用BlazeDS实现Java和Flex通信之hello world ”中的环境搭建过程,配置BlazeDS的开发环境。

创建com.yeeach.HelloWorldService,内容如下:
package com.yeeach; 

public class HelloWorldService { 
    public String hello(String var1) { 
        return "hello " + var1; 
    } 
    public String world(String var1) { 
        return "world " + var1; 
    } 
}

2、下载Spring BlazeDS Integration 1.0、Spring、jackson包
http://s3.amazonaws.com/dist.springframework.org/release/FLEX/spring-flex-1.0.0.RELEASE-with-dependencies.zip

http://s3.amazonaws.com/dist.springframework.org/release/SPR/spring-framework-2.5.6.SEC01-with-dependencies.zip

http://jackson.codehaus.org/0.9.4/jackson-asl-0.9.4.jar

放入到flex-spring/WebRoot/WEB-INF/lib

3、修改web.xml,内容如下:
<?xml version="1.0" encoding="UTF-8"?> 

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> 

<web-app> 
    <display-name>Spring BlazeDS Integration Samples</display-name> 
    <description>Spring BlazeDS Integration Sample Application</description> 

    <!– Http Flex Session attribute and binding listener support –> 
    <listener> 
        <listener-class>flex.messaging.HttpFlexSession</listener-class> 
    </listener> 

    <!– The front controller of this Spring Web application, responsible for handling all application requests –> 
    <servlet> 
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
        <init-param> 
            <param-name>contextConfigLocation</param-name> 
            <param-value> 
                   classpath:/applicationContext*.xml 
                classpath*:/applicationContext.xml 
                /WEB-INF/applicationContext*.xml 
            </param-value> 
        </init-param> 
        <load-on-startup>1</load-on-startup> 
    </servlet> 
    <!– Map all *.spring requests to the DispatcherServlet for handling –> 
    <servlet-mapping> 
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
        <url-pattern>/spring/*</url-pattern> 
    </servlet-mapping> 

    <welcome-file-list> 
        <welcome-file>index.htm</welcome-file> 
    </welcome-file-list> 

</web-app>

4、修改flex/services-config.xml,内容如下:
<?xml version="1.0" encoding="UTF-8"?> 
<services-config> 

    <services> 
        <service-include file-path="remoting-config.xml" /> 
        <service-include file-path="proxy-config.xml" /> 

        <!– 
        Application level default channels. Application level default channels are 
        necessary when a dynamic destination is being used by a service component 
        and no ChannelSet has been defined for the service component. In that case, 
        application level default channels will be used to contact the destination. 
        –>   
        <default-channels> 
           <channel ref="my-amf"/> 
        </default-channels> 
    </services> 

    <channels> 
        <channel-definition id="my-streaming-amf" class="mx.messaging.channels.StreamingAMFChannel"> 
            <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/streamingamf" class="flex.messaging.endpoints.StreamingAMFEndpoint"/> 
        </channel-definition> 
        <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"> 
            <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/> 
            <properties> 
                <polling-enabled>false</polling-enabled> 
            </properties> 
        </channel-definition> 

        <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel"> 
            <endpoint url="https://{server.name}:{server.port}/{context.root}/spring/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/> 
            <properties> 
                <add-no-cache-headers>false</add-no-cache-headers> 
            </properties> 
        </channel-definition> 

        <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel"> 
            <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/> 
            <properties> 
                <polling-enabled>true</polling-enabled> 
                <polling-interval-seconds>4</polling-interval-seconds> 
            </properties> 
        </channel-definition> 

        <channel-definition id="my-http" class="mx.messaging.channels.HTTPChannel"> 
            <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/http" class="flex.messaging.endpoints.HTTPEndpoint"/> 
        </channel-definition> 

        <channel-definition id="my-secure-http" class="mx.messaging.channels.SecureHTTPChannel"> 
            <endpoint url="https://{server.name}:{server.port}/{context.root}/spring/messagebroker/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/> 
            <properties> 
                <add-no-cache-headers>false</add-no-cache-headers> 
            </properties> 
        </channel-definition> 

    </channels> 

    <logging> 
        <!– You may also use flex.messaging.log.ServletLogTarget –> 
        <target class="flex.messaging.log.ConsoleTarget" level="info"> 
            <properties> 
                <prefix>[BlazeDS] </prefix> 
                <includeDate>false</includeDate> 
                <includeTime>false</includeTime> 
                <includeLevel>true</includeLevel> 
                <includeCategory>false</includeCategory> 
            </properties> 
            <filters> 
                <pattern>Endpoint.*</pattern> 
                <pattern>Service.*</pattern> 
                <pattern>Configuration</pattern> 
            </filters> 
        </target> 
    </logging> 

</services-config>

5、修改flex/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> 
  </service>

6、修改applicationContext.xml,增加BlazeDS与Spring集成配置,将Spring的bean导出为flex的Destination
共有三种方法可以将Spring的bean导出为felx的Destination

创建WEB-INF/applicationContext.xml,内容如下:
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:flex="http://www.springframework.org/schema/flex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
http://www.springframework.org/schema/flex 
http://www.springframework.org/schema/flex/spring-flex-1.0.xsd"> 

    <!– Maps request paths at /messagebroker to the BlazeDS MessageBroker –> 
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
        <property name="mappings"> 
            <value> 
                /messagebroker/*=_messageBroker 
            </value> 
        </property> 
    </bean> 

    <!– Dispatches requests mapped to a MessageBroker –> 
    <bean class="org.springframework.flex.servlet.MessageBrokerHandlerAdapter"/> 

    <!– Bootstraps and exposes the BlazeDS MessageBroker –> 
    <bean id="_messageBroker " class="org.springframework.flex.core.MessageBrokerFactoryBean" />    

    <!– Expose the productService bean for BlazeDS remoting –> 
    <!– method 1 –> 
    <!– 
      <bean id="test1" class="com.yeeach.HelloWorldService" /> 
      <flex:remoting-destination ref="test1" /> 
      –> 
      <!–  method2 –> 
      <!– 
      <bean id="test1" class="com.yeeach.HelloWorldService" > 
          <flex:remoting-destination /> 
      </bean> 
       –> 
      <!–  method3 –> 
      <bean id="helloWorldService" class="com.yeeach.HelloWorldService" /> 
      <bean id="test1" class="org.springframework.flex.remoting.RemotingDestinationExporter"> 
          <property name="messageBroker" ref="mySpringManagedMessageBroker"/> 
        <property name="service" ref="helloWorldService"/> 
      </bean> 
</beans>

7、创建flex-src/helloworld.mxml,内容如下:
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                layout="vertical"> 
    <mx:RemoteObject destination="test1" 
                     id="test1"> 
        <mx:method name="hello" 
                   result="sayHelloResult(event)"/> 
        <mx:method name="world" 
                   result="sayWorldResult(event)"/> 
    </mx:RemoteObject> 
    <mx:HBox> 
        <mx:Label text="输入:"/> 
        <mx:TextInput id="inputStr"/> 
        <mx:Button label="say hello" 
                   click="sayHello(event);"/> 
        <mx:Button label="say world" 
                   click="sayWorld(event);"/> 
    </mx:HBox> 
    <mx:HBox> 
        <mx:Label text="结果:"/> 
        <mx:TextArea id="result"/> 
    </mx:HBox> 

    <mx:Script> 

        <![CDATA[ 
            import mx.rpc.events.FaultEvent; 
            import mx.controls.Alert; 
            import mx.rpc.events.ResultEvent; 

            function sayHello(event:Event):void 
            { 
                var inputVar:String=inputStr.text; 
                test1.hello(inputVar); 

            } 

            function sayWorld(event:Event):void 
            { 
                var inputVar:String=inputStr.text; 
                test1.world(inputVar); 

            } 

            private function sayHelloResult(event:ResultEvent):void 
            { 
                result.text=event.result.toString(); 
                Alert.show(event.result.toString(), "返回结果"); 
            } 

            private function sayWorldResult(event:ResultEvent):void 
            { 
                result.text=event.result.toString(); 
                Alert.show(event.result.toString(), "返回结果"); 
            } 
        ]]> 
    </mx:Script> 
</mx:Application>

8、参考文档:
    http://static.springsource.org/spring-flex/docs/1.0.x/reference/html/index.html

    http://blog.springsource.com/2009/06/10/using-spring-blazeds-integration-10/

    http://blog.springsource.com/2008/12/17/using-spring-blazeds-integration-m1/

    http://ria.dzone.com/articles/introduction-spring-blazeds?page=0,2

Archive for 七月, 2009
SEO先从产品优化做起
Posted 七月 26, 2009  Comments(3)
    最近今天想整理收录一些无线互联网的产品以供进一步思考无线互联网产品,需要收集的产品信息很简单,大致的结构如下:

    1、xx产品定位:什么是xx产品,xx产品能够做什么。

    2、xx产品功能特征及益处:xx产品有哪些功能及特征,能够给使用者带来什么好处。

    3、xx产品安装使用说明

    4、xx产品的标准图库及使用flash

   这些信息其实是任何公司做产品策划及产品推广必须准备的东西,原本以为很简单的事情,按照这些标准去收集产品信息时候才发现大部分公司官网对自己产品的介绍都很难满足这样最简单的要求,反而是那些资源下载站点可能介绍得更为清楚,当然这些站点对于产品定位描述是否准确只有官方自己知道了。

   企业门户从使用对象来说不外乎有客户、合作伙伴、竞争对手、员工等,按照微软、IBM等门户提供商的分类法莱划分,企业门户分为:

合作伙伴门户:更紧密地与合作伙伴渠道集成,同时降低通过该渠道开展业务的整体每次交易成本。 提供允许与合作伙伴轻松沟通的工具,在联合业务活动中展开协作以及推动产品与服务交易的自助模型。
客户门户:与客户建立并培养紧密持久的关系。 提高客户满意度,寻找新客户,并推动降低产品和服务交易成本。
雇员门户:使雇员在需要时能够与自己需要的不同信息、流程和应用程序建立联系。 提供协作工作,使雇员能够更好地与其他雇员和合作伙伴联系并开展合作。
   这里我们讨论的对象主要是合作伙伴门户和客户门户。对于大部分的互联网公司而言,由于业务规模、维护成本等因素,大部分官方网站承载了合作伙伴门户和客户门户的角色,因此官网的设计就应当考虑这两种客户群。大家都信奉口碑营销的力量,这两类客户都是我们潜在的营销人员。

   以产品定位来看,大部分的官网都倾向于直接介绍产品功能,不愿意用简短的一句话来明确向用户传达出产品的定位。或许这些厂商认为自己的产品太有名气了,大部分的用户理所当然知道xx产品是什么,没有必要以一句简洁的话来概括产品的定位;或许是这些产品太复杂了,很难用一句话来说清楚产品的丰富功能是什么。于是乎我们会发现各种博客、论坛、下载站点对于同一产品的定位的描述可以说是千奇百怪的。以手机大头为例子,如果要一句话来说清楚手机大头的定位,是聊天交友?是音乐下载?是资讯浏览。UCWEB对于其产品倒是有官方明确的定位说明:UCWEB是什么?WEB、WAP手机浏览器,速度快而稳定,具有视频播放、网站导航、搜索、下载、个人数据管理等功能,助您畅游网络世界。结果就是用户对于产品是什么含混不清,觉得什么功能都有,什么功能都不突出,很难给用户留下深刻的影响,要做口碑营销也要费上老大劲去解释说明。合作伙伴对产品的宣传也是乱七八糟,甚至可能与产品定位背道而驰。于是乎会看见搜索引擎结果中对于产品定位形形色色的介绍。

    对于产品特征介绍市大部分官网倒是作为重点来推介。或许是为了突出自己的技术优势,大部分产品在罗列出产品功能特征后,接着化了很大力气来描述产品技术实现优势及领先性。对于产品给用户带来的益处都寥寥数语。对于用户及合作伙伴而言,大部分的人其实并不懂技术,更不明白技术实现对他们有什么价值。

    对于产品的安装使用说明,问题也是多多。对于手机软件的适配机型描述方式大部分联动下拉框的方式(手机品牌,机型),这对于普通用户下载倒没有问题,但要是我是一个个人站长,要想直接拷贝黏贴适配信息到网站上就费劲了,只能一个品牌一个品牌录入。更多的产品连版本信息、使用手册、FAQ都没有。

    在做联盟推广时候大家都会按照联盟站点的要求提供给联盟站点一些自家产品各种尺寸的标准图片,但对于自己的官网似乎没有几家愿意提供这样的产品图库。提供这样的标准图库好处是显而易见的,对于一些像我这样的blogger、个人站点及资源下载站点,可以直接采用官方标准的图库,不用费老大力气去截图、裁减。这对于产品的推广肯定是有好处的。选择一种产品,用各大搜索引擎的图片搜索搜索一下产品名称,就会发现产品截图也是形形色色。

   我们每天都在琢磨怎样通过SEO让搜索引擎排名提升,怎样让搜索引擎收录更多关于我们自己产品介绍的网页;我们每天都在琢磨搜索引擎营销、博客营销、社区营销、邮件营销、事件营销、论坛营销等等,但是我们恰恰忘记了众多愿意帮助我们义务做推广的个人客户、个人站点、资源下载站点们,对于好的产品他们会不自觉地在blog、论坛、邮件、站点等通路中义务做宣传、推广,但是他们缺少标准化强有力的推广工具。如果这些人义务帮助我们做推广,还要让其费劲去截图,去写产品定位及功能介绍,那这样的热情他们又能够持续多久呢?如果我们的产品连人都不能很清晰地理解,那我们的SEO做得再好,又有什么价值呢?

    在做搜索引擎优化以前先从我们自己产品的优化开始做起。

Technorati 标签: seo,产品管理,运营管理,用户体验,搜索引擎优化
SaaS模式杂思之垂直化生存
Posted 七月 24, 2009  Comments(1)
    不停地制造各种新术语、新概念是各个咨询公司、IT厂商、互联网公司吸引眼球百试不爽的招式,尤其是在这低迷的经济环境下。

    SaaS、云计算是当下流行的词汇,尤其有Salesforce这样的标杆企业,以及Google、Microsoft、Amazon这些巨头们的竞相参与,各个心怀鬼胎的咨询公司、专家们、软件公司、互联网公司都不约而同地鼓吹SaaS及云计算模式光明的未来,各种厂商都迫不及待地标识自己提供的服务是SaaS+云计算模式,似乎SaaS模式是解决中小企业信息化困局的灵丹妙药。连各种IDC提供商也改称为“云计算”服务提供商了,呵呵。

    无可否认,SaaS服务对于中国近1000 万家中小企业而言具有现实的意义。这些中小企业的IT信息化程度较低,能够投入到IT建设的资源也相对有限。这些企业在渡过其生存期之后,直接面临应对市场竞争与降低成本的需求,IT系统能够帮助企业提供工作效率、提升管理质量、降低运营成本已被各企业的老板们所接受,因此这些企业对于SaaS服务有潜在的巨大需求。当然怎样激活这块市场是所有的SaaS服务商、传统软件厂商们所面临的问题。

    相对于需要在网络基础设计上重金投入的“云计算”游戏而言,转型为SaaS服务提供商对于大部分的IT公司似乎相对容易,把产品放到互联网上,然后将卖产品改为卖服务就行了,于是乎“忽如一夜春风来,千树万树SaaS结”,各种SaaS服务提供商层出不穷。整体而言,SaaS服务主要有两大类别:一类是面向企业的服务,向各种规模的企业和组织提供的服务,如CRM、ERP、HRM、SCM、电子商务等。 二是面向企业和个人消费者提供的通用服务,如电子邮件、在线Office、存储、视频会议、协同办公等。

    只不过迄今为止,在国内似乎很难见到较为成功的SaaS服务,究其原因,正如专家们分析,SAAS产品在商业模式的运作中存在以下几个亟待解决的关键问题:

    1.服务提供商的公信力问题

    2.企业需求个性化问题

    3.数据安全问题

    4.一次性投入与多次投入的问题

    5.生态链建立

    这些观点都很有道理,但似乎忽略了最根本的问题:SaaS服务对于企业真正的核心价值是什么?

    对于这样的问题,相信所有的SaaS服务商都会回答:节省成本、优化流程、提升竞争力等等,正如所有的IT厂商们所承诺的一样。但对于一遍又一遍被洗脑的中小企业而言,他们肯定需要CRM、肯定需要ERP,但他们需要的是与企业业务流程无缝融合在一起的系统及服务,并不需要堆砌了各种时尚术语但与企业业务流程严重脱节的“先进系统”。中小企业们没有能力像“我们的国企”们为了先进而先进,为了理念而理念。

    SaaS服务的核心价值在于能否融入到企业核心流程中,有力支撑企业战略的落实。

    作为企业应用之一SaaS服务,SaaS服务要取得真正的成功,就必须为企业提供有价值的服务,让企业依赖于SaaS服务。与个人客户不同,个人客户如果喜欢你的服务,他就会持续不断用下去。而对于一个由众多个体组成的企业,一种工具的选择本身就众口难调,因此如果SaaS服务本身只是作为一种锦上添花的工具,并不是员工们日常工作必不可少的支撑系统,那么我相信正如众多的企业IT系统的推广使用一样(例如CRM、知识管理、OA等),最终都不了了之。因此成功的SaaS模式必须有力支撑企业的战略及商业模式的实现,而要达成这一点,就要求SaaS服务必须深入到行业需求中去,将所提供服务融入到企业的核心业务流程中去。尽管这与大部分SaaS服务商所极力避免的“个性化定制”似乎有冲突。

    但如果SaaS服务只是停留在一套标准化组件满足所有行业客户需求的阶段,如果只是将一堆所谓的CRM、ERP、KM组合在一起就称之为“Total Solution”,如果以为通过一堆新概念忽悠用户购买服务就万事大吉了,那么SaaS服务即使解决了企业“资金流、信息流、物流”中的其中一环的部分问题,这样的SaaS服务对于企业而言并不会有本质性的帮助,至多只是一种可有可无的工具而已。

    相对于那些CRM、ERP、HRM、SCM厂商们针对垂直领域的SaaS服务而言,相对于那些提供大而全通吃各个行业的“Total Solution”的SaaS服务而言,我更看好垂直行业+垂直领域解决方案的SaaS服务模式,通过深入研究一个行业的行业弊端及行业需求,将SaaS融入到企业的核心业务流程中去,这样的SaaS服务必将给企业,也给SaaS服务提供商带来美好的前景。

 

Technorati 标签: SaaS,云计算,垂直化生存,商业模式,crm,erp,asp
Flex 对Java端返回Collection的处理方法
Posted 七月 22, 2009  Comments(4)
    将Flex与Spring集成后(BlazeDS 与Spring集成指南 ),第一个面临的问题就是:对于Java端返回的各种Java类型的对象,Flex中能否有相应的数据类型来映射。

处理,尤其是List、Set、Map及POJO对象值。

    在 BlazeDS 与Spring集成指南 例子的基础上,调整相关的测试代码如下:

1、Java端
1.1、com.yeeach.HelloWorldService 
package com.yeeach; 

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.HashSet; 
import java.util.List; 
import java.util.Map; 
import java.util.Set; 

public class HelloWorldService { 
    public String hello(String var1) { 
        return "hello " + var1; 
    } 
    public String world(String var1) { 
        return "world " + var1; 
    } 
    public Map<String,List<String>> getMap() { 
        ArrayList<String> list1=new ArrayList<String>(); 
        list1.add("value11"); 
        list1.add("value12"); 
        list1.add("value13"); 
        ArrayList<String> list2=new ArrayList<String>(); 
        list2.add("value21"); 
        list2.add("value22"); 
        list2.add("value23"); 
        ArrayList<String> list3=new ArrayList<String>(); 
        list3.add("value31"); 
        list3.add("value32"); 
        list3.add("value33");        
        HashMap<String,List<String>> map=new HashMap<String,List<String>>(); 
        map.put("key1", list1); 
        map.put("key2", list2); 
        map.put("key3", list3);        
        return map; 
    } 
    public ArrayList<Person> getList() { 
        ArrayList <Person> list=new ArrayList<Person>(); 
        Person p1=new Person(); 
        p1.setName("name1"); 
        p1.setPass("pass1"); 
        Person p2=new Person(); 
        p2.setName("name2"); 
        p2.setPass("pass2"); 
        Person p3=new Person(); 
        p3.setName("name3"); 
        p3.setPass("pass3"); 
        list.add(p1); 
        list.add(p2); 
        list.add(p3); 
        return list; 
    } 
    public Set<Person> getSet() { 
        HashSet<Person>  set=new HashSet<Person>(); 
        Person p1=new Person(); 
        p1.setName("name1"); 
        p1.setPass("pass1"); 
        Person p2=new Person(); 
        p2.setName("name2"); 
        p2.setPass("pass2"); 
        Person p3=new Person(); 
        p3.setName("name3"); 
        p3.setPass("pass3"); 
        set.add(p1); 
        set.add(p2); 
        set.add(p3); 
        return set; 
    }    
}


1.2、com.yeeach.Person
package com.yeeach 

public class Person { 

        public String getName() { 
            return name; 
        } 
        public void setName(String name) { 
            this.name = name; 
        } 
        public String getPass() { 
            return pass; 
        } 
        public void setPass(String pass) { 
            this.pass = pass; 
        } 
        private String name; 
        private String pass; 

}


2、Flex 端
2.1、helloworld.mxml
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                layout="vertical"> 
    <mx:RemoteObject destination="test1" 
                     id="test1"> 
        <mx:method name="hello" 
                   result="sayHelloResult(event)"/> 
        <mx:method name="world" 
                   result="sayWorldResult(event)"/> 
        <mx:method name="getMap" 
                   result="getMapResult(event)"/> 
        <mx:method name="getList" 
                   result="getListResult(event)"/> 
        <mx:method name="getSet" 
                   result="getSetResult(event)"/> 
    </mx:RemoteObject> 
    <mx:HBox> 
        <mx:Label text="输入:"/> 
        <mx:TextInput id="inputStr"/> 
        <mx:Button label="say hello" 
                   click="sayHello(event);"/> 
        <mx:Button label="say world" 
                   click="sayWorld(event);"/> 
        <mx:Button label="get map" 
                   click="test1.getMap()"/> 
        <mx:Button label="get list" 
                   click="test1.getList()"/> 
        <mx:Button label="get set" 
                   click="test1.getSet()"/>                   
    </mx:HBox> 
    <mx:HBox> 
        <mx:Label text="结果:"/> 
        <mx:TextArea id="result"/> 
    </mx:HBox> 

    <mx:Script> 

        <![CDATA[ 
            import mx.collections.ArrayCollection; 
            import mx.rpc.events.FaultEvent; 
            import mx.controls.Alert; 
            import mx.rpc.events.ResultEvent; 
            import com.yeeach.Person; 
            [Bindable] 
            public var person:Person; 
            [Bindable] 

            public var map:ArrayCollection=null; 

            function sayHello(event:Event):void 
            { 
                var inputVar:String=inputStr.text; 
                test1.hello(inputVar); 

            } 

            function sayWorld(event:Event):void 
            { 
                var inputVar:String=inputStr.text; 
                test1.world(inputVar); 

            } 

            private function sayHelloResult(event:ResultEvent):void 
            { 
                result.text=event.result.toString(); 
                Alert.show(event.result.toString(), "返回结果"); 
            } 

            private function sayWorldResult(event:ResultEvent):void 
            { 
                result.text=event.result.toString(); 
                Alert.show(event.result.toString(), "返回结果"); 
            } 

            private function getMapResult(event:ResultEvent):void 
            { 
                for (var key:String in event.result) 
                { 
                    var list:ArrayCollection=event.result[key] as ArrayCollection; 
                    for (var key1:Object in list) 
                    { 
                        Alert.show("map item key is: " + key + " value is: " + key1); 
                    } 

                } 
            } 

            private function getList():void 
            { 
                test1.getList(); 
            } 

            private function getListResult(event:ResultEvent):void 
            { 
                var ac:ArrayCollection=event.result as ArrayCollection; 
                for (var i:int=0; i < ac.length; i++) 
                { 
                    var p1:Person=ac.getItemAt(i) as Person; 
                    Alert.show("list item name is: " + p1.name+" \n another usage : "+ac.getItemAt(i).name); 
                } 

            } 
            private function getSet():void 
            { 
                test1.getSet(); 
            } 

            private function getSetResult(event:ResultEvent):void 
            { 
                var ac:ArrayCollection=event.result as ArrayCollection; 
                for (var i:int=0; i < ac.length; i++) 
                { 
                    var p1:Person=ac.getItemAt(i) as Person; 
                    Alert.show("set item name  is: " + p1.name); 
                } 

            }            
        ]]> 
    </mx:Script> 
</mx:Application>



2.2、com.yeeach.Person.as
package com.yeeach 
{ 
    [Bindable] 
    [RemoteClass(alias="com.yeeach.Person")] 
    public class Person 
    { 
        public var name:String; 
        public var pass:String; 
    } 
}


3、总结:
    1、JavaBean从Java端返回给Flex,可以通过Flex的Meta Tag [RemoteClass (alias=” “)]来标识服务器端对应的Java的类(一般为POJO对象)。

注意位置,是在class声明前。

    2、Java Collection返回给Flex,都可以通过转化为mx.collections.ArrayCollection来进行处理。

    3、Flex对于服务器端返回的java其他类型的处理,相对简单,可以参考

http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_4.html

Technorati 标签: flex,RIA,arraycollection,RemoteClass,spring,blazeds


BlazeDS 与Spring集成指南
Posted 七月 21, 2009  Comments(3)
    Springsource与Adobe合作发布了Spring与BlazeDS集成的项目Spring BlazeDS Integration,通过Spring BlazeDS Integration可以把Spring的Bean暴露为BlazeDS的Flex Remoting Service,这样Flex客户端就能够通过AMF调用Spring 暴露出来的Bean,有效简化BlazeDS配置及开发难度。

1、配置好BlazeDS的开发环境
参考“使用BlazeDS实现Java和Flex通信之hello world ”中的环境搭建过程,配置BlazeDS的开发环境。

创建com.yeeach.HelloWorldService,内容如下:
package com.yeeach 

public class HelloWorldService { 
    public String hello(String var1) { 
        return "hello " + var1; 
    } 
    public String world(String var1) { 
        return "world " + var1; 
    } 
}


2、下载Spring BlazeDS Integration 1.0、Spring、jackson包
http://s3.amazonaws.com/dist.springframework.org/release/FLEX/spring-flex-1.0.0.RELEASE-with-dependencies.zip

http://s3.amazonaws.com/dist.springframework.org/release/SPR/spring-framework-2.5.6.SEC01-with-dependencies.zip

http://jackson.codehaus.org/0.9.4/jackson-asl-0.9.4.jar

放入到flex-spring/WebRoot/WEB-INF/lib

3、修改web.xml,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> 

<web-app> 
    <display-name>Spring BlazeDS Integration Samples</display-name> 
    <description>Spring BlazeDS Integration Sample Application</description> 

    <!– Http Flex Session attribute and binding listener support –> 
    <listener> 
        <listener-class>flex.messaging.HttpFlexSession</listener-class> 
    </listener> 

    <!– The front controller of this Spring Web application, responsible for handling all application requests –> 
    <servlet> 
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
        <init-param> 
            <param-name>contextConfigLocation</param-name> 
            <param-value> 
                   classpath:/applicationContext*.xml 
                classpath*:/applicationContext.xml 
                /WEB-INF/applicationContext*.xml 
            </param-value> 
        </init-param> 
        <load-on-startup>1</load-on-startup> 
    </servlet> 
    <!– Map all *.spring requests to the DispatcherServlet for handling –> 
    <servlet-mapping> 
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
        <url-pattern>/spring/*</url-pattern> 
    </servlet-mapping> 

    <welcome-file-list> 
        <welcome-file>index.htm</welcome-file> 
    </welcome-file-list> 

</web-app>



4、修改flex/services-config.xml,内容如下
<?xml version="1.0" encoding="UTF-8"?> 
<services-config> 

    <services> 
        <service-include file-path="remoting-config.xml" /> 
        <service-include file-path="proxy-config.xml" /> 

        <!– 
        Application level default channels. Application level default channels are 
        necessary when a dynamic destination is being used by a service component 
        and no ChannelSet has been defined for the service component. In that case, 
        application level default channels will be used to contact the destination. 
        –>   
        <default-channels> 
           <channel ref="my-amf"/> 
        </default-channels> 
    </services> 

    <channels> 
        <channel-definition id="my-streaming-amf" class="mx.messaging.channels.StreamingAMFChannel"> 
            <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/streamingamf" class="flex.messaging.endpoints.StreamingAMFEndpoint"/> 
        </channel-definition> 
        <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel"> 
            <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/> 
            <properties> 
                <polling-enabled>false</polling-enabled> 
            </properties> 
        </channel-definition> 

        <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel"> 
            <endpoint url="https://{server.name}:{server.port}/{context.root}/spring/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/> 
            <properties> 
                <add-no-cache-headers>false</add-no-cache-headers> 
            </properties> 
        </channel-definition> 

        <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel"> 
            <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/> 
            <properties> 
                <polling-enabled>true</polling-enabled> 
                <polling-interval-seconds>4</polling-interval-seconds> 
            </properties> 
        </channel-definition> 

        <channel-definition id="my-http" class="mx.messaging.channels.HTTPChannel"> 
            <endpoint url="http://{server.name}:{server.port}/{context.root}/spring/messagebroker/http" class="flex.messaging.endpoints.HTTPEndpoint"/> 
        </channel-definition> 

        <channel-definition id="my-secure-http" class="mx.messaging.channels.SecureHTTPChannel"> 
            <endpoint url="https://{server.name}:{server.port}/{context.root}/spring/messagebroker/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/> 
            <properties> 
                <add-no-cache-headers>false</add-no-cache-headers> 
            </properties> 
        </channel-definition> 

    </channels> 

    <logging> 
        <!– You may also use flex.messaging.log.ServletLogTarget –> 
        <target class="flex.messaging.log.ConsoleTarget" level="info"> 
            <properties> 
                <prefix>[BlazeDS] </prefix> 
                <includeDate>false</includeDate> 
                <includeTime>false</includeTime> 
                <includeLevel>true</includeLevel> 
                <includeCategory>false</includeCategory> 
            </properties> 
            <filters> 
                <pattern>Endpoint.*</pattern> 
                <pattern>Service.*</pattern> 
                <pattern>Configuration</pattern> 
            </filters> 
        </target> 
    </logging> 

</services-config>


5、修改flex/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> 
  </service>


6、修改applicationContext.xml,增加BlazeDS与Spring集成配置,将Spring的bean导出为flex的Destination
共有三种方法可以将Spring的bean导出为felx的Destination

创建WEB-INF/applicationContext.xml,内容如下:
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:flex="http://www.springframework.org/schema/flex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
http://www.springframework.org/schema/flex 
http://www.springframework.org/schema/flex/spring-flex-1.0.xsd"> 

    <!– Maps request paths at /messagebroker to the BlazeDS MessageBroker –> 
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
        <property name="mappings"> 
            <value> 
                /messagebroker/*=_messageBroker 
            </value> 
        </property> 
    </bean> 

    <!– Dispatches requests mapped to a MessageBroker –> 
    <bean class="org.springframework.flex.servlet.MessageBrokerHandlerAdapter"/> 

    <!– Bootstraps and exposes the BlazeDS MessageBroker –> 
    <bean id="_messageBroker " class="org.springframework.flex.core.MessageBrokerFactoryBean" />    

    <!– Expose the productService bean for BlazeDS remoting –> 
    <!– method 1 –> 
    <!– 
      <bean id="test1" class="com.yeeach.HelloWorldService" /> 
      <flex:remoting-destination ref="test1" /> 
      –> 
      <!–  method2 –> 
      <!– 
      <bean id="test1" class="com.yeeach.HelloWorldService" > 
          <flex:remoting-destination /> 
      </bean> 
       –> 
      <!–  method3 –> 
      <bean id="helloWorldService" class="com.yeeach.HelloWorldService" /> 
      <bean id="test1" class="org.springframework.flex.remoting.RemotingDestinationExporter"> 
          <property name="messageBroker" ref="mySpringManagedMessageBroker"/> 
        <property name="service" ref="helloWorldService"/> 
      </bean> 
</beans>


7、创建flex-src/helloworld.mxml,内容如下
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                layout="vertical"> 
    <mx:RemoteObject destination="test1" 
                     id="test1"> 
        <mx:method name="hello" 
                   result="sayHelloResult(event)"/> 
        <mx:method name="world" 
                   result="sayWorldResult(event)"/> 
    </mx:RemoteObject> 
    <mx:HBox> 
        <mx:Label text="输入:"/> 
        <mx:TextInput id="inputStr"/> 
        <mx:Button label="say hello" 
                   click="sayHello(event);"/> 
        <mx:Button label="say world" 
                   click="sayWorld(event);"/> 
    </mx:HBox> 
    <mx:HBox> 
        <mx:Label text="结果:"/> 
        <mx:TextArea id="result"/> 
    </mx:HBox> 

    <mx:Script> 

        <![CDATA[ 
            import mx.rpc.events.FaultEvent; 
            import mx.controls.Alert; 
            import mx.rpc.events.ResultEvent; 

            function sayHello(event:Event):void 
            { 
                var inputVar:String=inputStr.text; 
                test1.hello(inputVar); 

            } 

            function sayWorld(event:Event):void 
            { 
                var inputVar:String=inputStr.text; 
                test1.world(inputVar); 

            } 

            private function sayHelloResult(event:ResultEvent):void 
            { 
                result.text=event.result.toString(); 
                Alert.show(event.result.toString(), "返回结果"); 
            } 

            private function sayWorldResult(event:ResultEvent):void 
            { 
                result.text=event.result.toString(); 
                Alert.show(event.result.toString(), "返回结果"); 
            } 
        ]]> 
    </mx:Script> 
</mx:Application>


8、参考文档:
    http://static.springsource.org/spring-flex/docs/1.0.x/reference/html/index.html

    http://blog.springsource.com/2009/06/10/using-spring-blazeds-integration-10/

    http://blog.springsource.com/2008/12/17/using-spring-blazeds-integration-m1/

    http://ria.dzone.com/articles/introduction-spring-blazeds?page=0,2


程序代码:flex-spring.rar  (附件里可下载)


使用BlazeDS实现Java和Flex通信之hello world
新的项目对用户体验及用户互动要求较高,决定选用Flex作为前端的展现技术,整体框架仍然是Flex+Spring+Hibernate(考虑采用seam中)。作为入门,先从经典的Hello world开始,暂时不考虑Flex与Spring、Hibernate的集成。

Flex要实现与Java集成,开源项目BlazeDS、GraniteDS、Flamingo都提供了相应的解决方案,考虑到BlazeDS是Adobe官方的开源项目,因此采用BlazeDs作为Flex与Java通信的基础框架。什么是BlazeDS呢,看看官方的介绍:

BlazeDS is the server-based Java remoting and web messaging technology that enables developers to easily connect to back-end distributed data and push data in real-time to Adobe® Flex® and Adobe AIR™ applications for more responsive rich Internet application (RIA) experiences.

开发工具采用Eclipse+Flex Builder 3 Plug-in方式,不采用Flex Builder 3。先安装Eclipse,再安装Flex Builder 3 Plug-in,相关的安装配置不再赘述。

1、下载BlazeDS
下载BlazeDS Turnkey :http://flexorg.wip3.adobe.com/blazeds/3.0.x/milestone/3978/blazeds-turnkey-3.2.0.3978.zip

由于BlazeDS Turnkey中包含BlazeDS的使用例子,对于入门熟悉Flex及BlazeDS都有较好的参考价值,因此建议下载BlazeDS Turnkey。

关于blazeds-turnkey 的目录说明:

docs:BlazeDS Javadoc

resources:BlazeDS的相关支持包,包括clustering(采用jgroups)、BlazeDS与ColdFusion 集成的配置文件、BlazeDS的配置文件、BlazeDS与AJAX集成的桥、Flex的SDK、Flex的java library、BlazeDS与Tomcat、Jboss、Websphere等security集成的支持包。

sampledb:hsqldb的启动脚本及样例数据库

tomcat:Tomcat 包

blazeds.war:最小化的BlazeDS 文件,可以作为空白项目来建立BlazeDS 应用程序。

sample.war:BlazeDS的demo例子(所谓的testdrive)。

ds-console.war :BlazeDS的部署管理程序。

2、建立Java Web Project
File->New->Web Project 建立Java helloworld项目

在helloworld/src下,新建com.yeeach.HelloWorldService类,内容如下:
package com.yeeach; 

public class HelloWorldService {
   public String hello(String var1) {
      return “hello ” + var1;
   }
   public String world(String var1) {
      return “world ” + var1;
   }
}

3、建立helloworld的BlazeDS开发环境
3.1、拷贝blazeds.war下的WEB-INF到helloworld的目录下,覆盖原有的WEB-INF
3.2、在helloworld下建立flex-src目录(与src同级),用于存放flex的相关代码

helloworld/src:用于存放项目的java代码

helloworld/flex-src:用于存放项目flex的相关代码
helloworld/WebRoot/WEB-INF/flex:存放flex的相关配置文件
3.3、设置Flex Project Nature




3.4、在helloworld/flex-src下,新建MXML Application:helloworld.mxml,内容如下:
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”vertical”>
<mx:RemoteObject destination=”com.yeeach.HelloWorldService”
id=”helloWorldService”>
<mx:method name=”hello”
result=”sayHelloResult(event)”/>
<mx:method name=”world”
result=”sayWorldResult(event)”/>
</mx:RemoteObject>
<mx:HBox>
<mx:Label text=”输入:”/>
<mx:TextInput id=”inputStr”/>
<mx:Button label=”say hello”
click=”sayHello(event);”/>
<mx:Button label=”say world”
click=”sayWorld(event);”/>
</mx:HBox>
<mx:HBox>
<mx:Label text=”结果:”/>
<mx:TextArea id=”result”/>
</mx:HBox> 

<mx:Script> 

<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent; 

function sayHello(event:Event):void
{
var inputVar:String=inputStr.text;
helloWorldService.hello(inputVar); 

} 

function sayWorld(event:Event):void
{
var inputVar:String=inputStr.text;
helloWorldService.world(inputVar); 

} 

private function sayHelloResult(event:ResultEvent):void
{
result.text=event.result.toString();
Alert.show(event.result.toString(), "返回结果");
} 

private function sayWorldResult(event:ResultEvent):void
{
result.text=event.result.toString();
Alert.show(event.result.toString(), "返回结果");
}
]]>
</mx:Script>
</mx:Application>

3.5、修改remoting-config.xml,增加对destination的说明:
<destination id=”com.yeeach.HelloWorldService”>
<properties>
<source>com.yeeach.HelloWorldService</source>
</properties>
</destination>

3.6、设置Flex Build Path等相关属性

1)右键->Properties,设置Flex Build Path属性,将Main source folder修改为flex-src,然后点击“OK”

2)右键->Properties,设置Flex Applications属性,添加flex-src下的其他Application,然后点击“OK”

如果需要添加flex-src子目录下的其他Application(例如helloworld/flex-src/com/yeeach/helloworld1.mxml),目前从UI界面似乎无法正确添加,可以直接修改.actionScriptProperties,在<applications></applications>中间增加相应的Application

<applications>
<application path=”helloworld.mxml”/>

<application path=”com/yeeach.com/helloworld1.mxml”/>
</applications>

3)右键->Properties,设置Flex Compiler属性,将Flex SDK version 修改为“Use default”或“Use a specific SDK”,指向正确的Flex SDK;确认“Additional compiler arguments”配置参数正确,然后点击“OK”

4)右键->Properties,设置Flex Server属性,配置为正确的参数,然后点击“OK”

3.7、部署helloworld 应用到Tomcat

通过http://127.0.0.1:8080/helloworld/helloworld.swf来访问我们的hello world

3.8、分析helloworld.mxml
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml”
layout=”vertical”>
<mx:RemoteObject destination=”com.yeeach.HelloWorldService”
id=”helloWorldService”>

//此处的destination=”com.yeeach.HelloWorldService”与remoting-config.xml中的id=”com.yeeach.HelloWorldService”完全匹配

//id=”helloWorldService”用来在actionscript中标识destination=”com.yeeach.HelloWorldService”,后面的helloWorldService.hello(inputVar)等都使用此id;

<mx:method name=”hello”
result=”sayHelloResult(event)”/>

//mx:method 声明java类com.yeeah.com.HelloWorldService中的hello方法及响应结果回调函数sayHelloResult
<mx:method name=”world”
result=”sayWorldResult(event)”/>
</mx:RemoteObject>
<mx:HBox>
<mx:Label text=”输入:”/>
<mx:TextInput id=”inputStr”/>
<mx:Button label=”say hello”
click=”sayHello(event);”/>
<mx:Button label=”say world”
click=”sayWorld(event);”/>
</mx:HBox>
<mx:HBox>
<mx:Label text=”结果:”/>
<mx:TextArea id=”result”/>
</mx:HBox> 

<mx:Script> 

<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent; 

function sayHello(event:Event):void
{
var inputVar:String=inputStr.text;
helloWorldService.hello(inputVar); 

} 

function sayWorld(event:Event):void
{
var inputVar:String=inputStr.text;
helloWorldService.world(inputVar); 

} 

private function sayHelloResult(event:ResultEvent):void
{
result.text=event.result.toString();
Alert.show(event.result.toString(), "返回结果");
} 

private function sayWorldResult(event:ResultEvent):void
{
result.text=event.result.toString();
Alert.show(event.result.toString(), "返回结果");
}
]]>
</mx:Script>
</mx:Application>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics