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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:03:03+00:00 2026-05-27T09:03:03+00:00

Not having much luck getting help from any of you Spring gurus on here.

  • 0

Not having much luck getting help from any of you Spring gurus on here. Hopefully this time I word the question better so it makes more sense. I’ve got a fairly basic Spring app using a Mysql database. Basically I just want to know the proper way to load data into a SELECT object on a form, but I need the entire process.

Here is a bit more depth. I’ve got a Job object that is stored in a Job table in the DB. It’s tied to a form that a user can fill out to populate the Job object. The Job object also has a Many to One relationship with a Filter object that is stored in a seperate table in the DB. So when the user is creating a Job object with the form, there is a SELECT box that is loaded with Filter objects for them to select. So far all of my code to do that works fine. The filter objects are displayed and then stored in the DB properly so I believe I have that part down right. The problem comes when a user attempts to edit a Job object. I load the form and all the data from the Job object is correctly pre-populated into the various boxes, except that the SELECT box is not automatically set to the Job objects stored choice. The SELECT object is getting loaded with Filter objects, but it’s always set to the first choice instead of say the 4th or whatever happens to be stored in the Job object. So clearly I’m not doing something right or missing some vital aspect of this process. If anyone can help me out here I would truly appreciate it. This is a bug in an application for work that I’m trying to fix and I cannot seem to find the solution. Anyway, below I’ve posted what I believe to be all the relevant code.

Job Object

@Entity
public class Job implements Runnable {
    @Id @GeneratedValue
    private Long id;

    @ManyToOne
    @JoinColumn(name="filterId")
    private Filter filter;

    //getters and setters
}

Filter Editor (for translating the id passed from the form into a Filter object)

public class FilterEditor extends PropertyEditorSupport {

private FilterService filterService;

public FilterEditor(FilterService filterService) {
    this.filterService = filterService;
}

public void setAsText(String value) {
    long filterId = Long.parseLong(value);
    Filter f = filterService.getById(provisionId);
    setValue(f);
}
}

Job Controller (relevant parts)

@InitBinder
protected void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(Date.class, new DatePropertyEditor());
    binder.registerCustomEditor(Filter.class, new FilterEditor(filterService));
}

@RequestMapping(value="/job", method=RequestMethod.GET)
public void showJobForm(Model model) {
    model.addAttribute(new Job());

    model.addAttribute("filters", filterService.getAll());
}

@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", filterService.getAll());
    return "job";
}

And the relevant parts of the JSP

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

<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>
        </td></tr>
    </table>
</sf:form>

If I can clarify anything or provide anything else please do let me know. I have been trying to fix this for days and am at a loss. Thanks again.

  • 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-27T09:03:04+00:00Added an answer on May 27, 2026 at 9:03 am

    Shot in the dark, because I’m not an expert in Spring MVC, and don’t know if you’re using Open Session In View or not.

    If you’re not using Open Session In View, and if Spring uses equals to compare the selected filter with every filter in the select box, then the problem might come from the lack of proper redefinition of equals (and hashCode) in the Filter entity. Indeed, you’ll have two different Filter instances, having the same ID, but being different regarding equals.

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

Sidebar

Related Questions

This may be a beginners question but not having much luck getting this going.
Not having much luck Googling this question and I thought about posting it on
I'm sorry if this question is noob-ish but I'm not having much luck with
Ok, I am not having much luck with this. I am new to Entity
Not having much luck with this. I'm trying to determine if a var is
I'm not having much luck searching for this answer, as I think that I
I've been trying to research this but not having much luck. I seem to
I'm not having much luck centering vertically the label I'm adding to the TitleView
I'm interfacing with a payment gateway and not having any luck with Net::SSLeay and
I'm not having much luck with updating an app widget with AlarmManager generated broadcasts.

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.