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

  • Home
  • SEARCH
  • 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 8779847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:53:59+00:00 2026-06-13T19:53:59+00:00

I’m lost for ideas as to why this controller method is not working, but

  • 0

I’m lost for ideas as to why this controller method is not working, but maybe someone has seen something like this before. My web form supplies all the Property object’s variables (one of them being the id) using the masqueraded PUT method. It’s annotated like this:

package uk.co.nicshouse.jester.domain;

import java.io.Serializable;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;


@Entity
public class Property implements Serializable
{
    @Id
    @GeneratedValue
    private long id;
    private String name;
    private String description;

    @Embedded
    private Address address;

    @Override
    public boolean equals(Object obj)
    {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Property other = (Property) obj;
        if (this.id != other.id) {
            return false;
        }
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        if ((this.description == null) ? (other.description != null) : !this.description.equals(other.description)) {
            return false;
        }
        if (this.address != other.address && (this.address == null || !this.address.equals(other.address))) {
            return false;
        }
        return true;
    }



    @Override
    public int hashCode()
    {
        int hash = 3;
        hash = 29 * hash + (int)this.id;
        hash = 29 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 29 * hash + (this.description != null ? this.description.hashCode() : 0);
        hash = 29 * hash + (this.address != null ? this.address.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString()
    {
        return "Property{" + "id=" + id + ", name=" + name + ", description=" + description + ", address=" + address + '}';
    }



    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

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

    public String getDescription()
    {
        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public Address getAddress()
    {
        return address;
    }

    public void setAddress(Address address)
    {
        this.address = address;
    }

}

The controller looks like this:

package uk.co.nicshouse.jester.mvc;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.portlet.ModelAndView;
import uk.co.nicshouse.jester.domain.Property;
import uk.co.nicshouse.jester.service.PropertyService;


@Controller
@RequestMapping("/property")
public class PropertyController
{
    @Autowired
    private PropertyService propertyService;


    /*
     * Methods that return views
     */

    @RequestMapping(method=RequestMethod.GET, produces="text/html")
    public String listProperty(Model model, HttpServletRequest request)
    {
        model.addAttribute( propertyService.getAll() );
        model.addAttribute("hostname", request.getServerName());
        return "property/list";
    }

    @RequestMapping(value="/{id}", method=RequestMethod.GET, produces="text/html")
    public String viewProperty(@PathVariable long id, Model model)
    {
        model.addAttribute( propertyService.getById(id) );
        return "property/view";
    }

    @RequestMapping(value="/{id}/edit", method=RequestMethod.GET, produces="text/html")
    public String editProperty(@PathVariable long id, Model model)
    {
        model.addAttribute( propertyService.getById(id) );
        return "property/edit";
    }

    @RequestMapping(value="/new", method=RequestMethod.GET, produces="text/html")
    public String newProperty(Model model)
    {
        model.addAttribute( new Property() );
        return "property/edit";
    }

    @RequestMapping(value="/new", method=RequestMethod.POST)
    public String createProperty(@Valid Property property, BindingResult bindingResult)
    {
        getPropertyService().create(property);
        return "redirect:/property/" + property.getId();
    }

    @RequestMapping(value="/**", method=RequestMethod.PUT)
    public String updateProperty(@RequestParam("id") int id, Property property)
    {
        System.out.println("Supplied id: " + id);
        System.out.println("Supplied property: " + property);
        getPropertyService().update(property);

        return "redirect:/property/" + property.getId();
    }





    public PropertyService getPropertyService()
    {
        return propertyService;
    }

    public void setPropertyService(PropertyService propertyService)
    {
        this.propertyService = propertyService;
    }
}

And the form as generated by jstl looks like this:

<form id="property" action="/jester/property/1/edit" method="post" enctype="multipart/form-data"><input type="hidden" name="_method" value="PUT"/>
<input id="id" name="id" type="hidden" value="3"/>
<div>
    <label for="name">Name</label>
    <input id="name" name="name" type="text" value="Test Name" size="15"/><br/>

</div>
<div>
    <label for="description">Description</label>
    <textarea id="description" name="description" size="15">Test Description Here</textarea><br/>

</div>
<div>
    <label for="address.street">Street</label>
    <input id="address.street" name="address.street" type="text" value="Test Street" size="15"/><br/>

</div>
<div>
    <label for="address.borough">Borough</label>
    <input id="address.borough" name="address.borough" type="text" value="" size="15"/><br/>

</div>
<div>
    <label for="address.town">Town</label>
    <input id="address.town" name="address.town" type="text" value="Test Town" size="15"/><br/>

</div>
<div>
    <label for="address.county">County</label>
    <input id="address.county" name="address.county" type="text" value="Test County" size="15"/><br/>

</div>
<div>
    <label for="address.postcode">Postcode</label>
    <input id="address.postcode" name="address.postcode" type="text" value="TT11 1TT" size="15"/><br/>

</div>
<div>
    <label for="address.country">Country</label>
    <input id="address.country" name="address.country" type="text" value="UK" size="15"/><br/>

</div>
<div>
    <input type="submit" value="Save" />
    <input type="reset" />
</div>

The strange thing is that the id==3 (the correct value from the HTML form), but property.id==0! Property’s other variables are set correctly. Any ideas why this is happening?

  • 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-06-13T19:54:00+00:00Added an answer on June 13, 2026 at 7:54 pm

    Figured this one out, it was a bug on my part. Property.id’s type was long but Property.setId accepted an int. This seems to have screwed Spring up in some way! Thanks for your efforts though! NFV

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
This could be a duplicate question, but I have no idea what search terms
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

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.