Previous     Contents     Index     Next     
iPlanet Market Maker 4.5 Customization Guide



Chapter 4   Customizing the Auction Module


This chapter contains the following sections:



Overview

"Extending Event Handling" in Chapter 3 described the general process for customizing modules. This chapter describes a customization for the Auction module. It describes how to add a navigation link to an existing page through the extension of an existing event handler. It also describes how to add a new page flow by creating a new event handler and JSP.

For additional information about how the event handling mechanisms work, refer to the comments in the code examples in this chapter.

The example in this chapter adds a Terms and Conditions link to the Auction Bidding page that links to a Terms and Conditions page. The Terms and Conditions page provides a link to return to the Auction Bidding page. The content of the Terms and Conditions page is specified by the Auction Initiator when the auction is initiated and is not covered in this chapter.

Figure 4-1 shows part of the Auction Bidding page with a Terms and Conditions link.

Figure 4-1    Auction Bidding Page with Terms and Conditions Link




Extending Event Handling for the Auction Bidding Page



As described in "Interpreting Event Handlers"in Chapter 3, each user interaction is mapped to an action code and event handler. So the Terms and Conditions link in Figure 4-1 needs to have an action code and event handler to be able to link to the Terms and Conditions page. The following example reassigns an existing action code to a new event handler. It also creates a new action code and event handler.

The mapping of action codes to event handlers is defined in an XML file, which is shown in the following SunBidAuctionEvents.xml file.

<?xml version="1.0"?>

<EventMap class="com.sun.ecommerce.sunbid.auction.display.AucJSPSB">

<!-- Override the event handler for the Auction Bidding screen -->

<EventHandler symcode="ACT_BIDDER_BID"                       class="com.sun.ecommerce.sunbid.auction.display.EventHandlerBidderBidSB" />

<!--Add a new event handler for the Terms and Conditions page -->

<!-- Java constant ACT_BIDDER_TANDC_DISPLAY is defined in AuctionConstants.java -->

<EventHandler symcode="ACT_BIDDER_TANDC_DISPLAY"                             class="com.sun.ecommerce.sunbid.auction.display.EventHandlerCommonTandC" />

</EventMap>

The SunBidAuctionEvents.xml file first calls the AucJSPSB class to ensure that the constants defined in the AuctionConstants class can be referenced by the SunBidAuctionEvents.xml file. The code for the AucJSPSB class is as follows.

public class AucJSPSB extends AucJSP implements AuctionConstants {

// intentionally left blank. This class is created to ensure the // constants defined in AuctionConstants can be referenced in
// SunBidAuctionEvents.xml

}

The code for the AuctionConstants class is as follows.

public interface AuctionConstants {

// Define offsets with USER_OFFSET to ensure custom action codes do not conflict // with base product action codes. Action codes must be unique

public static final int USER_OFFSET = com.iplanet.ecommerce.vortex.auction.AuctionModule.USER_OFFSET;

public static final int OFFSET = USER_OFFSET;

// Define custom action codes for the Terms and Conditions Page

public static final int ACT_BIDDER_TANDC_DISPLAY = OFFSET + 3;

}


Assigning an Existing Action Code to a New Event Handler

Next the SunBidAuctionEvents.xml file assigns the existing action code "ACT_BIDDER_BID" to a new EventHandlerBidderBidSB class to extend the existing functionality of the class originally assigned to"ACT_BIDDER_BID". The EventHandlerBidderBidSB class uses the existing EventHandlerBidderBid class and adds new functionality to it.

The code for the EventHandlerBidderBidSB class is as follows.


/**
 * This class is the event handler for ACT_BIDDER_BID
 */
public class EventHandlerBidderBidSB extends EventHandlerBidderBid
    implements IEventHandler, AuctionConstants {
    public DisplayBean execute(IEventContext ctx) throws VortexException {
    Guid auctionGuid;
    // Invoke the parent event handler
    PresentationBean bidScreenBean = (PresentationBean) super.execute(ctx);
    if (ctx.isRefreshable()) { // when REDISPLAYing
    auctionGuid = getSavedParamGuid(ctx, ATTR_ROWBEAN_GUID_STRING,
    INVALID_GUID);
    } else {
    auctionGuid = getParamGuid(ctx, ATTR_ROWBEAN_GUID_STRING,
    INVALID_GUID);
    }
       // Create Terms and Conditions link
    NVPLinkGen tandcDisplayLink = ctx.makeLinkGenerator();
    tandcDisplayLink.addAction(ACT_BIDDER_TANDC_DISPLAY);
    tandcDisplayLink.addNVPair(ATTR_ROWBEAN_GUID_STRING,auctionGuid.toString() );
    bidScreenBean.put(ATTR_BIDSCREENBEAN_TANDC_DISPLAY_LINK, tandcDisplayLink);
    }
}



