Exercise 1.3: Developing the UserAdmin page
Before you begin, you must complete Exercise 1.2: Preparing for portlet development and defining the application flow.
Create the UserAdminView.jsp page
Creating the UserAdminView.jsp page involves designing the user interface and adding a connection to dynamic data, an EJB session reference, into the application's logic.
- If UserAdminView.jsp is not open in Page Designer, you can double-click the UserAdminView.jsp icon in the Web diagram editor to open it.
- Delete the default Place content here. text.
- Drag the EJB Session bean object from the Data drawer
in the palette to the file.
- When the Session Bean wizard opens, click the New EJB Reference button.
- Expand the AuctionPortletEAR and AuctionEJB50 folders, and select UserFacade to create the enterprise bean reference.
- Click Finish.
- Click Next in the Session Bean wizard.
- Select the findByName(String name) interface, which will be used for the input field on the portlet page.
- Click Next.
- Click the Options button in the Input Form page, and type Find in the Label field. Click OK.
- Click Next, which should bring you to the Results Form page of the wizard. In this page, you will define the data table that will retrieve and display the data from the database.
- Click None to deselect all of the columns, so that you can individually select, organize, and configure the appropriate columns for the data table to be used in the portlet page. Then, select the check boxes for the following columns:
- Using the up down arrow buttons, move the selected data columns into the order shown in the step above.
- Select and change the Label value for the userid column to User ID.
- Click Finish to generate the default user interface for the UserAdminView.jsp
page. The user interface will look similar to the following:

- Save UserAdminView.jsp.
Add Java page code to the UserAdmin page
In this portion of the exercise, you will add Java page code to accomplish the following:
Store the name parameter in the session scope, so that it can be reused for any future refresh of the portlet content.
Initialize the parameter to be displayed in the Name input field with the one stored in session scope.
Initialize the result data using name parameter stored in the session scope.
You can add the EJB reference logic and the code to bind the invocation and results to the user interface, using the following steps:
- Select Edit Page Code from the pop-up menu in Page Designer.
- Type the following bold code into doUserFacadeLocalFindByNameAction():
public String doUserFacadeLocalFindByNameAction() {
String name = getUserFacadeLocalFindByNameParamBean().getName();
getSessionScope().put("name", name);
try {
userFacadeLocalFindByNameResultBean =
getUserFacadeLocal().findByName(name);
} catch (Exception e) {
logException(e);
}
return null;
}
- Type the following bold code into getUserFacadeLocalFindByNameParamBean():
public UserFacadeLocalFindByNameParamBean
getUserFacadeLocalFindByNameParamBean() {
if (userFacadeLocalFindByNameParamBean == null) {
userFacadeLocalFindByNameParamBean =
new UserFacadeLocalFindByNameParamBean();
String name = (String)getSessionScope().get("name");
userFacadeLocalFindByNameParamBean.setName(name);
}
return userFacadeLocalFindByNameParamBean;
}
- Type the following bold code into getUserFacadeLocalFindByNameResultBean():
public RegistrationData[] getUserFacadeLocalFindByNameResultBean() {
if (userFacadeLocalFindByNameResultBean == null) {
String name = (String)getSessionScope().get("name");
if (name != null) {
try {
userFacadeLocalFindByNameResultBean =
getUserFacadeLocal().findByName(name);
} catch (Exception e) {
logException(e);
}
}
}
return userFacadeLocalFindByNameResultBean;
}
- Save and close UserAdminView.java.
Run UserAdminView.jsp
To verify that the UserAdmin portlet is working as intended up to this point,
you should run the portlet on the internal browser provided with Rational
Developer. To run the portlet, do the following:
- Select the AuctionPortlet project in the Project Explorer, and select Run > Run on server from its pop-up menu.
- Because you have already defined the WebSphere Portal v5.1 Test Environment, select it, and click Finish in the Server Selection wizard.
- The file will eventually display in the browser. Here you can see the input fields and layout that a user would see on a portal site:

- To test the input form and the data table that you have just created, type % in Name field and click the Find button.
The data table should display all users.

Before we move to the next exercise, it is advisable to stop the test environment server to improve performance during development. To stop the test environment server, simply select it in the Servers view, and click the Stop the server tool bar button
.
Now you are ready to begin Exercise 1.4: Creating pages for creating and editing user information.