|
|
A Tour Through WebLogic Workshop 8.1: Westside Auto Sales Domain SetupNow we need to create a connection to our database in our WebLogic Server domain. We will be using the "Workshop" domain that ships with the WebLogic samples (found in [BEA Install Directory]\WebLogic81\samples\domains\workshop). To add the services we need, first start the domain and then go to the console (usually http://localhost:7001/console) and log in (username: First, we will set up the connection pool. Under JDBC on the main page, select "Connection Pools". Click "Configure a new JDBC Connection Pool", then choose the database type and select a driver. Because we will be using transactions, you will need to choose an "XA" driver. Because I am using Microsoft SQL (with the JDBC driver service pack), I choose BEA's MS SQL Server Driver (Type 4XA). Name the pool "WASPool". Test the connection, and then create and deploy it on the server. Because we will be using local transactions, click on the new "WASPool", choose the "Connections" tab and then advanced options. Check the "Supports Local Transactions" and click on "Apply". Once the pool is created, we can create a data source. Click on the Home icon in the upper right-hand side of the page, and then choose "Datasources" under JDBC. Click on "Configure a JDBC Data Source", use "WASDataSource" as the name and the JNDI name. Click "continue", and then choose "WASPool" as the connection pool. Then click "continue" and then "create". Now we need our JMS topic for our messaging. In the left-hand side of the console, go to Services\JMS\Servers\cgJMSServer\Destinations and configure a new JMS topic. Set the name and JNDI name as "WASTopic" and click "Create". Once the new topic is created you will need to restart the server. Web ApplicationNow we are ready to start building our application. We will start with the Web application. Launch WebLogic Workshop 8.1 and create a new default application called "Westside". Web applications in WLW use a new technology called Page Flows. Based on the Struts framework, Page Flows allow you to separate business logic from display logic. This means rather than filling your JSP files with lots of code, you put all your code in the JPF. This will become clear once we start building our site. We were given a default page flow to start with. Let's start up the server and run our page flow once to see what we are working with. Open the Controller.jpf under the WestsideWeb directory and hit the play button in the toolbar. Once the site is compiled you should get a page in the test browser that says "New Web Application Page". Our site is not very exciting yet, but that will change soon. The first part of our application involves showing the current vehicle inventory to the user. Normally we would spend hours building JSPs that display the results of a rowset, allow for filtering and sorting, allow for pagination, etc. With WLW this task is easy. First we need a RowSet Control to access the data in our database. We will put all our controls in a new folder called "Controls" under the "WestsideWeb" folder. Create the new folder then right-click on it and choose New\Other File Type\RowSet Control. In the RowSet Control Wizard, name the new control
Let's finish up the rest of the Web interface. First we will put a link to this new page flow from our main page. It's also good to have a link back to the home page. Let's add it in the title bar of the Inventory section. Because every page uses NetUI templates, we can add the link in the file WestsideWeb\resources\jsp\header.jsp and it will appear on every Inventory page. Add the following code to this file (code to add in italics):
If you re-run the InventoryController.jpf file, you should see the navigation at the top of the page:
Now that we have a common navigation system, let's add this template to our home page. Go back to index.jsp under WestsideWeb and change it to look like this:
Now we'll add the code to allow users to buy a car. First we need a "
Because you can only buy a car if it is available, we first check to make sure the car has not been sold, and then we show the link. To do this, first we create a local instance of the DatabaseForm that holds all our detail information. Then we can access members within this form. Notice, our link to buy the car is a link to an action on the page flow, not a hard link to a file. As you add this code, you will get a blue popup message asking if you want to add an import statement for Inventory.InventoryController.DatabaseForm to the page. Hit Alt+Enter to accept the import. This adds the following to the top of the page:
There will be several other instances when you add code from this article that you will need to accept the import statements WebLogic Workshop suggests. If you switch back to design view of the InventoryController.jpf you should see the new action and page in the context of the rest of the site:
|