...
Submit a AJAX Request in your JS listener class for the Product Code, Sub Product, and Function Codes entitled along with the model data.
The following keys must be keys must be sent as parameters in the AJAX request in the JS listener:Code Block language js # Mandatory keys for AJAX request: "PAGE_CODE_TYPE" : '<PAGE_CODE_TYPE>', "INPUT_PRODUCT" : '<PRODUCT_CODE>', "INPUT_ACTIONSUB_PRODUCT" : '<ACTION<SUB_PRODUCT_CODE>', "INPUT_FUNCTION_CODE" : '<FUNCTION_CODE>', "INPUTPRODUCT_SUB_PRODUCTNAME" : '<SUB<PRODUCT_PRODUCT_CODE>NAME>', "PRODUCTINPUT_NAMEACTION" : '<PRODUCT<ACTION_NAME>CODE>', # If sending JSON in the AJAX request, the following additional keys are needed: "JSON_TO_HASH_MAP_SUPPORT_FLAG" : "<SOME_KEY>", "<SOME_KEY>" : <JSON_OBJECT>
For the Transaction Payment form, add the request as follows in the Submit button handler:Code Block language js CABR.registerHandler('SUBMIT', 'PAYMENTS_CONTAINER', function (config) { var fm = new canvas.form.FormManager( { formId : "PAYMENT_FORM" }); var mData = fm.model.getModelData(); var paymenttxnData = { 'ACC_NO' : mData.TXT_DBIT_AC_NO, 'ACC_NAME' : mData.TXT_DBIT_AC_NAME 'BENE_ACC_NO' : mData.TXT_BEN_AC_NO, 'BENE_NAME' : mData.TXT_BEN_AC_NAME, 'TRANS_DATE' : mData.TRANS_DATE, 'TRANS_AMNT' : mData.TXT_TRANS_AMNT, "PAGE_CODE_TYPE" : 'GET_TXN', "INPUT_PRODUCT": "'PAYMNT"', "INPUT_SUB_PRODUCT": "'BKSIFT"', "INPUT_FUNCTION_CODE" : 'PAYXFER', "PAYXFER"PRODUCT_NAME" : 'CUSER', "INPUT_ACTION" : "'GET_TXN",' }; canvas.ajax( { params : paramspaymenttxnData, success : function (result, request) { alert("Record added successfully"); }, failure : function (result, request) { alert("Error, something went wrong"); } }); });
Create a forward mapping in the forward mapping file to an action class that forwards the Ajax request to the server.
The forward mapping files are simple mapping files that contain the action class for each combination of Screen Code (Added as a Page Code in FORM_CONTAINER_ACTION_MAP table), product code, Sub Product Code, and Function Code. These files should be registered with ActionMapRegistry in the application Startup Servlet to get the requests raised from the client and forward it to the Server. The typical structure of the forward mapping file is:Code Block language xml <action-mapping> <action-map screenCode= "PAGE_CODE" prodCode = "PROD_CODE" subProdCode = "SUB_PROD_CODE" funcCode = "FUNCT_CODE" host = "HOST_CODE"> <action-class>action class path</action-class> </action-map> </action-mapping>
For the Payment Transaction form, create a mapping file (payment-forward.mapping) as follows:
Code Block language xml <action-map screenCode = "PMNT_TRNFR" prodCode = "PAYMNT" subProdCode = "BKSIFT" funcCode = "PAYXFER" host = "PYTTXNHOST"> <action-class> com.intellectdesign.modelhouse.PymtTxnAction </action-class> </action-map>
Also, add the mapping file in the start-up servlet as follows:
Code Block language java try { ActionMapRegistry.setCustomInstanceIndexer(ClassicalActionMapIndexer.class); ActionMapRegistry actionMapRegistry = ActionMapRegistry.getCustomInstance(); actionMapRegistry.register("coresvs-forward.mapping"); //Adding the mapping file in the startup servlet actionMapRegistry.register("payment-forward.mapping"); } catch (BaseException e) { LOGGER.error("Unable to start ActionMapRegistry", e); }
The given mapping file expects the PymtTxnAction action class to read the client request. Create the action class extending the Canvas's PortletAction class that validates the user entitlement and formats the request data as JSON request to the server:
Code Block language java package com.intellectdesign.modelhouse; import java.util.Map; import javax.servlet.http.HttpServletRequest; import com.intellectdesign.canvas.action.PortletAction; import com.intellectdesign.canvas.common.ReplyObject; import com.intellectdesign.canvas.exceptions.action.OrbiActionException; import com.intellectdesign.canvas.exceptions.common.ProcessingErrorException; import com.intellectdesign.canvas.login.sessions.SessionInfo; import com.intellectdesign.canvas.web.config.ActionMap; public class PymtTxnAction extends PortletAction { @Override public ReplyObject executePortletActionUsing(String action, SessionInfo sessionInfo, ActionMap actionMap, Map requestParams, HttpServletRequest request) throws OrbiActionException { ReplyObject reply = null; try { reply = executeHostRequest(sessionInfo, actionMap.getHostCode(), requestParams, request); } catch (ProcessingErrorException procExp) { throw new OrbiActionException("System Error:"+ procExp); } return reply; } }
In the handler properties file (which is defined for the HANDLER_PROPERTIES_FILE key in System Preference Configurator), Map the handler class to the Host Code to handle all the requests from the host (defined in the forward mapping file).
The typical mapping should be:Code Block language js HOST_CODE_Handler = Handler file path
For the Payment Transaction form, create the mapping in the (handler.properties) file as follows:Code Block language js PYTTXNHOST_Handler = com.intellectdesign.modelhouse.PymtTxnRequestHandler
Create the handler class (added in the system handler properties file) extending the Canvas SimpleRequestHandler class that provides the Ajax request data as HashMap to the handler class.
You can use this handler class to massage the data, implement your business logic and pass to instruction class.Code Block language java package com.intellectdesign.modelhouse; import java.util.HashMap; import java.util.Vector; import com.intellectdesign.canvas.common.ExtReplyObject; import com.intellectdesign.canvas.common.ReplyObject; import com.intellectdesign.canvas.constants.util.TIConstants; import com.intellectdesign.canvas.database.DatabaseException; import com.intellectdesign.canvas.event.handler.IData; import com.intellectdesign.canvas.exceptions.common.ProcessingErrorException; import com.intellectdesign.canvas.handler.SimpleRequestHandler; import com.intellectdesign.modelhouse.txn.PaymentInstruction; import com.intellectdesign.modelhouse.txn.TxnData; public class PymtTxnRequestHandler extends SimpleRequestHandler { public ReplyObject processRequest(Vector obj) throws ProcessingErrorException { ReplyObject reply = new ExtReplyObject(); if (obj instanceof Vector) { Vector inputVector = (Vector) obj; String userNo = (String) inputVector.get(TIConstants.USER_NO_INDEX_IN_VECTOR); HashMap map = (HashMap) inputVector.get(inputVector.size() - 1); map.put("USER_NO", userNo); TxnData txnData = (TxnData) formatTxnData(map); try { //Pass the transaction data to the instruction class PaymentInstruction paymentInstruction = new PaymentInstruction(); paymentInstruction.insertTxnData(txnData); HashMap successMap = new HashMap(); reply = constructSuccessReply(successMap); } catch (DatabaseException dbException) { throw new ProcessingErrorException("TXN0001", userNo); } return reply; } return reply; } private ExtReplyObject constructSuccessReply(HashMap respMap) { ExtReplyObject reply = new ExtReplyObject(); reply.headerMap = new HashMap(); reply.headerMap.put("REPLY_TYPE", "SUCCESS"); if (respMap != null) { reply.headerMap.put("JSON_MAP", respMap); } return reply; } protected IData formatTxnData(HashMap mapData) { TxnData txnData = new TxnData(); txnData.setAccNo((String) mapData.get("ACC_NO")); txnData.setAccName((String) mapData.get("ACC_NAME")); txnData.setAccCcy((String) mapData.get("BENE_ACC_NO")); txnData.setAccName((String) mapData.get("BENE_NAME")); txnData.setAccBranch((String) mapData.get("TRANS_DATE")); txnData.setAccBranch((String) mapData.get("TRANS_AMNT")); return txnData; } }
Create the Instruction class that handles the DBRequest.
Refer the Database Framework to learn about Canvas database framework.Code Block language java package com.intellectdesign.modelhouse; import java.util.HashMap; import com.intellectdesign.canvas.database.DatabaseConstants; import com.intellectdesign.canvas.database.DatabaseException; import com.intellectdesign.canvas.database.DatabaseRequest; import com.intellectdesign.modelhouse.txn.TxnData; public class PaymentInstruction { public void insertTxnData(TxnData txnData) throws DatabaseException { // First prepare the hashmap for passing to the DB layer. DatabaseRequest dbRequest = null; HashMap dataMap = new HashMap(); dataMap.put("ACC_NO", txnData.getAccNo()); dataMap.put("ACC_NAME", txnData.getAccName()); dataMap.put("TRANSACTION_AMT", txnData.getTransactionAmt()); dataMap.put("TRAN_TYPE", txnData.getTranType()); dataMap.put("TRAN_DATE", txnData.getTranDate()); dataMap.put("BENE_ACC_NO", txnData.getBeneAccNo()); dataMap.put("BENE_NAME", txnData.getBeneName()); // Create a DB request to execute the query. try { dbRequest = new DatabaseRequest(); dbRequest.setDataSource(DatabaseConstants.DEFAULT_DATASOURCE); dbRequest.setDataAccessMapKey("INSERT_PAYMNT"); dbRequest.setOperation(DatabaseConstants.INSERT); dbRequest.setData(dataMap); //Pass the data to insert dbRequest.execute(); } catch (DatabaseException dbException) { throw dbException; } } }
The given instruction class expects a result map with the Access Key INSERT_PAYMNT in the SQL map file.
So, create PaymentSQLMap.xml SQLMap file that contains the SQLs to insert the data into the database as follows:Code Block language xml <?xmlversion="1.0"encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"> <sqlMap> <!-- Parameter map for inserting details in PAYMENT_TXN_DATA table --> <parameterMapid="TRASACTION_PARAM_MAP"class="java.util.HashMap"> <parameterproperty="ACC_NO"jdbcType="VARCHAR"javaType="java.lang.String" /> <parameterproperty="ACC_TYPE"jdbcType="VARCHAR"javaType="java.lang.String" /> <parameterproperty="ACC_CCY"jdbcType="VARCHAR"javaType="java.lang.String" /> <parameterproperty="ACC_NAME"jdbcType="VARCHAR"javaType="java.lang.String" /> <parameterproperty="TRANS_AMT"jdbcType="NUMBER"javaType="java.lang.String" /> <parameterproperty="TRAN_DATE"jdbcType="TIMESTAMP"javaType="java.lang.String" /> <parameterproperty="BENE_ACC_NO"jdbcType="VARCHAR"javaType="java.lang.String" /> <parameterproperty="BENE_NAME"jdbcType="VARCHAR"javaType="java.lang.String" /> </parameterMap> <!-- PAYMENT_TXN_DATA insertion --> <insertid="INSERT_PAYMNT_INSERT_TRASACTION"parameterMap="TRASACTION_PARAM_MAP"> INSERT INTO PAYMENT_TXN_DATA ( ACC_NO, ACC_NAME, TRANSACTION_AMT, TRAN_DATE, BENE_ACC_NO, BENE_NAME ) VALUES ( ?, ?, ?, ?, to_date(?,'DD/MM/YY'), ?, ? ) </insert> </sqlMap>
...