...
Code Block | ||
---|---|---|
| ||
/* This is a sample custom publisher Java class that inserts a value for Currency column, which is not entered on the form by the customer. */ import java.util.ArrayList; import java.util.HashMap; import com.intellectdesign.canvas.model.StateModelException; import com.intellectdesign.canvas.reqmodel.external.CanvasPublishContext; import com.intellectdesign.canvas.reqmodel.external.CanvasReqModelDBPublisher; /* In this example, the form data is to be sent to database, hence the custom publisher class must be extended from CanvasReqModelDBPublisher class. */ public class CustomPublisher extends CanvasReqModelDBPublisher { /* The prepareDataToBePublished method prepares the data to be sent to the database and can be used for any data manipulation or formatting needs. */ @Override public void prepareDataToBePublished(CanvasPublishContext publishContext) throws StateModelException { super.prepareDataToBePublished(publishContext); // Form data is stored in an array list. ArrayList data = (ArrayList) publishContext.getFormattedData(); /* Two array list variables are used to store field IDs and field values separately. */ ArrayList columnList, valueList; columnList =(ArrayList) ((HashMap)data.get(0)).get("COLUMN_IDS"); valueList =(ArrayList) ((HashMap)data.get(0)).get("VALUES"); /* The getUserData method fetches the user details such as GCIF, user ID, first/last name etc. */ publishContext.getUserData(); /* The index number of the Currency field in the array list is stored in a variable. */ int ind = columnList.indexOf("CURRENCY"); /* The current value of the field is removed and new value is assigned to it. */ valueList.remove(ind); valueList.add(ind,"USD"); /* The setFormattedData method sets the data in the CanvasPublishContext object. */ publishContext.setFormattedData(data); } /* The publish method publishes the formatted data in the CanvasPublishContext object to the database. */ @Override public boolean publish(CanvasPublishContext publishContext) throws StateModelException { return super.publish(publishContext); } } |
...