Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Java Page Flow

Java Page Flow

Web application development is hard. Or rather, Web application development used to be hard.

Web application development used to be an activity that required developers to learn and use complex programming models. Web application development used to be an activity that required developers to manage the myriad details of configuring their Web application so that the various pieces of the application worked together. Web application development used to be an activity that was performed outside of the helpful environment of an IDE.

No longer.

The new Java Page Flow feature set of WebLogic Workshop version 2 makes Web application development easy. It provides a simple, easy-to-understand Web application programming model. Java Page Flow automatically manages Web application configuration details. And it provides a set of tools that help developers quickly and correctly build Web applications, and integrate those applications with business logic.

What Is It?
Java Page Flow is a feature set built on a Struts-based Web application programming model. It leverages the power and extensibility of Struts while eliminating the difficulties and challenges of building Struts-based applications. Java Page Flow features include runtime support for the Web application programming model and tools that enable developers to quickly and easily build applications based upon the model.

The central concept and construct of Java Page Flow is called page flow. Basically, a page flow is a directory of Web app files that work together to implement a UI feature. For example, a page flow could implement a Web app's user registration wizard feature. The files of this page flow could be arranged in a userRegistration directory as shown in Figure 1.

The userRegistration directory contains several *.jsp files, a *.jcx file and a *.jpf file. The *.jsp files are standard JavaServer Pages files that contain markup that describes the visual aspect of the user registration wizard. For example, name.jsp contains markup that describes a First Name and Last Name data entry form. The *.jcx file is a BEA innovation. It contains annotated Java code that implements logic used by the user registration wizard. UserManager.jcx contains code that implements a createUser( ) function.

The *.jpf file is also a BEA innovation and is the main focus of this article. It contains annotated Java code that implements the navigation and state management logic of the user registration wizard and makes calls to business logic. For example, UserRegistrationController.jpf contains code that decides that name.jsp should be presented before address.jsp, gathers the firstName and lastName information from name.jsp before presenting address.jsp, and calls the createUser( ) function of UserManager.jcx.

For those of you familiar with Struts and Model-View-Controller (MVC) programming, the files of the user registration wizard may be mapped to the 'M', the 'V', and the 'C' of MVC as seen in Table 1.

Page Flow Controllers
Page flow controllers are the main focus of this article. Let's take a step-by-step look at the contents of the UserRegistrationController.jpf file and how the file performs its navigation, state management, and logic-calling functions.

First, UserRegistrationController.jpf contains a class definition whose skeleton looks like this:

package userRegistration;

import com.bea.wlw.netui.pageflow.PageFlowController;

public class UserRegistrationController
extends PageFlowController

UserRegistrationController extends PageFlowController, which is a class that provides useful base class functionality and derives indirectly from org.apache.struts.action.Action. The base class functionality of PageFlowController provides support for things such as login and logout. The derivation from Action is an important aspect of the Struts interoperability of PageFlowController. Many classes in Java Page Flow inherit from Struts classes and interoperate with the Struts plumbing that serves as the foundation for the Java Page Flow runtime.

Actions and Navigation
Since UserRegistrationController acts as the controller for the user registration wizard, it contains code, in the form of action methods, that performs the page navigation decisions for the wizard. Action methods are methods invoked in response to things like form submissions. For example, UserRegistrationController contains an action method named name_next (see Listing 1).

The name_next action method is invoked whenever a user submits the form of the name.jsp page (see Listing 2).

The name_next action method decides that the address.jsp page should be the next page presented to a user. Because the name_next action method is invoked whenever a user submits the form of the name.jsp page, the name_next method effectively causes navigation from the name.jsp page to the address.jsp page.

All action methods have similar signatures. For example, they all have Forward as their return type. All action methods are specially annotated with @jpf:action to indicate to the *.jpf compiler that they should be configured as action methods in the auto-generated Struts configuration files. Also, action methods may be annotated with @jpf:forward to indicate to the *.jpf compiler and to the IDE tools the possible navigation decisions that the action methods may make such as deciding to forward to a page like address.jsp. Action methods are called by the page flow runtime and express their navigation decisions to the runtime by returning objects of type Forward to the runtime. The Forward objects encapsulate information described by the @jpf:forward annotations on the action methods.

The page flow runtime is responsible for selecting and calling action methods in controllers as part of the runtime's request processing life cycle. It is also responsible for executing the navigation decisions made by the action methods. In other words, if a user submits the form of address.jsp, the page flow runtime performs a request processing life cycle that includes these steps:
1.  Intercept the submission when it arrives at the application server.
2.  Determine that the name_next action method should be called.
3.  Call the name_next method.
4.  Receive the Forward("getAddress") object from the name_next method.
5.  Forward it to the address.jsp page described by the Forward("getAddress") object.

Page flow controllers may contain any number of action methods. For example, UserRegistrationController contains five action methods in addition to the name_next action method (see Listing 3).

