C H A P T E R  11

Tutorial--Section 2.5
Link Login Page to Customer Page

This chapter describes how to link the LoginPage to the CustomerPage in the Suntrademark ONE Application Framework application, filtering the data the Customer page displays based on the customer's login.


Task 5: Link the Login Page to the Customer Page

Edit the handleLoginRequest Method in LoginPage

Edit the LoginPage.java file.

Modify the logic in the handleLoginRequest() method as shown in the code example below so that in the event of a successful login, the Customer page displays with the customer data that corresponds to the value entered in the User Name field.



Note - In the code example below, the only legal values for the User Name field are also CustomerID values from the customer table.

Therefore, you can take the Login ID value and apply it to the WHERE clause used by the CustomerModel.

This ensures that the data retrieved by the CustomerModel corresponds to the appropriate CustomerID.

Make code changes cautiously.

The code that appears below practically replaces all of the code that appeared previously in this event.

Adding just what appears to be the delta will likely lead to errors. It is best to just delete the current code and replace with the following.



Following is the code you need to enter to modify the logic in the handleLoginRequest() method.

public void handleLoginRequest(RequestInvocationEvent event) 
{
    // Retrieve the customer number 
    String custNum = getDisplayFieldStringValue(CHILD_CUSTOMER_NUM); 
    String theMessage = ""; 
 
    // Check the customer number 
    // Note, we don't check the password in this example 
 
    if (custNum.equalsIgnoreCase("1") || 
        custNum.equals("777") || 
        custNum.equals("410")) 
    { 
        // Instead of returning the login page, display the Customer 
        // page for the customer that matches the customer number 
 
        // Get a reference to the CustomerModel 
        CustomerModel model = 
           (CustomerModel)getModel(CustomerModel.class); 
 
        // Modify the where criteria to reflect the customer number used to login 
       model.clearUserWhereCriteria(); 
       model.addUserWhereCriterion( 
           "CUSTOMER_TBL_CUSTOMER_NUM", new Integer(custNum)); 
 
       // Display the Customer page 
       getViewBean(CustomerPage.class).forwardTo(event.getRequestContext()); 
    } 
 
    else 
    { 
       theMessage = "Sorry, "+ custNum + 
       ",your customer number was incorrect!"; 
 
       // Set the output status message 
       getDisplayField(CHILD_MESSAGE).setValue(theMessage); 
       forwardTo(); 
     } 	
}