C H A P T E R  14

Tutorial--Section 3.2
Add a Logout Link to the Customer Page

This chapter describes how to add an HREF to a page that uses a Command component.


Task 2: Add an HREF to a Customer Page

1. Select the CustomerPage node.

2. Add a Hyperlink (HREF) component using the Component Palette.

An HREF command field is added to the CustomerPage's Visual Components node.

3. Rename the HREF as logout.

This figure shows the HREF renamed as logout. 

Configure an HREF's Command Descriptor

Configure the logout HREF to use the UserAccessCommand component via the Command Descriptor property of the button. This is identical to the button Command Descriptor configuration in the previous task, except the operation name will be logout instead of login.

1. Select the logout HREF under CustomerPage's Visual Components node.

2. Click the ellipsis button for the Request Handler property.

This displays the Request Handler editor.

This figure shows the Request Invocation Command editor. 

3. Select User-Defined Command (Default) from the list under the Create new shared instance radio button choice.

4. Change the name to userAccessCommand

5. Select the Component Properties tab at the bottom of the editor.

This figure shows the Component Properties tab at the bottom of the editor. 

6. Click the ellipsis button for the Command Class Name property.

This displays the Command Class Chooser dialog.

This figure shows the Command Class Chooser dialog. 

7. Expand the Current Application Components node, then expand jatoturial, and then main.

8. Select the UserAccessCommand command component.

9. Click OK.

10. Change the Operation Name from DEFAULT to logout.

Recall in the code what you implemented for the execute method in the UserAccessCommand class. You have an if/else block that is expecting either login or logout as an operation name.

These are case sensitive, so be sure you set this correctly, or you will receive the CommandException (Unknown operation name) when you test run this command.

This figure shows the Operation Name that is changed from DEFAULT to logout. 

11. Click OK to finish setting the Request Handler property for the logout HREF.

When you login with a valid customer number, you are taken to the Customer page. The logout link displays. When clicked, the logout operation name is passed into the UserAccessCommand to invalidate the user's session and display the Login page with the logout message.

Format the HREF tag in the Customer JSP

When you added the logout HREF field to the CustomerPage, an HREF tag was added to the CustomerPage.jsp file. However, the link displays with the default name of the HREF, href1, which is not the required text.

1. Expand the JSPs node under CustomerPage.

2. Double-click the CustomerPage JSP node to open the JSP in the editor window.

3. Find the logout HREF tag and modify the body content portion to display Logout instead of href1.

<jato:href name="logout">Logout</jato:href>

You can position the HREF tag anywhere you prefer, so long as it is nested between the useViewBean tags and is part of the HTML's body section (between the body tags).

Unlike the button, an HREF is not required to be part of the form, so it can be positioned outside the form tags (<jato:form>).