HOME
you can use either SendMsgCmd.setContent or SendMsgCmd.compose to build an email message and send it through the outbound messaging system.
If SendMsgCmd.setContent and SendMsgCmd.compose are used together, content that is generated by composition can override the other according to the following behavior priorities:
- If SendMsgCmd.setContent is called with the languageId parameter, its generated content is overridden when SendMsgCmd.compose is called.
- If SendMsgCmd.setContent is called without the languageId parameter, its generated content is not overridden when SendMsgCmd.compose is called.
It is not recommended to use both methods, as it adds unnecessary complexity
try
{
com.ibm.commerce.messaging.commands.SendMsgCmd api =
(com.ibm.commerce.messaging.commands.SendMsgCmd)
CommandFactory.createCommand(SendMsgCmd.NAME, getStoreId());
// Assume you have set the msgType in the MSGTYPES table to 200 and you are
using
// storeId of 1.
api.setMsgType("OrderReceived");
api.setStoreID(new Integer(1));
// You have to choice how to build the msg:
// First choice: build your XML msg in a String object and then use the
setContent().
String OrderNotifyMsg =
new String("Your Order has been received. Thank You for Shopping with us.");
// Set the content for English (with language id of -1)
// The first parameter is null. This means that the transport used is dependent on the
// value set in the Administration Console.
SendMsgCmd.setContent(null, "-1" , OrderCreateMsg.getBytes());
// Or, use the message composition services (compose()) by passing the
template/view name
TypedProperty tp = null;
// Pass the viewName, command Context and null parameter stored in tp to composition
// services, assuming the JSP file associating with default view does not require
// any additional values from this command.
// Upon successful completion, a message is build according to message layout
defined in the
// JSP message layout template referred by viewName associated with the
// message type OrderReceive.
SendMsgCmd.compose(null, getCommandContext(), tp);
// Set the subject, recipient and sender information using Configurable message data services.
// To adapt the following example to use the file adapter instead of the e-mail adapter, replace
// the 3 lines of code for the e-mail adapter with the following 2 lines:
// api.setConfigData("location","c:\");
// api.setConfigData("FileName","abc.txt");
api.setConfigData("subject","Your Order has been received");
api.setConfigData("recipient",getEmailAddress());
api.setConfigData("sender","storeAdmin@storeABC.com);
// Send out the message using sendImmediate send service.
api.sendImmediate();
// Set the command context obtained from the controller command.
api.setCommandContext(getCommandContext());
// Run the outbound messaging system services
api.execute();
}
catch (Exception ex )
{
ex.printStackTrace(System.err);
Composition JSP files
The default view for the OrderReceived message is defined in the MSGTYPES table and is the OrderReceivedView. This view is defined in the struts-config-ext.xml file. This view refers to the OrderReceivedNotify.jsp, which is used to compose the message:
<forward className="com.ibm.commerce.struts.ECActionForward" name="OrderReceivedView/10101/-3" path="/Messages/OrderReceivedNotify.jsp">
<set-property property="implClassName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl"/>
<set-property property="interfaceName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommand"/>
</forward>
See the OrderReceivedNotify.jsp file for details on how the message is composed.
No comments:
Post a Comment