Defining a New Action Code and Event Handler

Finally the SunBidAuctionEvents.xml file defines a new action code "ACT_BIDDER_TANDC_DISPLAY" mapped to a new event handler "EventHandlerCommonTandC". Note that in the AuctionsConstants class shown in the "Extending Event Handling for the Auction Bidding Page" section, a offset range predefined in AuctionModule.USER_OFFSET is added to the action code value of 3 that corresponds to the "ACT_BIDDER_TANDC_DISPLAY" symbolic action code name. This offset value ensures that each action code number is unique.

The code for the "EventHandlerCommonTandC" class is as follows.


public class EventHandlerCommonTandC extends EventHandlerAuction implements IEventHandler {
    public DisplayBean execute(IEventContext ctx) throws VortexException {
        Guid auctionGuid;
        PresentationBean presentationBean = new PresentationBean(ctx);
        // Create data beans and extract data
        DataBeanTandC dataBeanTandC = new DataBeanTamdC(ctx);
    auctionGuid = getSavedParamGuid(ctx, ATTR_ROWBEAN_GUID_STRING, INVALID_GUID);
    dataBeanTandC = (DataBeanTandC)readFromSession("SESS_AUCTIONTANDCBEAN",
                AuctionConstants.ACT_COMMON_TANDC_DISPLAY, ctx);
    } else {
         auctionGuid = getParamGuid(ctx, ATTR_ROWBEAN_GUID_STRING, INVALID_GUID);
// Grab the Terms and Condition content based the auctionGuid from
// the Auction object

            // Customization of back-end objects not covered in this example.
            String tandc = "Terms and Conditions goes HERE!";
            dataBeanTandC.setTandC(tandc);
          }
            // create Return to Previous link
         NVPLinkGen prevLink = ctx.makeLinkGenerator();
         prevLink.addNVPair(ATTR_ROWBEAN_GUID_STRING, auctionGuid.toString() );
         prevLink.addAction(ACT_BIDDER_BID);
         // populate the returning PresentationBean
         presentationBean.put(ATTR_BIDSCREENBEAN_PREV_LINK, prevLink);
         resentationBean.put("DataBeanTandC", dataBeanTandC);
         // Prepare for REDISPLAY - save paramMap in session
         String params[] = { ATTR_ROWBEAN_GUID_STRING };
         String values[] = { auctionGuid.toString() };
         saveParamMap(params, values, ctx);
         // Save AuctionTandCBean to session
         writeToSession("SESS_AUCTIONTANDCBEAN",
             AuctionConstants.ACT_COMMON_TANDC_DISPLAY, dataBeanTandC, ctx);
         presentationBean.setJSP("auction/CommonTandC.jsp");
         return presentationBean;
     }
}



Displaying the Added JSP

The event handler EventHandlerBidderBidSB calls the CommonTandC.jsp to display the Terms and Conditions page. The code for the CommonTandC.jsp is as follows.


<%@ include file="../include/AuctionInclusionHeader.jsp" %>
<%@ page import="com.iplanet.ecommerce.vortex.community.display.*" %>
<%@ page import="com.sun.ecommerce.sunbid.auction.display.DataBeanTandC" %>
<%@ page import="com.sun.ecommerce.sunbid.auction.display.AuctionConstant s" %>
<%
     PresentationBean bean =
                 (PresentationBean) request.getAttribute("DisplayBean");
<%-- Get the Terms and Conditions DataBean --%>
                 DataBeanTandC dataBeanTandC =
                 (DataBeanTandC)bean.getDisplayBean("DataBeanTan dC");
