Flex two kinds of ways to interact with the background JAVA __java

Source: Internet
Author: User
Tags current time
My side now has two teams to do the system, the first team uses the RemoteObject, the first team uses the Httpservice.
My previous idea was also to use RemoteObject, but later found that RemoteObject had some unpleasant spots.
1.RemoteObject to use entity classes to as (using bindable to bind Java classes). My system involves more than 200 tables, and if you change the table structure, the As entity class should also be changed. Very troublesome, and write well to change Getter,setter, but also deployed to Tomcat. Unless you write your own tool automatically generated.

2. Using RemoteObject, That your Java EE background to add remoting-config.xml,services-config.xml and so on the configuration file and Flex lib, many more files, and I do the project flex is only the client display, and then call backstage. Therefore, my service side can completely be familiar with the Java EE need to use the files. Reduced configuration and later maintenance.

3. If you want to use spring, you need to configure springfactory and destination. For example:
Services-config.xml inside Add:
<factories>

<factory id= "Spring" class= "Flex.samples.factories.SpringFactory"/>

</factories>
Remoting-config.xml inside Add:

<destination id= "UserService" >

<properties>

<!--factory--> your own factory name.

<factory>spring</factory>

<!--This source corresponds to the ID of the spring bean-->

<source>userService</source>

</properties>

</destination>
Here needs to be configured for every service, many words ....

4. My side of the Flex UI developers are fresh graduates, the use of remoteobject it is necessary to understand ORM (my background persistence layer Framework is JPA), otherwise they can adjust the RemoteObject method is easy to error, or not call. Using Httpservice, the flex developer who only needs the UI of our backstage staff and the front desk to agree on a set of XML formats for the communication. Backstage is responsible for returning XML, the front desk is responsible for sending XML, very cool. For example:
<root>
<model>
<attribute1>attr1</attribute1>
<attribute2>attr2</attribute2>
</model>
</root>

5.Flex components are very friendly to XML support. You can simply put the XML returned by Httpservice into the component's dataprovider, especially if the DataGrid or tree is particularly good.

5. The use of Httpservice reduces the amount of deployment. I just deploy the background Java program to Tomcat, the front of the flex can directly flexbuilder compiled programs in the client connection background, without deployment to Tomcat, direct testing can be. Greatly improved the development efficiency.

6. The use of Httpservice also has drawbacks. The first is that the efficiency of communication is not remoteobject high (because it is XML, it can also use JSON or other means of communication). Second, you need to write the conversion between object and XML. Instead of using XStream, I write my own tool class with reflection. You also need to provide a servlet call to flex. I use the SPRINGMVC provided by Muliticontroller to provide the HTTP service for Flex.

7. Using Httpservice, I came across some unexpected things. The most vomiting of all is that when I provide a Get method to return XML data, Flex always displays the old data. The solution is to add an argument to the servlet address you requested (parameter name is random, I use random), and the requested parameter must be different each time (can be implemented through the current time or UUID), for example: http://192.168.2.111:8080/ Usercontroller.do?servlet=getall&random=sdfsdfs
This I have been wrong for a long time, depressed ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.