Introduced in Feature Pack 2

Creating the serialization JSP files for both Recipe & RecipeCollection to transfer nouns to XML

Introduced in Feature Pack 2

In this lesson, you create the serialization JSP files to transform both the Recipe and RecipeCollection nouns to XML to get the version related information from the server to the client. When data is sent from the WebSphere Commerce Server to Management Center, the Management Center Web application transforms nouns into the XML representation that is expected by the Management Center. The JavaServer Pages (JSP) file that represents the Struts action forward is used to transform nouns into XML format.

You also register the new serialization JSP files into the Struts configuration. The GetContentVersion service defined in the previous topic calls this JSP file.

About this task

Procedure

  1. In the Enterprise Explorer view, expand LOBTools > WebContent > jsp > mycompany > recipe.
  2. Create the serialization JSP file for the Recipe noun.
    1. Right-click recipe, then click New > File.
    2. In the File name field, enter GetVersionedRecipe.jsp.
    3. Click Finish. The GetVersionedRecipe.jsp file opens.
    4. Click the Source tab.
    5. Copy the following code into the newly created JSP file.
      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      <%@ taglib uri="http://commerce.ibm.com/foundation" prefix="wcf"%>
      <wcf:getData type="com.mycompany.commerce.project.facade.datatypes.ProjectType[]"
      	var="projects"
      	expressionBuilder="getProjectsByprojectId"
      	varShowVerb="showVerb">
      		<wcf:contextData name="storeId" data="${param.storeId}"/>
      		<wcf:contextData name="versionId" data="${param.objectVersionId}"/>
      		<wcf:param name="projectId" value="${param.objectId}"/>	
      </wcf:getData>
      
      <c:if test="${!(empty projects)}">
      		<c:set var="objectVersionId" value="${param.objectVersionId}" scope="request" />
      		<c:set var="objectVersionNumber" value="${param.objectVersionNumber}" scope="request" />
      		<c:forEach var="project" items="${projects}">
      			<c:set var="objectType" value="${param.objectType}"/>
      			<jsp:directive.include file="serialize/SerializeRecipe.jspf"/>
      		</c:forEach>
      </c:if>

      This code is similar to the code in the GetRecipebyRecipeId.jsp file. A new parameter versionId is added to the new JSP file so that when data is sent from the WebSphere Commerce Server to the Management Center, the version related information for the Recipe noun is also retrieved.

      Note:
      • The objectVersionId and objectVersionNumber properties must be included in your JSP file so that the framework knows if the returned object is a version object or not.
    6. Save and close the file.
  3. Create the serialization JSP for the RecipeCollection noun.
    1. Right-click recipe, then click New > File.
    2. In the File name field, enter GetVersionedRecipeCollection.jsp.
    3. Click Finish. The GetVersionedRecipeCollection.jsp file opens.
    4. Copy the following code into the newly created JSP file.
      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      <%@ taglib uri="http://commerce.ibm.com/foundation" prefix="wcf"%>
      
      <wcf:getData type="com.mycompany.commerce.project.facade.datatypes.ProjectCollectionType[]"
      	var="projectCollections"
      	expressionBuilder="getProjectCollectionById"
      	varShowVerb="showVerb">
      		<wcf:contextData name="storeId" data="${param.storeId}"/>
      		<wcf:contextData name="versionId" data="${param.objectVersionId}"/>
      		<wcf:param name="collectionId" value="${param.objectId}"/>
      </wcf:getData>
      
      <c:if test="${!(empty projectCollections)}">
      		<c:set var="objectVersionId" value="${param.objectVersionId}" scope="request" />
      		<% System.out.println("objectVersionId:" + request.getParameter("objectVersionId")); %>
      		<c:set var="objectVersionNumber" value="${param.objectVersionNumber}" scope="request" />
      		<c:forEach var="projectCollection" items="${projectCollections}">
      			<c:set var="objectType" value="${param.objectType}"/>
      			<jsp:directive.include file="serialize/SerializeRecipeCollection.jspf"/>
      		</c:forEach>
      </c:if>
    5. Save and close the file.
  4. Register the actions in the struts action configurations.
    1. In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF.
    2. Open the struts-extension.xml file.
    3. Click the Source tab.
    4. Copy the following lines to the XML file.
      <action path="/GetVersionedRecipe" include="/jsp/mycompany/recipe/GetVersionedRecipe.jsp" />
      <action path="/GetVersionedRecipeCollection" include="/jsp/mycompany/recipe/GetVersionedRecipeCollection.jsp" />
    5. Save your changes.
  5. Navigate to LOBTools > WebContent > jsp > recipemycompany > serialize. Update SerializeRecipe.jspf.
    You must update the SerializeRecipe.jspf file to return the information for objectversionId and objectVersionnumber so that you can retrieve the data for the different versions of the Recipe noun. Add the following lines in bold as shown:
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
    <object	objectType="${objectType}">
    <!-- return the ObjectVersionID & Version number -->
    	<c:set var="showVerb" value="${showVerb}" scope="request"/>
    	<c:set var="businessObject" value="${project}" scope="request"/>
    	<jsp:include page="/cmc/SerializeChangeControlMetaData" />
    
    	<objectStoreId>${recipeOwningStoreId}</objectStoreId>
    	<recipeId>${project.projectIdentifier.uniqueID}</recipeId>
    	<name><![CDATA[${project.projectIdentifier.externalIdentifier.name}]]></name>
    	<time>${project.timeToComplete}</time>
    	<difficulty>${project.difficulty}</difficulty>
    	<c:forEach var="description" items="${project.description}">
    		<object objectType="RecipeDescription">	
    		<lDesc><![CDATA[${description.longDescription}]]></lDesc> 
    		<sDesc><![CDATA[${description.shortDescription}]]></sDesc> 
    		<languageId>${description.language}</languageId>
    		</object>
    	</c:forEach>
    </object>
  6. Update SerializeRecipeCollection.jspf.

    You must update the SerializeRecipeCollection.jspf file to return the information for objectversionId and objectVersionnumber so that you can retrieve the data for the different versions of the RecipeCollection noun.

    Add the following lines in bold as shown:
    <c:forEach var="projectColl" items="${projectCollections}">
    	<c:set var="objectType" value="RecipeCollection" /> 
    	<c:set var="collectionOwningStoreId" value="${projectColl.projectCollectionIdentifier.externalIdentifier.storeIdentifier.uniqueID}" />
    	<object	objectType="${objectType}">
    
    	<!-- return the ObjectVersionID & Version number -->
    	<c:set var="showVerb" value="${showVerb}" scope="request"/>
    	<c:set var="businessObject" value="${projectColl}" scope="request"/>
    	<jsp:include page="/cmc/SerializeChangeControlMetaData" />
    
    	<objectStoreId>${collectionOwningStoreId}</objectStoreId>
    	<collectionId>${projectColl.projectCollectionIdentifier.uniqueID}</collectionId>
    	<collectionName><![CDATA[${projectColl.projectCollectionIdentifier.externalIdentifier.name}]]></collectionName>
    	<c:forEach var="description" items="${projectColl.description}">
    		<object objectType="RecipeCollectionDescription">
    			<description><![CDATA[${description.value}]]></description>
    			<languageId>${description.language}</languageId>
    		</object>
    	</c:forEach>
    	</object>
    </c:forEach>
  7. Update SerializeRecipeCollections.jspf.
    Add the following lines in bold as shown:
    <objects 
    	recordSetCompleteIndicator="${showVerb.recordSetCompleteIndicator}"
    	recordSetReferenceId="${showVerb.recordSetReferenceId}"
    	recordSetStartNumber="${showVerb.recordSetStartNumber}"
    	recordSetCount="${showVerb.recordSetCount}"
    	recordSetTotal="${showVerb.recordSetTotal}">
    
    	<c:forEach var="projectColl" items="${projectCollections}">
    		<c:set var="objectType" value="RecipeCollection" /> 
    		<c:set var="collectionOwningStoreId" value="${projectColl.projectCollectionIdentifier.externalIdentifier.storeIdentifier.uniqueID}" />
    		<object	objectType="${objectType}">
    		
    			<c:set var="showVerb" value="${showVerb}" scope="request"/>
    			<c:set var="businessObject" value="${projectColl}" scope="request"/>
    			<jsp:include page="/cmc/SerializeChangeControlMetaData" />
       
    			<objectStoreId>${collectionOwningStoreId}</objectStoreId>
    			<collectionId>${projectColl.projectCollectionIdentifier.uniqueID}</collectionId>
    			<collectionName><![CDATA[${projectColl.projectCollectionIdentifier.externalIdentifier.name}]]></collectionName>
    			<c:forEach var="description" items="${projectColl.description}">
    				<object objectType="RecipeCollectionDescription">	
    					<description><![CDATA[${description.value}]]></description>
    					<languageId>${description.language}</languageId>
    				</object>
    			</c:forEach>
    		</object>
    	</c:forEach>
    </objects>
  8. Update SerializeChildRecipe.jspf.
    Add the following lines in bold as shown:
    <object	objectType="${childobjectType}"> 
    <childRecipeId>${param.collectionId}_${project.projectIdentifier.uniqueID}</childRecipeId>
    <objectStoreId>${recipeOwningStoreId}</objectStoreId>			   
    <object	objectType="${objectType}">
    <c:set var="showVerb" value="${showVerb}" scope="request"/>
    <c:set var="businessObject" value="${project}" scope="request"/>
    <jsp:include page="/cmc/SerializeChangeControlMetaData" />
  9. Save and close all the files.

Results