Discuss this tutorial. Printable version (PDF).
Go to Contents page. Go to previous page. Go up a level. Go to next page.

 

 

Implementation


This section describes how the BC4J-VSM uses Struts and JBO tags together with the BC4J framework to display a list of orders to a mall customer.

The Struts technologies used are:

  • Struts Controller Sevlet - MVC Controller servlet which controls all access to application.

  • Struts Action - A java class designated to handle a Struts application Action which is in the form of a URL request.

  • Struts ActionForm (Form Bean) - A Java class which represents the contents of an HTML form. It also provides a validation method.

  • Struts "Bean" and "HTML" tag libraries - JSP tag libraries which allow for interaction with Struts components from JSP.

  • Struts-Config.xml - The master configuration file for all Struts applications.

  • ApplicationResources.properties - A resource file which can store multi-lingual messages and data for a Struts application.

JDeveloper provides these facilities to develop a web application based on Jakarta Project's Struts framework that you deploy as either Java servlets or JavaServer Pages.

  • The Struts Configuration Editor lets you manage the struts-config.xml file, which defines the ActionMappings for your application. The Struts controller uses the mappings to turn HTTP requests into application actions.

  • The various Struts dialogs in the Web Tier - Struts category of the New Gallery let you add the Struts framework components to a generic JSP web application. When you add Struts to a generic JSP project, you may also work with BC4J through its request processor (BC4JRequestProcessor).

  • The BC4J Struts JSP Web Application Wizard in the Web Tier - Struts-Based JSP for Business Components category of the New Gallery lets you generate an entire databound web application. The generated JSP pages rely on a BC4J-specific action controller that functions with a model implemented by Oracle's data access layer, Business Components for Java (BC4J).

For work with Struts and BC4J frameworks, JDeveloper provides a set of wizards that resemble the standard (non-Struts) BC4J JSP page wizards, but they generate a web application that relies on a BC4J-specific request processor for use in the Struts MVC paradigm. The wizard-generated code implements the BC4J framework and provides full database access, state management, and transaction control to web application clients.

For example, the BC4J JSP Struts Web Application Wizard helps you create an entire web application based on a Business Components project. Standard actions are implemented using the Struts framework and a Struts version of the component tags from the BC4J Data Tags custom tag library.

All Struts actions begin with a URL that is submitted to the JSP request object when the end user clicks a Struts-defined link. The link must be of the form actionPathName.do, where the extension .do causes the ActionServlet to locate the corresponding action in the struts-config.xml configuration file.

The runtime process for handling actions in the Struts framework implemented by the BC4J component tags is:

  1. User clicks a link that submits a .do parameter.
  2. ActionServlet maps the request URI to the Action class through the definition in struts-config.xml.
  3. The action class processes the request through a method implementation.

The following HTML code (with jbo tags) comes from mallUsers/allOrders.jsp. It includes an HTML anchor tag that defines a link to manageorder.do.

<%UserOrdersRow row = null;%>
<jbo:RowsetIterate datasource="OrderTrackingService.UserOrders">
<jbo:Row id="currRow" action="Active"
datasource="OrderTrackingService.UserOrders"/>

<%
row = (UserOrdersRow)currRow;
%>
<TR>
...
<TD align="center" class="BlackText" width="82">
<A href="manageorders.do?jboRowKey=
<%=row.getKey().toStringFormat(true)%>
&jboEvent=getOrders"
class="Link">Details</A>

</TD>
</TR>
</jbo:RowsetIterate>

The following XML code comes form struts-config.xml. It defines the action manageorders, specifying a Java class (OrderEditAction) and method (getAllOrders) to handle the action, and associated JSPs (including allOrders.jsp).

...
  <action path="/manageorders" parameter="jboEvent" 
scope="request"
type="oracle.otnsamples.vsm.controllers.user.OrderEditAction"
validate="false">
<set-property property="releasemode" value="Stateless"/>
<set-property property="application" value="OrderTrackingService"/>
<set-property property="viewobject" value="UserOrders"/>
<forward name="getOrders" path="/jsps/mallUser/myOrders.jsp"/>
<forward name="getAllOrders" path="/jsps/mallUser/allOrders.jsp"/>
</action> ...

The following Java code comes from OrderEditAction.java. It implements the action method defined in the Struts configuration file (shown above). It imports Struts action classes (org.apache.struts.action.*) and BC4J classes (oracle.jbo.*) to gain access to those frameworks' functionality. This code calls BC4JContext.getContext to get context data from the HTTP request parameter, then uses this data to instantiate the UserOrders View Object, a BC4J component. Then the code uses the View Object to execute a query and iterate through the results.

package oracle.otnsamples.vsm.controllers.user;
...
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import oracle.jbo.client.JboUtil;
import oracle.jbo.ViewObject;
import oracle.jbo.html.struts11.actions.EditAction;
import oracle.jbo.html.struts11.BC4JUtils;
import oracle.jbo.RowIterator;
import oracle.jbo.Key;
import oracle.jbo.html.BC4JContext;
import oracle.jbo.Row;

import oracle.otnsamples.vsm.views.common.UserOrders;
import oracle.otnsamples.vsm.views.common.UserOrdersRow;
import oracle.otnsamples.vsm.views.common.OrderItemsRow;
import oracle.otnsamples.vsm.views.common.ItemRow;
import oracle.otnsamples.util.Utilities; ...
public ActionForward getAllOrders(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {

BC4JContext context = BC4JContext.getContext(request);
try {
String uName = (String)request.getSession().getAttribute("USER_NAME");
UserOrders orders = (UserOrders)context.getViewObject();
orders.setUserName(uName);
orders.executeQuery();

UserOrdersRow row = null;
double total = 0.0;
RowIterator iter = null;
OrderItemsRow currRow = null;
while(orders.hasNext()) {
row = (UserOrdersRow)orders.next();
total = 0.0;
iter = row.getOrderItems();
while(iter.hasNext()) {
currRow = (OrderItemsRow)iter.next();
total += currRow.getUnitPrice().doubleValue() *
currRow.getQuantity().doubleValue();
}
request.setAttribute(row.getId().getSequenceNumber().stringValue(),
new Double(total));
}
orders.reset();
}
catch(Exception ex) {
...
}
return BC4JUtils.getForwardFromContext(context, mapping);
}

The other tutorials in this series describe various application features and explain how they were implemented.


Discuss this tutorial. Printable version (PDF).
Go to Contents page. Go to previous page. Go up a level. Go to next page.
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy