# How Do I: Define an Action That Forwards Users to Another Page?

The following topic shows how to define web application navigation within a Java Page Flow file (JPF file). To learn more about the basics of navigational control in WebLogic Workshop, see Getting Started with Page Flows.

Note: that the following topic shows how to create a purely navigational action method, it does not explain how to create an action method that controls both navigation and the submission of user data. For detailed information on creating action methods that combine navigation and the submission of data, see How Do I: Make a JSP Page that Submits Data to a Page Flow?

Instead of using the standard HTML <a href> tag to move users from one JSP page to another when they clicked linked text, you can control navigation with action methods. In this form of navigation, clicking a link invokes an action method in the page flow's controller (JPF) file. This action method can be defined to simply navigate to another page or implement some decision logic which determines the destination of the link depending on some user state or some other factor. To create such a link, you must take the following three steps, and the optional fourth:

1. Place an anchor tag on the JSP page

2. Create an action method in the JPF file

3. Link the action method to the destination JPF page

4. (Optional) Define some decision logic within the action method

To Place an anchor tag on the JSP page

1. In the Application window, double-click the JSP page to open the file.
2. In the Palette window select the anchor icon and drag and drop it into Design View. The New Anchor dialog appears.

Create an action method in the JPF file

1. Select the invoke an action radio button. In the Details section, provide the text that will be linked in the Text field. Also, to create a new action, click the New button. The New Action dialog appears.
2. In the New Action dialog, confirm that the Create New radio button is selected and enter a name for the method. Click OK.
3. In the New Anchor dialog, click OK.

You have created an anchor that, when clicked by a user, invokes an action method. You have also created a method in the JPF File.
The code for the new anchor looks something like the following.

<netui:anchor action="MyMethod">Display Text</netui:anchor>

Note: the HTML equivalent of the <netui:anchor> tag above is:

<a href="MyMethod.do">Dispaly Text</a>

To invoke an action method from an HTML <a> tag, use the action method name followed by ".do".

The action attribute specifies that the anchor invokes the method MyMethod. Note that the <netui:anchor> tag does not require a parent <netui:form> tag in order invoke a method. This is in contrast to the <netui:button> tag, which requires a parent <netui:form> tag in order to invoke methods within a Page Flow file.

Link the Action to the Destination JSP page

Next you need to define the page that will be loaded by this action method.

1. Open the controller (JPF) file in Flow View. You should see a new action icon representing the action method you just created. Also locate the JSP icon you want the action method to navigate to.
2. Draw an arrow from the action icon to the target JSP page.

To examine the source code for the action method, double-click the action icon. The code will be similar to the following example:

/**
* @jpf:action
* @jpf:forward name="success" path="targetJSPPage.jsp"
*/
protected Forward anchorAction()
{
return new Forward("success");
}

Place Decision Logic Within Your Action Method

So far, you have essentially created a page flow version of an ordinary HTML anchor tag. To take further advantage of page flow functionality, you can place some decision logic within your action method. If you want to make the target JSP page dependent on some other factor, such as a user property, you could add Java code to your action method.

The action method in the following example examines the user's status to determine the JSP page to be loaded:

/**
* @jpf:action
* @jpf:forward name="success" path="targetJSPPage.jsp"
* @jpf:forward name="no_access" path="accessDeniedJSPPage.jsp"
* @jpf:forward name="limited_access" path="limitedAccessJSPPage.jsp"
*/
protected Forward anchorAction()
{
if(globalApp.User_Status.equals("Administrator"))
return new Forward("success");
else if(globalApp.User_Status.equals("Assistant"))
return new Forward("no_access");
else
return new Forward("limited_access");
}

The action method defines three possible pages to go to next depending on the user's status. In Flow View, three arrows should point from the action method to the various JSP pages. In the example, the user status is set in the globalApp data binding context. For more information about this and other data binding contexts, see Using Data Binding in Page Flows.

Related Topics

Designing User Interfaces in JSPs

Getting Started with Page Flows

A Detailed Page Flow Example