Sun Java Studio Enterprise Practice: Create a web application

xiaoxiao2021-03-06  47

Excern: http://gceclub.sun.com.cn/staticContent/html/2004-06-10/studio.html Be a few months ago Sun Microsystems announced Sun Java System, which is packaged, released, and A new method for pricing. Sun initially specifies a set of software that make up Sun Java System. Sun Java Enterprise System is one of them, which integrates a set of integrated standard-based enterprise services into a single package. These services include Web and application services, directory, and authentication services, portal services, and availability services.

As part of the Sun Java System Declaration, Sun also announced Sun Java Studio Enterprise, which is a developer solution for Java Enterprise System. Java Studio Enterprise includes tools and services for creating and testing applications on Java Enterprise System. In short, Java Studio Enterprise and Java Enterprise System provide developers with a complete set of solutions for development, testing, and deployment of corporate applications and web services.

Another early article introduced Java Studio Enterprise. It emphasizes some key features of Java Studio Enterprise, as well as the benefits of developers. The following article describes how Java Studio Enterprise is easy to create and test session beans, session beans are a component based on Enterprise JavaBean (EJB) and represents a customer of the J2EE server.

In this article, you will learn how to use Sun Studio's Web Application Framework to easily create a web application, Web Application Framework has been integrated into Java Studio Enterprise. (For simplicity, this article does not use "Web Application Framework" without "Sun Studio's Web Application Framework".) Web Application Framework not only simplifies the creation process of web applications, but also ensures that the web application meets the best design. The concept and has a high degree of scalability.

table of Contents

- Web Application Example - More Themes about Web Application Framework

Start Java Studio Enterprise Creating a new web application Creating a JDBC SQL query model Creating a Pagelet component Creating a Pagelet Add Pagelet to Page Add Navigation Control Test Web Application

Web application example

In the following example, you will learn how to quickly create a web application using the Web Application Framework already integrated into Java Studio Enterprise. With created web applications, users can visually browse records in the database. The following steps will describe the multi-functional features of the Web Application Framework such as visual and invisable components, and allowing the customization of user-defined components. In addition to the function of Web Application Framework, Java Studio Enterprise has many other functions for increasing the efficiency of developers, as well as a comprehensive development resource and support service, with the aim of solving the development, compilation, and testing process of applications. The problem encountered in.

More topics about Web Application Framework For web applications, if it should meet the needs of demand, its creation is relatively simple. But as demand growth, creating a web application will quickly become difficult. One of the most difficult needs is to make web applications with scalability to meet the growing growth of users (sometimes the number is very huge). It is difficult to make web applications that are scalable, and it will also increase the complexity of the application, and it is more difficult to maintain it. In order to meet these challenges, Java Studio Enterprise integrates powerful, flexible, and easy-to-use Web Application Framework. Web Application Framework provides you with a graphical environment and a reusable component so you can quickly create web applications, even WEB applications with highly complexity and maturity. The basis of the Web Application Framework is a Best Practice, a set of J2EE's best programs. Web Application Framework implements many of these design patterns in the code it generated. To do this, the Web Application Framework ensures the structure integrity of the web application and makes them highly scalable while easy to maintain.

Start Java Studio Enterprise

Start Java Studio Enterprise on the development platform you have chosen. It can run on the Solaris operating system, Microsoft Windows 2000, and Microsoft Windows XP. This example is running on the Solaris operating system. Once you start Java Studio Enterprise, it opens its integrated development environment (IDE). Select the VIEW menu from the menu bar. Then select Web Application Framework and Web Application Framework Explorer. This will open the Web Application Framework workspace. The work area consists of a set of windows, and it can perform a set of related tasks. In addition to the Web Application Framework workspace, you also have workspaces, GUI editing, and compilation of file editing related tasks in IDE. You can open any of these workspaces, just click on the appropriate tabs in the IDE. You can also create new workspaces or customize existing workspaces. Each workspace may have different layouts for a particular task. We can also use only one work area to configure it to display all windows and available resources. However, this work area will change very crowd. This is why everyone is happy to create different workspaces. The Web Application Framework workspace will display the Explorer window on the left side and display the Web Application Framework Apps and Runtime View tabs at the lower side. Note the toolbar in the Web Application Framework Apps view. By clicking icons on the toolbar, you can perform tasks related to the development web application. The center area of ​​the Web Application Framework workspace displays the Welcome window (when you open a file for editing, the area displays the Source Editing window), and the Output window below it. A window titled "Component Palette" is displayed on the right. (Note: If you have customized your Java Studio Enterprise environment, the layout of the workspace may be different.) Click Zoom

