Code generated by the IBM i Web Interaction wizard

The Action classes and ActionForm classes generated by the IBM® i Web Interaction wizard are based on code contained within templates. There are four templates, which contain both static content and dynamic content. The static content can be changed and customized. The dynamic content is used by the Web Interaction wizard to generate code based on the settings made in the wizard. Keywords in this section start with a # character. The keywords are reserved for the Web Interaction wizard. The dynamic section can be customized, but the reserved keywords need to remain in the order in which they occur. User comments can be added to this section by preceding the comments with ## characters. The user comments are not generated in the final code.

The four code templates are:
  • iseriesPgmCallAction.template - used for the generation of Action classes for the program call interactions.
  • iseriesJBAction.template - used for the generation of Action classes for Java™ bean interactions.
  • iseriesNoPgmCallAction.template - used for the generation of Action classes when there is no program call or Java bean.
  • iseriesActionForm.template - used for the generation of ActionForm classes for all options selected in the Web Interaction wizard.

Each template affects the code generated in all of the Web projects in the workspace. That is, the scope of the templates is workspace-global.

The original templates are copied into the workspace folder. This protects the original templates from being overwritten. The templates that are in the workspace are used by the Web Interaction wizard for code generation. You should only customize the copies that are in the workspace in the following location:
workspace_location\.metadata\.plugins\com.ibm.etools.iseries.webtools\

Example of the iseriesPgmCallAction template file

The action classes generated by the Web Interaction wizard are organized by package names containing .action. Potentially, five action classes can be generated:
  • The name of the main action class is the Web interaction name plus Action.java.
  • The IBM i helper action class is ISeriesAction.java.
  • ISeriesPgmAction.java is based on iseriesPgmCallAction.template.
  • ISeriesNoPgmAction.java is based on iseriesNoPgmCallAction.template.
  • ISeriesJBAction.java is based on iseriesJBAction.template.
ISeriesPgmAction.java, ISeriesNoPgmAction.java, and ISeriesJBAction.java are generated on a per project basis.

If you customized the template files, delete the corresponding action classes before running the Web Interaction wizard with the changes in the template files.

The following example shows a portion of the iseriesPgmCallAction.template file. Keywords are identified with the # character, and user comments are identified with the ## characters.
#PACKAGE ## e.g. package com.ibm.userwebapp.actions;

##============================================================
## Template file for the generation of user Action classes
## that invokes IBM i host program.
## #{keyword} are for the internal dynamic code-generation
## based on the Web Interaction Wizard
## Template Comment will be ignored by the code-generation.
##============================================================

/**
 * Description - Use PCML to call IBM i ILE program
 */
import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;
import javax.servlet.http.*;
import javax.servlet.ServletContext;
import org.apache.struts.action.*;
import com.ibm.as400.access.*;
import com.ibm.iseries.webint.*;
import com.ibm.connector2.iseries.pgmcall.*;

#IMPORT                           ## e.g. import com.ibm.userwebapp.beans.*;

public class ISeriesPgmAction extends ISeriesBaseAction
{

  #DEFINE_CONSTRUCTOR             ## e.g. public UserWebAppAction()
  {
    super(xmlPath);
  }

  public ActionForward
  #EXECUTE_METHOD_NAME            ## Struts 1.0 -> perform, Struts 1.1 -> execute
  ( ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response,
    ActionServlet actionServlet )
  {
    try
    {
      if(!request.isRequestedSessionIdValid())
      {
        return mapping.findForward("session_error");
      }
      else
      {
        setActionServlet(actionServlet);

        preprocessing(request, response, form);

        HttpSession session = request.getSession();

        Object databean = processInput(form, request, session);
        
        ArrayList inputPageNames = getInputPages();
        if(inputPageNames != null && inputPageNames.siz() > 0)
        {
          for(int k=0; k<inputPageNames.siz(); k++)
          {
            saveFormToPage(session,
            (ISeriesActionFormInterface) form,
            (String)inputPageNames.get(k));
          }
         }

        Object formBean = getOutputFormBean();

        _databean = (ProgramCallRecord) databean;

        invokeHostProgram(request, _dataBean, form, ISeriesActionFormInterface) formBean);

        processOutput(databean, formBean, session);

        if(msgCodeObj != null)
        {
          String msgPage = checkAndMapMessages(msgCodeObj,
          request, form, (ISeriesActionFormInterface)
          formBean);
          if(msgPage != null && msgPage.compareTo(getOutputPage())!= 0)
          {
            postprocessing(request, form,(ISeriesActionFormInterface) formBean);
            return mapping.findForward(msgPage);
          }
         }

        ArrayList outputPageNames = getOutputPages();
        if(outputPageNames != null && outputPageNames.size() > 0)
        {
          for(int k=0; k<outputPageNames.size(); k++)
          {
            saveFormToPage(session, (ISeriesActionFormInterface) formBean, (String)outputPageNames.get(k));
          }
         }
        
        postprocessing(request, form, (ISeriesActionFormInterface) formBean);

        if( _bInvalidateSession )
        {
          session.setAttribute( "wdt400.invalidateSession", "true");
          session.invalidate();
        }

        if(sFlowCtrl.equals(""))
        return getForward(mapping, session);
        else
        return getForward(sFlowCtrl, mapping, session);
      }
    }
    catch(Exception ex)
    {
      handleError(request, response, ex);
      return mapping.findForward("wdt_error");
    }
  }

  // Trigger methods Section
  // These methods represent key processing phases of
  // the generated Action execute().
  // User can potentially extend the classes and override the methods
  // to specialize their needs.
  // In general, it is recommended that the derived methods to invoke the
  // corresponding method in the super class, e.g. super.preprocessing() etc.
  //-----------------------------------------------------------------------------------------
  protected void preprocessing(HttpServletRequest request,
                               HttpServletResponse response,
                               ActionForm inputForm )
  throws Exception
  {
  }

  protected void invokeHostProgram( HttpServletRequest request,
                                    ProgramCallRecord dataBean,
                                    ActionForm inputForm,
                                    ISeriesActionFormInterface resultsForm )
  throws WebIntRuntimeException
  {
  }

  protected void postprocessing( HttpServletRequest request,
                                 ActionForm inputForm,
                                 ISeriesActionFormInterface resultsForm )
  {
  }

  // Helper methods Section
  //-----------------------------------------------------------------------------

Feedback