In addition to selecting and calling action methods, the page flow runtime also passes to the action methods any form data that may have been submitted. For example, when a user submits the form of the name.jsp page, the page flow runtime captures the firstName and lastName data of the form in properties of a NameForm object, and passes the populated NameForm object to the name_next action method: package userRegistration (see Listing 4).

State Management
Java Page Flow provides a powerful, yet easy-to-use, foundation for state management that makes it simple for UserRegistrationController to perform its state management responsibilities. For example, to manage the form data that is received from pages such as name.jsp, code may be added to UserRegistrationController that captures the data in convenient instance members (see Listing 5).

Since the page flow runtime makes it possible to cache state in controller instance members, it's easy to implement support for a back button in a wizard. For example, if the confirmation.jsp page contained a back button, UserRegistrationController could respond to a press of the back button by navigating backward to the address.jsp page with all previously filled-out address.jsp form data still intact (see Listing 6; Listings 6-8 can be found online at www.sys-con.com/weblogic/source.cfm).

As you can see, the confirmation_back action method forwards backwards to the address.jsp page. As part of the forward, confirmation_back passes to address.jsp the address data that had already been received from address.jsp as an argument to the address_next action method.

Calling Business Logic
BEA WebLogic Workshop makes it easy to expose business logic as controls, and the Java Page Flow feature makes it easy to call controls from action methods. Because the page flow runtime performs automatic instantiation and initialization of controls for all instance members that are annotated with @common:control, action methods in page flow controllers may call Workshop controls without having to include code that performs control instantiation and initialization. For example, the confirmation_next action method can simply and directly call the createUser( ) method of UserManager.jcx: package userRegistration (see Listing 7).

BEA WebLogic Workshop makes it easy to expose all kinds of business logic as controls, including business logic that is implemented as EJBs. In other words, WebLogic Workshop even makes it easy to build Web applications over EJBs.

Additional Features
Java Page Flow contains many features in addition to those described above. For example, you may have noticed that the @jpf:forward annotation for the confirmation_next action method was a bit different from the other @jpf:forward annotations (see Listing 8).

The returnAction= "userRegistrationDone" attribute enables UserRegistrationController to participate in a Java Page Flow feature called "nesting."

As I mentioned earlier, the Java Page Flow feature set includes some IDE tools that help developers build Web applications. One example of such a tool is the new flow view that enables developers to architect entire Web applications using little more than simple drag -and- drop gestures (see Figure 2).

Like nesting, data binding, and custom tags, we'll take a look at the IDE tools in a future WLDJ article.

Take It for a Test Spin
For now, the best thing you can do is tdownload BEA WebLogic Workshop v2 and experiment with the new Java Page Flow features. See for yourself just how much easier Web application development can be.

Reproduced with permission from BEA Systems.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

IoT & Smart Cities Stories
The challenges of aggregating data from consumer-oriented devices, such as wearable technologies and smart thermostats, are fairly well-understood. However, there are a new set of challenges for IoT devices that generate megabytes or gigabytes of data per second. Certainly, the infrastructure will have to change, as those volumes of data will likely overwhelm the available bandwidth for aggregating the data into a central repository. Ochandarena discusses a whole new way to think about your next...
DXWorldEXPO LLC announced today that Big Data Federation to Exhibit at the 22nd International CloudEXPO, colocated with DevOpsSUMMIT and DXWorldEXPO, November 12-13, 2018 in New York City. Big Data Federation, Inc. develops and applies artificial intelligence to predict financial and economic events that matter. The company uncovers patterns and precise drivers of performance and outcomes with the aid of machine-learning algorithms, big data, and fundamental analysis. Their products are deployed...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...
All in Mobile is a place where we continually maximize their impact by fostering understanding, empathy, insights, creativity and joy. They believe that a truly useful and desirable mobile app doesn't need the brightest idea or the most advanced technology. A great product begins with understanding people. It's easy to think that customers will love your app, but can you justify it? They make sure your final app is something that users truly want and need. The only way to do this is by ...
CloudEXPO | DevOpsSUMMIT | DXWorldEXPO are the world's most influential, independent events where Cloud Computing was coined and where technology buyers and vendors meet to experience and discuss the big picture of Digital Transformation and all of the strategies, tactics, and tools they need to realize their goals. Sponsors of DXWorldEXPO | CloudEXPO benefit from unmatched branding, profile building and lead generation opportunities.
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Cell networks have the advantage of long-range communications, reaching an estimated 90% of the world. But cell networks such as 2G, 3G and LTE consume lots of power and were designed for connecting people. They are not optimized for low- or battery-powered devices or for IoT applications with infrequently transmitted data. Cell IoT modules that support narrow-band IoT and 4G cell networks will enable cell connectivity, device management, and app enablement for low-power wide-area network IoT. B...
The hierarchical architecture that distributes "compute" within the network specially at the edge can enable new services by harnessing emerging technologies. But Edge-Compute comes at increased cost that needs to be managed and potentially augmented by creative architecture solutions as there will always a catching-up with the capacity demands. Processing power in smartphones has enhanced YoY and there is increasingly spare compute capacity that can be potentially pooled. Uber has successfully ...
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...