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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:41:25+00:00 2026-05-27T14:41:25+00:00

Using Spring 3.1. I’ve got a form that populates a POJO stored in a

  • 0

Using Spring 3.1. I’ve got a form that populates a POJO stored in a DB. However, this POJO also has an instance of another POJO in it:

class Job {
    private id;
    private Filter filter;
    //getters and setters
}

and the Filter class:

class Filter {
    private id;
    private name;
    //getters and setters
}

So on the form that populates the Job object I’m trying to display the Filter objects in a select object. All of that part seems to work properly. The problem comes in when I try to edit a Job object that already has a Filter. The select object is not automatically setting itself to the corresponding Filter object associated with the job. Wondering if someone can let me know what I’m screwing up. Here is the JSP:

<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>

<div align="center">
<s:url value="/job" var="jobPost_url"/>
<s:url value="/job/provData" var="provData_url"/>

<sf:form method="POST" modelAttribute="job" dojoType="dijit.form.Form" action="${jobPost_url}">
    <script type="dojo/method" event="onSubmit">
        if (!this.validate()) {
            return false;
        }
        return true;
    </script>
    <sf:hidden path="id" />
    <table>
        <tr><td align="right">Customer:</td><td>
            <sf:input path="customer" dojoType="dijit.form.ValidationTextBox" trim="true" required="true"/><br/>
            <sf:errors path="customer" cssClass="error"/>   
        </td></tr>
        <tr><td align="right">Project:</td><td>
            <sf:input path="project" dojoType="dijit.form.ValidationTextBox" trim="true" required="true"/><br/>
            <sf:errors path="project" cssClass="error"/>    
        </td></tr>
        <tr><td align="right">Date:</td><td>
            <sf:input path="date" dojoType="dijit.form.DateTextBox" required="true"
                    constraints="{datePattern:'MMM d, y'}" /><br/>
            <sf:errors path="date" cssClass="error"/>   
        </td></tr>
        <tr><td align="right">Filter:</td><td><sf:select id="filter" path="filter" items="${filters}" itemValue="id" 
            itemLabel="programName"/></td>
        </tr>
        <tr><td colspan="2" align="right">
            <button dojoType="dijit.form.Button" type="submit">Submit</button>
            <button dojoType="dijit.form.Button" id="testButton">Test</button>
        </td></tr>
    </table>
</sf:form>
</div>

And here is the Controller (or at least the relevant parts):

@Controller
public class JobController {
@Autowired
private JobService jobService;
@Autowired
private ProvisionService provisionService;

@InitBinder
protected void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(Date.class, new DatePropertyEditor());
    binder.registerCustomEditor(Provision.class, new ProvisionEditor(provisionService));
}

@ModelAttribute("filters")
@RequestMapping(value="/job", method=RequestMethod.GET)
public List<Provision> showJobForm(Model model) {
    model.addAttribute(new Job());

    return provisionService.getAll();
}

@RequestMapping(value="/job", method=RequestMethod.POST)
public String submitJobForm(@Valid Job job, BindingResult bindingResult) {
    if(bindingResult.hasErrors())
        return "job";

    job.setStatus("Running");
    JobManager.AddJob(job);

    jobService.save(job);

    return "redirect:/";
}

@RequestMapping(value="/job/edit", method=RequestMethod.POST)
public String editJob(@RequestParam("jobHiddenList") String list, Model model) {
    log.info("Edit List: " + list);

    Job job = jobService.getById(Long.valueOf(list.trim()));
    model.addAttribute("job", job);
    model.addAttribute("filters", provisionService.getAll());
    return "job";
}
}

And the ProvisionEditor needed for converting the Provision from the select’s ID to a Provision:

public class ProvisionEditor extends PropertyEditorSupport {

private ProvisionService provisionService;

public ProvisionEditor(ProvisionService provisionService) {
    this.provisionService = provisionService;
}

public void setAsText(String value) {
    long provisionId = Long.parseLong(value);
    Provision p = provisionService.getById(provisionId);
    setValue(p);
}
}

So, as I said, things work fine when creating a new Job. The list of Provisions get loaded into the select, everything gets assigned correctly and stored correctly in the DB. However, when a user selects a provison later and edits it, it brings them to the same form and all the data loads in correctly except for the Provision select. It loads the list of provisions in, but it doesn’t select the correct one. Any ideas how I can fix this? Thanks.

  • 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-27T14:41:26+00:00Added an answer on May 27, 2026 at 2:41 pm

    Turns out the problem was that I did not override Equals and Hashcode for the objects. After solving another proble I came across the issue, fixed it, and everything started working as it should. It’s made especially easy because I use Eclipse and it has automatic generation of overriding both of those methods.

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

Sidebar

Related Questions

We are using Spring SimpleJdbcCall to call stored procedures in Oracle that return cursors.
I'm using Spring 3 and I tried to access url that has no mapping
Using Spring 2.5 tag library, I have an Integer value in a command form
I'm using Spring.net with NHiberante (HibernateTemplate) to implement my DAO's. I also have some
I am using Spring Forms for my web application. For nested properties, the form
Using Spring, I can get all beans of a certain type that are currently
Using Spring : can jta-transaction-manager use id as name so that I can pass
I am using Spring 3.0.2. I have two relatively simple bean definitions. One has
Using Spring MVC, do interceptors only intercept defined controller mappings or can they also
For using spring request scope bean is this definition correct? <bean id=shoppingCart class=ShoppingCart scope=request>

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.