MIGRATING WEB 1.0 INTERFACES TO RIA
427
PHP Middle Tier
PHP objects and scripts are less governed by specification than Java EE objects. Therefore, the form in
which a PHP middle tier exists could be quite varied. It could be within a container, like the Zend engine, or
it could live as objects on a PHP-enabled web server. The PHP code may be procedural or object
oriented.
Flex to PHP remoting options like the AMFPHP remoting library can be used to facilitate RPCs. However,
there is one possible obstacle to direct usage of the middle-tier methods. Not all PHP applications cleanly
demarcate between presentation logic and behavior, so directly consuming the data returned by PHP
methods in Flex may require additional parsing on the Flex side. In such situations, you may benefit from
following the preceding advice on making PHP generate XML or service-orienting the existing application.
Strategies to Port Framework-based Applications
As mentioned earlier, we pick two frameworks, Apache Struts and Ruby on Rails, and port them over to
use a Flex user interface. If you are planning to port applications of either of these two types, then this
section will give you a starting point in your endeavor. If your framework is not one of these two, then you
will still benefit indirectly, as the examples will give you some insight into the migration options at your
disposal.
Let’s rework an Apache Struts 1.x application to include a Flex user interface.
Apache Struts 1.x and Flex
First, take a look at Figure 12-16, which pictorially describes Apache Struts. Requests to an Apache
Struts–powered web application are intercepted by its front controller. The front controller routes requests
to appropriate action classes. The framework configuration and the request URL to action mapping are
accessed from the struts-config.xml file and the action mapping class instance. Action classes access
the middle-tier objects and the underlying data and then forward the output to a JSP. Alternatively, Apache
Tiles can be used to construct the views.
CHAPTER 12
428
Figure 12-16. Apache Struts—its front controller, action classes, action mapping, configuration, and form
bean
The preceding description is true for Apache Struts 1.x. Apache Struts 2.0 is a drastic overhaul of the
framework and is out of the scope of the current discussion.
A possible migration path from Apache Struts 1.x to Flex is to replace the View part of the Apache Struts
Model-View-Controller (MVC) structure. (In order to migrate smoothly, you need to make the following
modifications:
• Create a new Flex user interface.
• Invoke Apache Struts actions based on requests from Flex.
• Forward the output to a JSP that does not display the data but forwards the data in a format
that can be consumed by the Flex interface.
• Forward the error messages to a JSP that does not display the error messages but forwards
the data in a format that can be consumed by the Flex interface.
Get AdvancED Flex 4 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.