Bibhas Bhattacharya, Web Age Solutions Inc.
WebLogic Workshop introduces a new framework that implements the Model View Controller (MVC) pattern. The framework, as it exists within Workshop, has no single official name. It is generally known as the Page Flow and Control framework. BEA has donated the framework to Apache as theBeehive project. The View and the Controller portion of the framework - called Page Flow - is built as an extension of the Struts framework. This is how the MVC pattern is implemented.
The model layer can be built using Plain Old Java Objects (POJO) or EJB. Workshop introduces an alternative technology - called Control - that can also be used to implement the model layer.
Theview layer is built using JSP and a set of custom tags supplied by the Workshop framework. These tags are known as the NetUI tags. Struts custom tags have been completely abandoned by the framework and replaced by the NetUI tags.
The controller layer is built using Page Flow. If you are new to Page Flow, think of it as a replacement for Servlet or Struts Actions. A Page Flow is a Javaclass with .jpf file name extension. You develop public methods in that class. The method's name can be used as the action attribute of a form. When the form is submitted, system executes the method. These methods are called actions. Behind the scene, system actually registers a Struts action for each of these methods. One advantage of Page Flow over tradtional Struts action is that, a Page Flowcan have many methods. Essentially, multiple related Struts actions can be implemented using a single Page Flow class.
Struts and Page Flow
It is almost an academic discussion that the Page Flow framework uses Struts under the covers. On the surface the two are significantly different. If you know Struts, you will still need to learn about Page Flow. The motivation behind Page Flow was tosimplify web development beyond the level of simplicity already achieved by Struts. The focus of this article is the Controller layer, or, Page Flow. Subsequent articles will get into the other two layers of MVC.
Build a Project Structure
Launch WebLogic Workshop. From the menubar, select File->New->Application.
Enter BasicApp as the name of the application. Click on Create.
You can think ofan application as a J2EE Enterprise Application. You can add mutiple web and EJB modules within the application. An application is exported as a EAR file that can be deployed in a production server. An application is configured to be deployed to a WebLogic server for testing and debugging. A test server is already configured in the samples/domains/workshop folder as a part of the Workshopinstallation. Applications are deployed to that server by default. (See the Server dropdown list in the screenshot above).
When an application is created, system automatically adds a web module project. In our case, this project is called BasicAppWeb. You can add additional web or EJB module projects to this application. We are not going do that for this article.
Create a Simple Page Flow
Acontroller has two primary responsibilities: 1. Convert data from HTTP request to a data structure the model layer can work with. In HTTP, all request data is of String data type. The controller needs to build input objects and convert String to other data types if needed (such as int or java.sql.Date). 2. Determine the view that needs to be displayed under a given circumstance. For example, after thelogin action is performed, a controller needs to display the home page. This act of view selection is essentially what determines the page navigation flow of a web site. In this step, we will learn about the second responsibility of a controller - page navigation flow. We will build a controller (Page Flow class), that will display odd.jsp or even.jsp depending on whether the number URL parameter...