Create a new web application

Create a web application named PAGINATEDEMO:

Click the first one on the Web Application Framework workspace toolbar (that is, the one on the leftmost) icon. Open the New Application Wizard. There are also two other ways to open the New Application wizard. One is to select the File menu in the IDE menu, then select New. Open the New Wizard. In the New Wizard, expand the Web Application Framework node, select Application, and click Next button. The other is right-click the Web Application Framework node in Explorer and select the New Web Application Framework App. (These methods illustrate the flexibility of IDE). The New Application Wizard will prompt you to locate a location for your new application. This location consists of a basic directory and a web context. In this example, we use the default basic directory. Enter PAGINATEDEMO as the name of the Web context. Click the Finish button. Other panes in the wizard help you customize the web applications and its modules. For example, you can specify a package name for the web application, or specify a class name for a servlet as a web application before the WEB application. However, in this example, the default attribute of the web application and its modules is sufficient. As a response, you will see a notification window, which shows that the web application has loaded, and it also shows that it is a Web Application Framework application. The notification also illustrates a variety of ways to view the loaded web applications in the workspace and tell you the location of the technical documentation. Click the OK button to close the notification window. Note An Paging Demo node now appears in the Web Application Framework Web Apps view of the Explorer window. At the lower part of the Paginate Demo node, you will see three child nodes: Settings & Configuration, Application Classes, and Documents. Expand the Applications Classes node, then expand the Page InnDemo folder, and then expand the main folder. The main folder is very special because it is a module folder. The module folder is where all Application Framework components (such as Page, Model, and Command) are created. In this case, you will use a module folder and a simple Java package structure. However, Application Framework allows you to create many module folders and use complex Java package structures. Application Framework has no restrictions on how you schema your web application. This shows that you can create a highly complex web application using Application Framework. Create a JDBC SQL query model

You have learned that a web application can display a group of client records and allow you to visual browsing. In this case, these records come from a simple SQL database residing on the PointBase database server. Note that the PointBase database server and other useful development tools such as Tomcat Web servers, ANT XML-based script tools, and JUnit test tools are bound to Java Studio Enterprise.

You will need to start the PointBase web server before accessing the records in the database.

Start the PointBase web server:

Select PointBase Network Server in the Tools menu and select Start Server. Open the PointBase console. If you don't need it, you can minimize it. Next, you need to create a model that represents both the data you want to access, also represents an operation of retrieving the data. Note Web Application Framework is above a set of optimal programs called design patterns. Web Application Framework implements these modes when generating application code. One of the main patterns implemented by the Web Application Framework is the MVC (Model, View, Controller design mode. The MVC design mode divides the application's design into three obvious parts: Model, view (View), and Controller. The functions of each part are as follows: Model - represents business data and business rules responsible for data access and update management. This shows that the model represents both data, also represents the allowed data access and data operations. View - presenting the content of the model. That is, the view displays the data in the model to the user. Controller - Translates the interaction with the view into the operation performed by the model. This shows that according to the user's operation (for example, the user clicks a button in the view), the controller selects a set of suitable actions to be executed for the model. The controller then selects a view based on the operation result. Because the data you want to access exists in the SQL database, you need to create a JDBC SQL query model. This model is used to perform a query for the SQL database (via JDBC API). Create a JDBC SQL query model:

Select the main module folder from the Web Application Framework Web Apps view of the Explorer window. Click the Add Model icon on the Web Application Framework workspace toolbar. Now open New Model Wizard. New Model Wizard shows a list of available model types. Another method is to right-click the MAIN module folder in the Explorer window, then select Add, and select Model. Enter CustomerModel in the Name field. Select JDBC SQL Query Model as a model type and click Next button. Show the Select DataSource pane. Select JDBC / JDBC-POINTBASE from the drop-down list of the Select DataSource pane (unique options). The JDBC / JDBC-PointBase data source is automatically generated in the creation of a web application. You can create a data source that points to other databases as needed (such as databases from other developers). When you create a web application, you can choose to avoid creating the default data source. Click the Next button. Show the Select Database Tables pane. Select Customer_TBL from the list of available tables and click the Add button. Then click the Next button. Show the Select Table Columns pane. Click the Add All button. All columns in Customer_TBL are selected. Click the Finish button.

Click to enlarge