%>
<FORM ACTION="<%= bean.getPortalURL() %>" name="<%= bean.getFormName() %>" METHOD="post">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="95%" ALIGN="center">
<TR>
<TD CLASS="mainTitle" ALIGN="left">Auctions : Terms and Conditions<BR>&nbsp;</TD>
</TR>
<TR>
<TD>
        <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="33" WIDTH="100%">
        <TR>
        <TD CLASS="pagetitle" ALIGN="left" VALIGN="top" WIDTH="1%"><IMG HEIGHT="15" SRC="images/curve_left.gif"></TD>
        <TD CLASS="pagetitle" ALIGN="left" VALIGN="middle">
                <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="19">
                <TR>

                     <TD NOWRAP CLASS="dark"><IMG SRC="images/buttons/b_left.gif" BORDER="0"></TD>

                     <%-- Return To Previous link --%>
                      <TD NOWRAP CLASS="dark"><A CLASS="buttonText" HREF="<%= bean.getNavigation(ATTR_BIDSCREENBEAN_PREV_LINK) %>">< Return to Previous</A></TD>
                     <TD NOWRAP CLASS="dark"><IMG SRC="images/buttons/b_right.gif" BORDER="0"></TD>
                    </TR>
                    </TABLE>
         </TD>
         <TD CLASS="pagetitle" ALIGN="right" VALIGN="top" WIDTH="1%"><IMG HEIGHT="15" WIDTH="17" SRC="images/curve_right.gif"></TD>
         </TR>
         </TABLE>
</TD>
</TR>
<TR>
<TD><!-- begin the inner nested table-->
        <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
        <TR>
        <TD WIDTH="3%">&nbsp;</td>
        <TD WIDTH="94%">
        <!--##############enter content here###################-->
<TABLE BORDER="0" WIDTH="90%" CELLSPACING="0" CELLPADDING="0">
    <TR>
        <TH CLASS="menu" height=20 align="left">
            Terms and Conditions
        </TH>
   </TR>
</TABLE>
<TABLE BORDER="0" WIDTH="90%" CELLSPACING="0" CELLPADDING="0">
   <TR>
     <TD CLASS="fieldvalue" nowrap>
     <form>
     <table width="50%" border=0 cellspacing=0 cellpadding=2>
     <tr>
     <td width="50%" ALIGN="RIGHT" BGCOLOR="#000000">
        <table width="100%" border=0 cellspacing=0 cellpadding=2>
        <tr>
        <td BGCOLOR="#DFDFDF" ALIGN=left>
                      <FONT COLOR="darkblue">
                      <STRONG>
                      Terms and Conditions:<BR>
                      Product Name
                      </STRONG>
                      </FONT>
                      <FONT COLOR="darkblue" SIZE="-1">
                      <P>
                      By viewing this page,
                      you agree to the terms and conditions below.
                      </P>
                      </FONT>
                      <font size="-1">
                      <textarea wrap = "virtual" readonly rows="20" cols="60">
                      <%-- Get the text for Terms and Conditions --%>
                      <%= dataBeanTandC.getTandC() %>
                      </textarea>
                      </font>
   </td>
   </tr>
   </table>
</td>
</tr>
</table>
</form>
         </TD>
         </TR>
</TABLE>
                 <BR>
         </TD>
         <TD width="3%">&nbsp;</td>
         </TR>
         </TABLE>
         <!-- end of the inner nested table-->
         <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="33" WIDTH="100%">
         <TR>
         <TD CLASS="pagetitle" ALIGN="left" VALIGN="bottom" WIDTH="1%"><IMG HEIGHT="15" SRC="images/curve_bottom_left.gif"></TD>
         <TD CLASS="pagetitle" ALIGN="left" VALIGN="middle">
                 <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" HEIGHT="19">
                 <TR>
                 <TD NOWRAP CLASS="dark"><IMG SRC="images/buttons/b_left.gif" BORDER="0"></TD>
                 <TD NOWRAP CLASS="dark"><A CLASS="buttonText" HREF="<%= bean.getNavigation(ATTR_BIDSCREENBEAN_PREV_LINK) %>">< Return to Previous</A></TD>
                 <TD NOWRAP CLASS="dark"><IMG SRC="images/buttons/b_right.gif" BORDER="0"></TD>
                 </TR>
                 </TABLE>
         /TD>
         <TD CLASS="pagetitle" ALIGN="right" VALIGN="bottom" WIDTH="1%"><IMG HEIGHT="15" WIDTH="17" SRC="images/curve_bottom_right.gif"></TD>
         /TR>
   </TABLE>
</TD>
</TR>
<TR><TD NOWRAP WIDTH="760" BGCOLOR="#FFFFFF"><!--this row is to force the minimum table width to 760-->&nbsp;</TD></TR>
</TABLE>
<%= bean.getButtonInfo() %>
</FORM>


Figure 4-2 shows part of the Terms and Conditions page.

Figure 4-2    Terms and Conditions Page



Previous     Contents     Index     Next     
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.

Last Updated March 25, 2002