Wednesday, 13 March 2013

Creating EJB (Entity Beans) in WCS

Next 5 slides shows how we can insert a record in database and update it in WCS using EJB.

1)First create a table:

CREATE TABLE DB2ADMIN.XBONUS  (
          MEMBERID BIGINT NOT NULL ,
          BONUSPOINT INTEGER NOT NULL ,
          OPTCOUNTER SMALLINT NOT NULL,
CONSTRAINT XBONUS_PK PRIMARY KEY (MEMBERID),
CONSTRAINT XBONUS_FK FOREIGN KEY (MEMBERID) REFERENCES DB2ADMIN.USERS(USERS_ID));


2)Follow below steps to create Entity Beans 































Click on Finish button-> This creates all the required, Home/Remote/Bean classes

























3)Next we see how to Configure EJB Properties

Issues with ControllerCommand and TaskCommand - solution

Issue 1) 00000114 CommerceSrvr  E CommandFactory locateCommandEntry CMN0203E: Command not found: "com.mycompany.commands.MyCatalogControllerCmd".

Solution : We need to make an entry in CMDREG table as mentioned at Register the Controller Command - CMDREG

otherwise at run time it throws exception


Issue 2) 000001a5 CommerceSrvr  E CommandManager createCommand CMN0110E: Cannot instantiate com.myCompany.commands.MyCatalogTaskCmdImpl for command com.mycompany.commands.MyCatalogTaskCmd. java.lang.NoClassDefFoundError: com/myCompany/commands/MyCatalogTaskCmdImpl (wrong name: com/mycompany/commands/MyCatalogTaskCmdImpl)
    at java.lang.ClassLoader.defineClassImpl(Native Method)



Solution : Make sure the value of public static final String defaultCommandClassName should match with actuals
example:

    public static final String defaultCommandClassName = "com.myCompany.commands.MyCatalogTaskCmdImpl";

make sure you have package com.myCompany.commands and class name as
MyCatalogTaskCmdImpl

If any of these mismatches, i.e.,  the package name here is
com.myCompany.commands and the original package name is
com.mycompany.commands (small c in mycompany), then at runtime we get exception.

Test ControllerCommand using JSP

We can test ControllerCommand using simple junit test case. But we will test this by using JSP/Action (struts-config-ext.xml).

According to our requirement edit the jsp which is already developed in previous session Create a new JSP for WCS use

Below is the JSP code:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><%@page
    language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">

<%@ page isELIgnored="true"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://commerce.ibm.com/base" prefix="wcbase"%>
<%@ taglib uri="flow.tld" prefix="flow"%>
<%@ include file="include/JSTLEnvironmentSetup.jspf"%>
<head>

<title>My New Page</title>
<link rel="stylesheet"
    href='<c:out value="${jspStoreImgDir}${vfileStylesheet}"/>'
    type="text/css" />

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="GENERATOR"
    content="Rational® Application Developer™for WebSphere® Software" />
</head>
<body>
<%@ include file="include/LayoutContainerTop.jspf"%>

<p>This is my new page</p>

<script language="Javascript1.2">
    function placeCatalogOrder(form)
    {
        form.submit();
    }
</script>
<form method="post" action="MyCatalogPage" name="MyCatalogPage_Form" id="MyCatalogPage_Form">
    <input type="hidden" name="storeId" value="<c:out value="${WCParam.storeId}" />"
                                            id="MyCatalogPage_FormInput_storeId" />
    <input type="hidden" name="langId" value="<c:out value="${WCParam.langId}" />"
                                            id="MyCatalogPage_FormInput_langId" />
    <input type="hidden" name="catalogId" value="<c:out value="${WCParam.catalogId}" />"
                                            id="MyCatalogPage_FormInput_catalogId" />
</form>

<a href="javascript:placeCatalogOrder(document.MyCatalogPage_Form)"
    class="button" id="OrderPaperCatalogForm_Button">
    <fmt:message key="ORDER_CATALOG" bundle="${storeText}" />
</a>
    <p>
        <c:out value="${taskShippingMessage}" />
        <c:out value="${taskShippingAddressee}" />
    </p>
<%@ include file="include/LayoutContainerBottom.jspf"%>
</body>
</html>

Output:

















Onclick on My New Page link we get below page:

















Onclick of Place Order button we get below output: