Xem mẫu

CHAPTER 4 SERVLET CONTAINER AND FRAMEWORKS application com.appirio.Gateway For Flex remoting to work correctly you need to pass some arguments to the compiler, telling it where to find the services file that defines your remoting destination. Your remoting destination points to a class calledGateway that you will create shortly. Right-click the project name in the left panel and select Properties ¾ Flex Compiler. Replace your compiler arguments with the following: -locale en_US -services ../war/WEB-INF/flex/services-config.xml Since you are using GraniteDS, you have to provide the runtime configuration for the container. Create a new folder called “granite” under /WEB-INF/ and paste the granite-config.xml file from graniteds/examples/graniteds_pojo/resources/ WEB-INF/granite/ into it. In this example you’ll be using the Java Persistence API (JPA) as the persistence protocol. Since App Engine utilizes JDO by default, you’ll need to create the configuration file for JPA manually. Create the persistence.xml file with the code from Listing 4-17 in the /src/META-INF/ directory. Listing 4-17. JPA persistence.xml file org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider< /provider> Client-Side Code Designing your Flex client is much easier than you might expect. Your client will be very basic and will expose two functions through a tabbed interface. Users will be able to either create a new account or look up the details of an existing one by its ID (Figure 4-10). Figure 4-10. The Flex UI displaying an account lookup 79 CHAPTER 4 SERVLET CONTAINER AND FRAMEWORKS Your Flex client will consist of a single MXML file containing all of your code and UI elements. For larger, more complex applications where you have clearly defined layers, you would typically break up the application into multiple MXML files and ActionScript classes using an MVC paradigm. Since your application is relatively small, there is really no need for this type of separation. As you look at the code for main.mxml in Listing 4-18, pay particular attention to the RemoteObject tag at the top of the file. The ID of the tag (gateway) is used to reference the RemoteObject throughout the file, while the destination (Gateway) is the same destination you set up in your services-config.xml file specifying your remoting destination of com.appirio.Gateway. The individual methods specified by the RemoteObject tag map directly to the public methods in the Gateway class that you will define in Listing 4-18. Listing 4-18. The Flex UI: main.mxml 81 CHAPTER 4 SERVLET CONTAINER AND FRAMEWORKS 82 ... - tailieumienphi.vn