Error in JavaScript: Attempting to append a null value to Formdata leading to a

When the client code below is received in Server Side via SpringMVC, it throws an exception:

FormData formData = FormData(document.getElementById(formElemId));
formData.append('version', null);

The server side code in Spring MVC looks like this:

@RequestParam(value = 'version', required = false) Integer versionNumber

The exception thrown is:

Error converting a value of type 'java.lang.String' to the required type 'java.lang.Integer'; the error stems from java.lang.NumberFormatException: For input string: "null"

Answer №1

To solve this problem, consider including the defaultValue as shown below.

@RequestParam(value = "version", required = false, defaultValue = "0") Integer versionNumber

For more information, check out the official documentation

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

Tips for updating content (wishlist) without the need to refresh the page

Currently experimenting with the TMDb API to enhance my PHP skills. I've successfully created a wishlist feature and now looking to optimize the script. A function is implemented on each movie page for adding movies to the wishlist. function getButt ...

Tips for retrieving the concealed input value from the div directly preceding

Is it possible for me to retrieve the hidden input value by clicking on the text "upload profile photo"? I don't have much experience in this area. <div> <input type="hidden" value='<?php echo $list['profil ...

Implement a dropdown menu for filtering, but it is currently not functioning as expected

When I select a city_name, my goal is for the graph to only display information pertaining to that particular city. In the params section of my code, I have included filtering options using a selection menu in Vega-Lite. However, despite selecting Brisba ...

Employ node's gm library in combination with promises and buffers

Using gm with Bluebird has been a bit tricky for me. Initially, I tried this approach: var gm = require('gm'); var bluebird = require('bluebird'); gm = bluebird.promisifyAll(gm); However, when attempting to execute the following code: ...

What could be the reason for my NextJS 'getStaticProps' function not executing as expected?

My primary reason for using Next.js is the 'getStaticProps' function, but unfortunately, it seems to not be running as expected. I attempted to create a new app from scratch using "npx create-next-app@latest" with no success. I then tried withou ...

Is there a way to use CSS to clip a side of a DIV element?

Imagine a scenario where there is a parent div named "clip" and a child div named "page." These two divs have specific dimensions, as shown below: <div id="clip"> <div id="page"> <!-- Content/Images here --> </div> </ ...

How can I ensure my game or website fits perfectly on the screen without any need

I have recently developed a fun Erase-A-Man game that is optimized for mobile devices. However, I am facing an issue where users need to scroll to view all the letters on their screens. My goal is to make the game fit perfectly on all phone screen sizes so ...

Guide to transferring a function as props to children components in React?

I've been trying to implement a handle function that can be passed down to all children of my Layout component. While I know how to do this with custom components, I've been having trouble getting it to work with the 'children' prop. E ...

Conceal a column within a table by double-clicking

I'm working on a project with a table, and I'd like to implement a feature where a column hides when double-clicked. I've seen various solutions for hiding columns on Stack Overflow, but I could use some guidance on where to add the ondblcli ...

Can you show the outcome of a JavaScript function within an API data object?

After entering fixed values in my input forms to display the order value accurately, I realized that taxes and fees were not included in the total. An example of input: Example input <input type="checkbox" name="item1" value=" ...

What is the method for adding all columns of JQuery data obtained from a Linq query to a Div element?

I'm currently working on a controller ActionResult method that fetches data from the server in JSON format. I have some Ajax and jQuery code in the view to retrieve the JSON data and append it to a container. Previously, I had a controller ViewResult ...

Forwarding images from a server to a client using socket.io and node.js

I am encountering an issue where I am trying to receive an image via socket.io in node.js and then forward it to a client (browser). However, the image sent through the message to the browser is not being recognized or displayed. Interestingly, if I save ...

None of the JavaScript queries are functioning properly, however, they do work when integrated into the jquery 1.10.0 file

My knowledge of jquery and JavaScript is limited, so I am having trouble understanding why the script at the bottom is not running properly. It works when inserted at the end of jquery-1.10.0.js, but not in the HTML file. Despite being aware that this vers ...

Unsupported server component type: undefined in Next.js version 13 is not recognized by the server

Encountered some unusual behavior in Next.js 13 while attempting a simple action. I have provided a basic example demonstrating the issue. Seeking assistance in understanding why this is occurring. This scenario involves 3 components: page: import {Conta ...

Styling the numerical values displayed in tooltips within Highcharts

When using tooltip.pointFormat to display additional data in the tooltip, I noticed that only point.x is formatted correctly with a thousand separator. Check out this jsFiddle for reference! $(function () { Highcharts.setOptions({ global: { u ...

The latest on rectAreaLight enhancements in three.js

It seems like this abandoned feature of three.js has become somewhat of a coveted prize; I've attempted to incorporate it a few times without success. You can find an example that works on an older release here: My minimal broken example is availabl ...

Managing state in React using a nested object structure with React hooks for adding or updating entries

In my React application, I have a state object that represents a book structure consisting of books, chapters, sections, and items: const book = { id: "123", name: "book1", chapters: [ { id: "123", name: "chapter1", sections: [ ...

Mastering form reset functionality using jquery

When attempting to register, an error is generated if any field is left blank in the form (from PHP). The input fields that have been filled out are retained using Smarty: {if isset($smarty.post.registratie.naam)} value="{$smarty.post.registratie.naam}"{el ...

Employing fetch to utilize the post method

I have developed a phone application using PhoneGap that involves sending data to a server. In my current setup, I am making use of the following AJAX call: $.ajax({ type: 'POST', dataType:"json", url: 'test.com', data: { mail: ...

Using Cleave.js to hide the input field in an HTML form

I am currently implementing cleave.js on a website in order to create a mask that restricts input to only a 3-digit number. Here is the snippet of code I am using with cleave.js: <script> let number = new Cleave("#numberId", { ...