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 7441837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:04:51+00:00 2026-05-29T11:04:51+00:00

I have a Contact object that I put in the request, this object is

  • 0

I have a Contact object that I put in the request, this object is modified in the
form and then get the modified object. I would like the object that is back is the same object that you send, you keep the value of the attributes that were not in the form.

class Contact{

     private String name;          // this attributes will be modified
     private String lastName;

     private Long id;
     private Date created;        // this atributes will not be modified

     // getters and setters ....

}


    @RequestMapping(value = "/{id}/edit", method = RequestMethod.GET)
    public String updateContact(@PathVariable("id") Long id, Model model) {

         Contact c = contactDao.get(id);
         model.addAttribute("contact", c);

         return "contact/form";

    }



     @RequestMapping(value = "/{id}/edit", method = RequestMethod.POST)
     public String update(@PathVariable("id") Long id, @Valid @ModelAttribute Contact contact, BindingResult result, Model model) {

        // The contact I get here I want to keep the original attributes of the
       // object sent, and have the changes in the fields shown on the form. is that possible?

        return "redirect:/contact";
  }


   <form:form action="${pageContext.servletContext.contextPath}/tags/create"            commandName="contact">

              <form:input path="name"/>
              <form:errors path="name" cssClass="formError"/>
              <form:input path="lastName"/>

   </form:form>

I do not want to use hidden fields to maintain the value of the attributes that will not be changing

  • 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-29T11:04:52+00:00Added an answer on May 29, 2026 at 11:04 am

    I found the solution to the problem by stating the contact object as an object that lives in the session

    @Controller
    @RequestMapping("/contact")  
    @SessionAttributes("contact")
    public class ContactController {
    
    ....
    ....
    
    
        @RequestMapping(value = "/{id}/edit", method = RequestMethod.GET)
        public String updateContact(@PathVariable("id") Long id, Model model) {
    
            Contact c = contactDao.get(id);
            model.addAttribute("contact", c);
            return "contact/form";
    
        }
    
    
        @RequestMapping(value = "/{id}/edit", method = RequestMethod.POST)
        public String update(@PathVariable("id") Long id, @Valid @ModelAttribute Contact contact, BindingResult result, Model model) {
    
            contactDao.update(contact);
    
            return "redirect:/contact";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In have a controller class that handle a Contact object. In this controller I
I have a contact us form that uses Ajax (i.e. relies on asynchronous requests).
I have a contact form that can be hidden using .slideToggle() but I want
The basics: I have a contact form that uses php to validate the forms.
If I have a form-backing object that has a complicated object tree -- say
I have a table for a contact form and this table contains another table
I have a Contact entity that exposes a navigation proeprty for child Phone entities.
i have a contact form sending itself to me by email using ASP classic,
I have a contact form where the email is actually accessible in the source,
I have a Windows form that's generated using code (including buttons and what not).

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.