The properties of a JavaScript/AngularJS object become null once it is passed to the Post method of MyService

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?

Answer №1

My apologies for the stab in the dark, as I may not have a complete grasp of the server-side context. Does the support/copyconceptaddcopy method require the model as a parameter? It seems like there's an unexpected DataSource as the first parameter in the code snippet you provided... could this be causing a binding issue?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Require a v-alert notification to appear on every page, ensuring visibility across the site

Imagine a scenario where there is a right drawer that displays a grade dropdown with options like grade1, grade2, and grade3. On all pages, I need a v-alert notification strip to show the total count of students. For example, if I select grade3 from the ri ...

Error-free ngClick doesn't trigger AngularJS controller method

I am struggling to trigger the removePlayer(playerId) method upon clicking a button. However, it seems that the method is not being called, as I have placed a console.log() statement at the top and the console remains empty. This situation has left me puz ...

Using the `await` command may lead to the variable losing its scope

Utilizing the await keyword to retrieve data from the database has been causing me some trouble. The variable secuity_ok is set to true on one line, but inexplicably changes to false on the following line. What could be causing this issue? It's worth ...

Using the setTimeout function in Vue.js to trigger the play of an audio file at a specified

I have set up a Vue-audio player in my Vue.js application using the AudioPlayer component. This is my code: <template> <vue-audio id = "myAudio" :file= "file1"/> </template> <script> import VueAudio from 'vue-audio'; ...

Understanding ExpressJS: Exploring the distinctions between ?, +, * in string patterns and regular expressions

Hello there! As a newcomer to Express, I've been on the hunt for a thorough explanation of string patterns with no luck. The path-to-regexp documentation has left me scratching my head. In particular, I'm grappling with this somewhat enigmatic s ...

date-fns | display date

Issue I have a function that formats date strings as shown below. import { format, parseISO } from "date-fns"; export function convertDate(myDate, displayFormat) { return format(new Date(parseISO(myDate)), displayFormat); } My articles con ...

Marking a form as invalid within an AngularJS application

At the beginning of a wizard, I want to ensure that my ng-form is set as invalid until later stages. This form includes a grid with various elements, each requiring its own validation. However, a problem arises when the grid is empty - the form incorrect ...

Bootstrap Modal for WooCommerce

I'm facing an issue while trying to create a modal window using woocommerce variables ($product). The problem lies in the placement of my modal and accessing the correct product id. Here is the code snippet I've been working on. Unfortunately, i ...

Implementing a POST method in jQuery Mobile without using AJAX

How can I send a post request without using ajax in jQuery Mobile? I've tried sending the post request but it's not working on BlackBerry OS 5. Can anyone help me with this? I currently have a post method that uses ajax and it works fine. Howeve ...

When attempting to post data using jQuery, an object is encountered that does not have a parameterless constructor

Here is the code snippet I am using with jQuery to post data and register a band: var formData = new FormData(); var file = document.getElementById("CoverPicture").files[0]; formData.append("file", file); var Name = $('#Name').val(); var Genre = ...

unable to import angular js script into ejs template

Having trouble including a JavaScript file in my EJS page while using the Express.js framework. //Below is the code for my index.ejs page <!DOCTYPE html> <html> <head> <script type='text/javascript' src= "order.js">&l ...

Pinia has not been instantiated yet due to an incorrect sequence of JavaScript file execution within Vue.js

I'm currently developing a Vue.js application using Vite, and I have a Pinia store that I want to monitor. Below is the content of my store.js file: import { defineStore } from 'pinia'; const useStore = defineStore('store', { st ...

Exploring the Scope of Angular's Controller Directive

Struggling with a perplexing issue for hours now, I am at a loss on how to resolve it. Working on an angular application utilizing the angular-openlayers-directive, I have the $scope.center object that dictates the initial map view position perfectly set u ...

The selectize feature is failing to show search results

I am attempting to incorporate Remote Source in Selectize. I am retrieving data from an API. The format is as follows: concept_id,name 228,Pelecypoda 286,Pelecypoda When I attempt to log the item in the render function, it does not show up in the consol ...

Activate button through input using Bootstrap

I am struggling to achieve the desired functionality with my "sendit" button. I want it to be enabled as soon as there are any characters entered in the box, but I have tried multiple solutions without success. Part of HTML: <input type="password ...

Stopping the audio player in HTML5 and JavaScript when the next track starts playing

My webpage contains several audio players, and I've implemented this script to handle them. While the players are functioning correctly, the issue arises when a second player is clicked while the first one is still playing. I've searched for a so ...

Exploring AngularJS: When to Choose Directives Over Controller-specific Code in Unique Situations

Currently, I am faced with a practical case that I consider to be theoretical. The task at hand involves working on a single page application (SPA) with multiple partials (currently 3) and a dynamic menu that transitions through various states to create a ...

AngularJS and Jackson Backend dealing with the presence of special German characters in URL Form Encoded format

My AngularJS Frontend communicates with a Spring MVC Backend using Jackson for Serialization and JS<->Java conversion. When I include German characters like "ö, ä, ü, ß" in the http body payload sent to the backend, there are no issues. With the ...

Exploring the jQuery Solution for Enhancing Dojo Widget Framework

My experience with Dojo in the past has been great, especially with its widget infrastructure. Being able to easily separate code and HTML content, having a seamless connection with the require system used by Dojo, and the convenient builder that compresse ...

Leveraging RXJS for efficient data retrieval in nodejs

When dealing with sending a bulk of data and moving on to the next one upon completion, it can be quite challenging. Take for instance this function: async function test() { await sample.sampleStructure() await sample.sampleDataAdd() await sample.sa ...