15.4.7 Realizing the welcome action mapping

The next component you will realize is the welcome action mapping. Follow these steps:

1. In the Web diagram, double-click welcome. The New Action Mapping wizard appears, as shown in Figure 15-24.

Figure 15-24 The New Action Mapping wizard

2. Notice that the wizard has filled in most of the data in this window. This data came from the Web diagram you previously designed. For example:

a. Action mapping name was entered as the Action Mapping Path.

b. The connections you created as Local forwards were automatically inserted into the Forwards list.

c. The Create an Action class radio button was selected, and the Model chosen was the Struts Portlet Framework Action Mapping. This is the mapping provided by Struts portlet framework.

3. No changes are required at this time so leave all data unchanged and click Next.

4. The Create an Action class for your mapping window shows that the mapping will inherit from com.ibm.wps.struts.action.StrutsAction. Click Finish to generate the Action class for your mapping.

Figure 15-25 Create an Action class for your mapping

5. Replace the generated execute method with the code shown in Example 15-6.

Example 15-6 Execute() method in the Welcome Action class

 public ActionForward execute(ActionMapping mapping, ActionForm form,
            PortletRequest request, PortletResponse response) throws Exception {

     System.out.println("===>View: Entering welcome action...");
     ActionForward forward = mapping.findForward("configured");
     ViewBean viewBean = (ViewBean) form;
     try {

      PortletPreferences portletPreferences = request.getPreferences();
      String username = portletPreferences.getValue("username", null);
      System.out.println("===>View: username = *" + username + "*");
      viewBean.setUserid(username);
        
      if (username == null || username.equals("")) {
          System.out.println("===>View: portlet not configured...");
       forward = mapping.findForward("notConfigured");
      }
      
     } catch (Exception ex) {
     }
     return forward;

 }

6. If you get errors, you might need to organize your imports.

7. Save the file and close the editor.

Redbooks
ibm.com/redbooks