Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3878922
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:40:02+00:00 2026-05-19T22:40:02+00:00

I am facing an issue with spring and it goes as follows: In SessionAttributes

  • 0

I am facing an issue with spring and it goes as follows:

In SessionAttributes I have an object person with an attribute addresses which is a list. Whenever person is updated via controler, previous entries still remain. So for example if I had in person addresses: old address 1, old address 2, old address 3 and I update person via form to have only one new address, list of addresses becomes: new address 1, old address 2, old address 3 while intended behavior is to have “new address 1” only. I couldn’t seem to find a workaround this problem. I am using Spring 3.0.X.

Please find below all related code that shows the issue on hand.

Person.java:

package com.convert.dashboard.web.test;

import java.util.List;

public class Person {

private String name;

private Integer age;

private List<String> addresses;

public Person(List<String> addresses) {
    this.addresses = addresses;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Integer getAge() {
    return age;
}

public void setAge(Integer age) {
    this.age = age;
}

public List<String> getAddresses() {
    return addresses;
}

public void setAddresses(List<String> addresses) {
    this.addresses = addresses;
}

}

TestController.java

package com.convert.dashboard.web.test;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/test")
@SessionAttributes("person")
public class TestController {

@RequestMapping(value = "/")
public ModelAndView xyz() {
    ModelAndView mav = new ModelAndView();
    List<String> abc = new ArrayList<String>();
    abc.add("old address1");
    abc.add("old address2");
    abc.add("old address3");
    Person person = new Person(abc);
    mav.addObject("person", person);
    mav.setViewName("cForm");
    return mav;
}

@RequestMapping("/save")
public @ResponseBody
String process(@ModelAttribute("person") Person person) {
    return "<body>" + " Name:" + person.getName() + "  Age: " + person.getAge() + " Addresses: " + person.getAddresses();
}
}

cForm.jsp:

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"       "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>populate form</title>
</head>
<body>
<form:form modelAttribute="person" action="/dashboard/test/save">

<form:hidden path="name" value="X" />
<form:hidden path="age" value="20" />
<form:hidden path="addresses[0]" value="New address" />
<input type="Submit" value="Submit" />
</form:form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:40:03+00:00Added an answer on May 19, 2026 at 10:40 pm

    So the solution goes as follows:

    By appending an AJAX call on remove on the client side and adding the code below to the controller.

        @RequestMapping("/remeveAddress")
        public @ResponseBody String removeElement(@ModelAttribute("person") Person person, @RequestParam Integer addressId, Model model){
        person.getAddresses().remove(addressId);
        model.addAttribute("person", person);
        return "{}";
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing an issue where I have one method which is calling another
I have been facing issue with sphinx result set for string attribute. Below is
I am new to MVC and facing one issue. I have a xml file
I'm working on a project which uses user authentication. I'm facing a issue with
I'm facing a frustrating issue. I have an application where the scroll wheel doesn't
I have an issue with the Spring and GWT application I am working on.
I'm facing an issue with RestTemplate in Spring 3.0. When I'm trying to request
I am facing a weird issue: My source string for Html.fromHtml() is as follows:
I'm facing a little issue with Spring Security 3.0.x (3.0.2 in particular at the
I am facing an issue while trying to use the spring android framework. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.