Click Zoom note a new model component called CustomerModel has been added to your MAIN module folder. Expand the CustomerModel node in Explorer. You will see a column node. A Java class is also created for the model. You can view the source code in this class by double-clicking the CustomerModel node (or its Java Source child node). In fact, you just pay attention to a component existing in the Web Application Framework component library, in this case, the JDBC SQL query component is referred to. The component library includes four types of components: model components, visual components, command components, and non-visible components. As the name suggests, the model component provides a model (ie, "M" is provided in an MVC design. The model provided by the JDBC SQL Query Components uses one or more tables in a SQL database as a data source. Visual component creates a user interface for web applications. Command components are used to package operations, such as requesting processing. Non-visual components provide support, such as configuration model instances. In this example, you will use visual, commands, and non-visual components. Create a Pagelet component

In this case, it is assumed that you want to display the customer record, display three records at once, and want to display the format of the table. To display data, you have to create a view. This view allows your application to display data in the model created in the previous step. Note The Web Application Framework component library contains visual components. These components create a user interface for web applications, and provide a view of the model.

Component libraries contain many different visual components, one of which is the Basic Container View component, also known as Pagelet components. A Pagelet provides a page. To display data, the Pagelet must be included in another visual component called Basic ViewBean, also known as the PAGE component. From this point of view, the Pagelet component is similar to the Panel component in Swing. The PAGE component is similar to the Frame component in Swing. Like Panel components, the Pagelet component is the basis for forming complex visual components.

The PageLet component can contain other visual components and are available for other Pagelet and Page throughout the web application. A single logical Page in the Web Application Framework application is usually corresponding to a PAGE component and an associated JSP page. When you create a Pagelet component (or page component), Application Framework gives you the opportunity to identify an associated JSP page. The next step in this example creates a PAGE component to provide more information about the PAGE component.

Click to enlarge

Click Enhance another visual component is a Basic TileDView component ((or simple, tiled view). A Tiled View is a Pagelet component, which can identify its child with a digital (called tile) (ie , Pagelet and other visual components such as display domains). The example is the list of tables or columns, or tabbed components tab. This function is exactly what you need to display three customer records. Create a Tiled View:

Select the main module folder from the Web Application Framework Web Apps view of the Explorer window. Click the Add Pagelet icon on the Web Application Framework workspace toolbar. Open Pagelet (ContainerView) Wizard. Pagelet (ContainerView) Wizard displays a list of available Pagelet Types. Alternatively, right-click the Main module folder in the Explorer window, then select Add, select Pagelet (ContainerView). Enter CustomerListPagelet as the name of the Pagelet and select Basic TileD View as the Pagelet type. Then click the Next button. The Associate JSP pane appeared at this time. In this pane, you can associate this PageLet with a JSP page. Click the radio button labeled "Create a JSP for this Component". At this time, the check box marked with "Use Default JSP Template" is automatically selected. Select the check box with "Use Formatting to Beautify Fields On JSP". Select this check box means a basic style sheet will be formatted in a simple table layout. To do this, use the default JSP / HTML syntax coloring code in Java Studio Enterprise to edit the JSP content of the original format. You can also use third-party HTML WYSIWYG editors. Click the Next button. Show the Model Associations pane. Extend the CURRENT Application Components node in the Model Associations pane until you see the CustomerModel component. Select the CustomerModel component, click the Add button, and then click Next button. Show the Bind Display Fields pane. Use the Control key to select multiple fields at a time, select the following CustomerModel field (all fields have prefix Customer_TBL _): Customer_Num, Email, Name, and Phone. Click the Add Field (s) button. Then click the Finish button to create a TileDView component. Note that a new Pagelet component called CustomerListPagelet has been added to your MAIN module folder. Expand the CustomerListPagelet node in Explorer to see the Visual Components child node. You will see four static text domains (with one marked). They are created after you choose in the Bind Display Fields pane in the Pagelet (ContainerView) Wizard. To do these, you need to bind the Pagelet to the field of CustomerModel associated with it. It also created a Java class for this Pagelet. To view the source code in the class, double-click the CustomerListPagelet node (or its Java Source child node). Create a PAGE component

As mentioned in the previous step, a PageLet provides a page. You can make a more complex PAGE component using many Pagelet components (and simple visual components such as Display Field and Button). Pagelet is a visible component, but if there is no help that contains its PAGE component, it cannot be displayed. Note that Similar Panel components in SWING. A Panel component is only displayed in an FRAME component. So the PAGE component is located at the top of the visual component hierarchy. Create a PAGE component as the parent container of the TileDView Pagelet. To create a PAGE component, select the Main Module folder from the Web Application Framework Web Apps view of the Explorer window. Click the Add Page (Viewbean) icon in the Web Application Framework workspace toolbar. So I opened Page (ViewBean) Wizard. Page (ViewBean) Wizard shows a list of available Page Types. (There is only one available Page Type: Basic Viewbean). Another method is to right-click the Main module folder in the Explorer window, then select Add, select Page (ViewBean). Enter CustomerlistPage as the name of the page and select Basic ViewBean as the Page Type. Then click the Finish button. Several options in the PageLand are the same as in the Pagelet wizard. If you don't click the finish button, but click the Next button to display the Associate JSP pane. In this example, you don't need to create a JSP page so that the Page is associated - the wizard creates a JSP page by default. Moreover, it is also necessary to associate this page with any model, so it is not necessary to display the Model Associations pane. Note that a new Page component called CustomerListPage has been added to your MAIN module folder. Expand the CustomerlistPage node in Explorer to see the Visual Components child node. It has no child nodes. In the next step, you will add Visual Components with Component Palette. A Java class is also created for this page. To view the source code in the class, double-click the CustomerListPage node (or its Java Source child node).

Click to enlarge

Click to enlarge

Add PageLet to PAGE

Web Application Framework is a component-friendly. That is, the components you create are easy to reuse. You can add the Pagelet component (CustomerListPageLet) to the PageLet component (CustomerlistPage) only needs to be specified and click. You can also use the Web Application Framework API to manually complete this task (to learn more about using the Web Application Framework API, see the Sun Java Studio Web Application Framework Development Guide). When you need more flexible and more complex display logic, you will be useful to manually complete the Web Application Framework task by API. However, in most cases, a graphical approach, that is, specifying and clicking is a quick and efficient method.

Add a CustomerListPagelet component to the CustomerListPage component:

Click to enlarge

Make sure the Component Palette is visible. If it is not visible, select Web Application Framework in the View menu, then select Component Palette. In Component Palette, the default view is the Visual Components layer. Select the CustomerListPage component in the Web Application Framework Web Apps view of the Explorer window. Select the Application Visual Component layer in Component Palette. The Application Visual Component layer is located at the bottom of the Component Palette, the displayed icon is. After selecting this layer, Component Palette displays the visual components of all current applications. There is only the visible component CustomerListPagelet displayed here. Once you have created additional Pagelet in your application, they can reserve them in the Application Visual Component layer. Select the CustomerlistPagelet component in Component Palette. Select this component to add a new child node to the Visual Components node of CustomerListPage. If you display the Java source code for CustomerlistPage in your editor, you will find additional code generation. If you look at the JSP page associated with it, you will find a new tag to be added to the JSP page. Select New Visual Components Children Customerlistpagelet1 in the Explorer window. In the property page, change the max display tiles attribute value, range is -1 (all rows) to 3. Here, the word "tile" is more common than "ROW".

Add navigation control

So far now, you have created a web application that can access three clients in the database. If you run the app, you will find three records on this page, but there is no way to browse the rest of the record. One of the objectives of this example is to allow users to browse all customer records. In order to be able to make navigation, you need to add an appropriate button (such as first, next, previous, and last) and configure it in order to use the built-in WebAction (WebAction can implement specific actions associated with the model). The JDBC SQL query model in the Web Application Framework and associated WebAction can complete all the basic work of the record navigation. Note that the record navigation is not limited to SQL-based models, and can also be applied to any model type that can process multi-record. Record navigation is based on the model interface available in the Web Application Framework API. To learn more about these interfaces, see the Sun Java Studio Web Application Framework Development Guide.

Not creating and adding a separate button, now let us create and add a component, which contains four pre-configured buttons to complete the record navigation function. Keep in mind that the Web Application Framework (and Tools) is based on the component. Advanced component architecture allows developers to create a variety of components. To simplify the operation, a component library containing multiple components has been created for the application PAGINATEDEMO. One component in this library provides the necessary buttons, each buttons perform proper configuration to complete a certain navigation function.

To access the component library, download the file paging.jar. Save the JAR file to your application's web-inf / lib directory (web-inf ± lib for windows). For example, if the PAGINATEDEMO application you created is in the directory / JStudio_6ee_user, save the JAR file to / JSTUDIO_6EE_USER / WEB-INF / LIB. In response, Java Studio Enterprise recognizes that a JAR file has been added to the lib directory of your web application (this will not cost too long, maybe only few seconds, depending on the performance of the machine). In addition, Java Studio Enterprise also sees the JAR file as a component library for Web Application Framework. (Included in the JAR file is a description file, which specifies the JAR file as a Web Application Framework component library.) The components included are displayed in different Java Studio Enterprise wizards and Component Palette. You will see the PAGINATE.JAR component at the bottom of the Visual Components layer in Component Palette.

Now the component library is available, add the navigation control in the library to the Page.

Select the CustomerListPage node or its Visual Components node in the Web Application Framework Web Apps view of the Explorer window. Click the First Prev - next - Last component in the Visual Components layer of Component Palette, add it to the page. Select the new Visual Components child node PAGINATEControls1 in the Explorer window. In the Property table, set the value of the attribute named Target Container Path to CustomerListPagelet1 (the name of the CustomerListPagelet visual component). Use the instance name of the visual component (CustomerListPagelet1) instead of a formal component name (CustomerListPagelet). This property allows you to locate a specific container that can be made in it. If you specify a blank value or use the default ("/"), the target container view is the father of the navigation control itself, that is, CustomerListPage. In fact, it is the final model. Target containers associated with the model are used to retrieve records. In this case, the target container view is an instance of the CustomerListPagelet, which is called CustomerListPagelet1. The depth of the target container view is more common. If you prefer, you can change the tag of the button, the current label is | << (First component), >> | (LAST component), -> (Next component), and <- (Previous components).

Click to enlarge

Note that the PAGINATE.JAR component library is just a prototype. Its purpose is not to indicate a finished product, but to illustrate the powerful functionality of the Web Application Framework component architecture and easy-to-use features. When you test a web application, you will find that the first (| <<) and Previous (<-) buttons are in an invalid status when the first record display of the database (as expected). However, if you click the Last (>> |) button to navigate to the last record of the recordset, you will find that next (->) and last (>> |) buttons are not inactive (not expected) . Test web application

Clicking To enlarge now is the time to test the web application. To test, you need to compile, deploy, and run the web application. However, the following work needs to be made before doing these steps:

Make sure the Sun Java System Application Server is running. Expand the Installed Servers node in the Web Application Framework Runtime view of the Explorer window. Then expand the Sun Java System Application Server 7 node, and then expand the localhost: 4848 node. Right-click the application server instance for the label Server1 (localhost: 8080), then select Status. Then display a status window of the application server instance. This state indicates that the application server instance is running. If the status is stopped, you can click the Start Server button in the Status window to launch the application server instance. Make sure this application server instance is the default server. Expand the DEFAULT Servers node in the Web Application Framework Runtime view of the Explorer window. The application server instance of the label Server1 (localhost: 8080) should be listed as the default server. If not, expand the Sun Java System Application Server 7 node, then expand the localhost: 4848 node. Right-click the application server instance for the label Server1 (localhost: 8080), then select Set As Default. Make sure the PointBase web server is running. If the PointBase web server is not running, select PointBase Network Server in the Tools menu, then select Start Server.

To compile, deploy, and run the web application, please:

Right-click the Paginate Demo application node in the Web Application Framework Web Apps view of the Explorer window and select Compile ALL. You will see a message that describes the successful Web application. Click the Paginate Demo application node again and select Deploy. At this time, there will be a dialog window displays the progress of the application deployment. If you have modified it after the web application deployment, you will need to recompile and redeploy. Right-click CustomerListPage in the Web Application Framework Web Apps view of the Explorer window and select Execute Page. As a response, you will see a Page that displays a table containing three clients recorded from the sample data. Click the navigation button to display the first, the last, the next, and the previous record. If you have modified the web application and to be tested, select Execute Page (RedEPloy). This will ensure that the previous version of the application is completely cleared from the memory of the application server. As the next exercise, you can add record statord components (Record Status Component) to the same page, and configure it in the same way as configuring navigation components. This will add a recording status message. For example, when you display the first one in three records, the message is displayed as "Records 1 TO 3".

Like the Paginate component library, recording stator components (Record Status Component) is a prototype and does not function. For example, recording status messages should display "Records 1 To 3 of 13", not simple "Records 1 to 3".

Reference

Sun java system

Sun Java Enterprise System

Sun Java Studio Enterprise

Introduction to Sun Java Studio Enterprise

Sun Java Studio Enterprise In Action: building a session bean

Blueprints: patterns

Sun Java Studio's Web Application Framework Developer's Guide

About author

Ed Ort is a staff member of developers.sun.com and java.sun.com. Published many articles about relational database technologies, programming languages, and Web services.

Reggie Carey is a senior system engineer of Sun Microsystems, Inc., has been engaged in software development and management. Participate in two writings for software technology books, have been experienced in the computer industry. Reggie occasionally comments on the application server and integrated development environment.

Craig Conover is Sun Microsystems, Inc. Inc., mainly engaged in Sun Java System Application Framework (JATO) project. He has 11 years of software industry experience, engaged in the research and development of Web application frameworks, tools, and applications. Its career begins in 1996, engaged in consultants, lecturers and other work.

转载请注明原文地址:https://www.9cbs.com/read-53967.html

New Post(0)