Our web application requires a function to copy a concept. This function takes two CCT_codes as input - one for the concept to be copied and another as the CCT_Code for the new concept. The function is triggered by a button click and takes two ng-models as input.
I'm constructing a message object (variable model) to send via .POST to a Custom StoredProcedure Call. However, it seems that the properties of this model are being lost during the process. It's worth noting that this approach has been successfully implemented on numerous other pages within the web application.
$scope.Copy = function(conceptId, newId){
if (conceptId !== "" && newId !== "") {
console.log("model creation started");
var model = {
p_cct_code_old: conceptId,
p_cct_code_new: newId,
p_specialty_layout: null
};
console.log("model creation finished");
};
console.log("cctOld model: '" + model.p_cct_code_old + "'; cctNew model: '" + model.p_cct_code_new + "'");
webService.POST('support/copyconceptaddcopy', model).then(function(response){
if(response.data.success){
showSuccess();
console.log("Success!");
refreshLov();
}
else{
$scope.errorMes = response.data.message;
console.log("POST or then() error");
console.error(response.data.message);
}
});
Output:
model creation started
model creation finished
cctOld model: '1020H'; cctNew model: '1021H'
This indicates that all values are properly assigned. Below is the constructor and execute method for the Procedure Call:
private static final String SPROC_NAME = "Web_specialties_pkg.copy_concept";
CopyConceptModel model;
public CopyConceptAddCopyProcedure(DataSource dataSource, CopyConceptModel model){
super(dataSource, SPROC_NAME);
this.model = model;
declareParameter(new SqlParameter("p_cct_code_old", Types.VARCHAR));
declareParameter(new SqlParameter("p_cct_code_new", Types.VARCHAR));
declareParameter(new SqlParameter("p_specialty_layout", Types.VARCHAR));
declareParameter(new SqlOutParameter("p_error", OracleTypes.VARCHAR));
compile();
}
public Message execute() {
String error;
Map in = new HashMap();
in.put("p_cct_code_old", model.getCctCodeOld());
in.put("p_cct_code_new", model.getCctCodeNew());
in.put("p_specialty_layout", model.getSpecialtyLayout());
Map out = this.execute(in);
error = (String) out.get("p_error") + "; model.cctOld: " + model.getCctCodeOld();
if (error != null)
{ return new Message(false, error); }
else
{ return new Message(true, "Success!"); }
}
The error message indicates the requirement of a cctOld parameter and upon debugging, I find the following error message:
model.cctOld: null
I've come across information stating that non-primitive types are assigned by reference rather than by value, possibly leading to pointer transfer issues. Even when using raw (primitive) values like "1020H" and "1041H" instead of conceptId and newId, the issue persists with the value ending up as null on the receiving end.
The main questions are, "Why does this occur?" and "How can it be prevented from happening?