Adding event handling

See Also  

The contents.jsp page now displays a list of folders and reports to users, and allows navigation through these folders. To complete the page, several features must be implemented that determine the action to take when the user clicks on various parts of the page.

Click the appropriate link to jump to that section:

Synchronizing content navigation

Since the path and foldersList components are bound to the same EnterpriseItems bean (representing folders), when users click on one component the other is automatically updated. Therefore, clicking a folder in the folderList component will update the navigation path in the path component.

However, the reportsList component on the page is bound to a different EnterpriseItem bean (representing reports). When users click on a folder in the path or foldersList components, reports contained in that folder must be displayed in the reportsList component. You must synchronize the EnterpriseItems data between the components for the reports to be displayed.

To synchronize the components
  1. In the visual designer, select the path component.
  2. In the Properties view, click the Synchronization tab.
  3. Click Synchronize with the following components and then click Add.
  4. In the Select a Component to Synchronize dialog box, select the reportsList component to synchronize with the current component.
  5. Click OK.
  6. Note:    If you try to synchronize with a component that binds to the same EnterpriseItems bean as other components, a message is displayed that indicates that multiple components share the same itemSource property value (the EnterpriseItems bean), and that, if you add synchronization to the selected component, synchronization will be added to all components that are bound to this bean. Click OK to confirm the synchronization.

  7. In the visual designer, select the foldersList component and repeat steps 2 to 5 to synchronize with the reportsList component.

Clicking on either the path or foldersList component now updates the reportsList component. For additional information, see How do I synchronize multiple ItemsGrid and Path components that bind to different EnterpriseItems beans?

Viewing a report from the grid

When users click on a report in the reportsList component, you want to redirect them to the view.jsp page where the report will be rendered. This action is signaled when the ItemClicked event is triggered. To enable this functionality, several procedures must be performed:

To add an action method to the actionListener attribute
  1. Open the file contents.jsp. Right-click and select Edit Page Code.
    The Contents.java file opens.
  2. Add the following member declaration to the Contents class of the Contents.java file:
  3. String actionString = "";

  4. Add the following import statement to the top of the file:
  5. import com.businessobjects.jsf.sdk.event.ItemClickedEvent;

  6. Save and close Contents.java.
  7. In the Properties view of the reportsList component, click the Quick Edit tab.
  8. Click the Action icon and type the following method into the Quick Edit text box:
  9.     if (event instanceof ItemClickedEvent)

        {

            ItemClickedEvent currentEvent = (ItemClickedEvent) event;

            String reportID = currentEvent.getEventArgs().getItemID();

            getEnterpriseItem().setItemID(reportID);

            int columnIndex = currentEvent.getEventArgs().getColumnIndex();

            if (columnIndex == 0)

            {

                actionString = "view_report";

            }

            else

            {

                actionString = "";

            }

        }

  10. Save and close contents.jsp.

The action method checks to see if the current event triggered is the ItemClicked event, which indicates that a user clicked an item in the reportsGrid component. If the ItemClicked event was triggered by the application, then the report ID of the report clicked is retrieved from the event data:

ItemClickedEvent currentEvent = (ItemClickedEvent) event;

String reportID = currentEvent.getEventArgs().getItemID();

This report ID is then set to the ItemID property of the EnterpriseItem bean, to be used as the report source for the ReportPageViewer component on the next page, view.jsp:

getEnterpriseItem().setItemID(reportID);

Finally, the method checks to see which column of the reportsGrid component was clicked. In this tutorial, only the title of the report (the first column) triggers the application to view the report. If another column is clicked, such as the description of the report, then no action takes place:

int columnIndex = currentEvent.getEventArgs().getColumnIndex();

if (columnIndex == 1)

{

    actionString = "view_report";

}

else

{

    actionString = "";

}

To add an action method to the action attribute
  1. In the Properties view of the reportsList component, click the Quick Edit tab.
  2. Click the Command icon and type the following method into the Quick Edit text box:
  3.     return actionString;

  4. Save contents.jsp.

This method returns the action string set by the action method. When users click on the title of the report in the first column of the reportsList component, this string is set to "view_report".

import com.businessobjects.jsf.sdk.event.ItemClickedEvent;

String actionString = "";

public void doActionListener(ActionEvent event)

{

    if (event instanceof ItemClickedEvent)

    {

        ItemClickedEvent currentEvent = (ItemClickedEvent) event;

        String reportID = currentEvent.getEventArgs().getItemID();

        getEnterpriseItem().setItemID(reportID);

        int columnIndex = currentEvent.getEventArgs().getColumnIndex();

        if (columnIndex == 0)

        {

            actionString = "view_report";

        }

        else

        {

            actionString = "";

        }

    }

}

if (event instanceof ItemClickedEvent)

ItemClickedEvent currentEvent = (ItemClickedEvent) event;

String reportID = currentEvent.getEventArgs().getItemID();

getEnterpriseItem().setItemID(reportID);

int columnIndex = currentEvent.getEventArgs().getColumnIndex();

if (columnIndex == 1)

{

    actionString = "view_report";

}

else

{

    actionString = "";

}

public String viewReport()

{

    return actionString;

}



Business Objects
http://www.businessobjects.com/
Support services
http://www.businessobjects.com/services/support/