Creating the serialization JSP files for both Recipe & RecipeCollection to transfer nouns to XML
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
- In the Enterprise Explorer view, expand LOBTools > WebContent > jsp > mycompany > recipe.
- Create the serialization JSP file for the Recipe noun.
- Right-click recipe, then click New > File.
- In the File name field, enter GetVersionedRecipe.jsp.
- Click Finish. The GetVersionedRecipe.jsp file opens.
- Click the Source tab.
- 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
andobjectVersionNumber
properties must be included in your JSP file so that the framework knows if the returned object is a version object or not.
- The
- Save and close the file.
- Create the serialization JSP for the RecipeCollection noun.
- Right-click recipe, then click New > File.
- In the File name field, enter GetVersionedRecipeCollection.jsp.
- Click Finish. The GetVersionedRecipeCollection.jsp file opens.
- 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>
- Save and close the file.
- Register the actions in the struts action configurations.
- In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF.
- Open the struts-extension.xml file.
- Click the Source tab.
- 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" />
- Save your changes.
- Navigate to LOBTools > WebContent > jsp > recipemycompany > serialize. Update SerializeRecipe.jspf.
You must update the SerializeRecipe.jspf file to return the information for
objectversionId
andobjectVersionnumber
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>
- Update SerializeRecipeCollection.jspf.
You must update the SerializeRecipeCollection.jspf file to return the information for
Add the following lines in bold as shown:objectversionId
andobjectVersionnumber
so that you can retrieve the data for the different versions of the RecipeCollection noun.<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>
- 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>
- 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" />
- Save and close all the files.