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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:32:28+00:00 2026-06-09T11:32:28+00:00

Im using custom editor in Spring MVC to map string valuest to my domain

  • 0

Im using custom editor in Spring MVC to map string valuest to my domain objects. Simple case: User object refers to Company (User.company -> Company). In User form I register data binder:

protected void initBinder(WebDataBinder binder) throws Exception {
    binder.registerCustomEditor(Company.class, new CompanyEditor(appService));
}

Editor is defined as folows:

class CompanyEditor extends PropertyEditorSupport {

    private AppService appService;  

    public CompanyEditor(AppService appService) {
        this.appService = appService;
    }

    public void setAsText(String text) {
        Company company = appService.getCompany(text);
        setValue(company);
    }

    public String getAsText() {
        Company company = (Company) this.getValue();
        if (company != null)
            return company.getId();
        return null;
    }    
}

When I use dropdown in my form

<form:select path="company">
    <form:options items="${companies}" itemLabel="name" itemValue="id"/>
</form:select>

I experience severe performance problems because (to check if company is selected, I suppose) fires setAsText and getAsText for each option, which makes it to run a SQL query for each company.

I thought that setAsText is used when I commit form to make application know how to translate compnany id to Company (persisted) object. Why should it fire it in dropdowns. Any ideas how to fix it?

  • 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-09T11:32:29+00:00Added an answer on June 9, 2026 at 11:32 am

    If your form backing object is stored as session attribute(i.e. you have something like @SessionAttributes("command") in your controller), so you can try to modify your setAsText(String text) method

    public void setAsText(String text) {
            Company currentCompany = (Company) this.getValue();
            if ((currentCompany != null) && (currentCompany.getId().equals(text)))
              return;
    
            Company company = appService.getCompany(text);
            setValue(company);
        }
    

    but I think that Spring 3.1 @Cacheable abstraction was introduced exactly for the such kind of things and is preferable

    see examples in documentation

    @Cacheable("books")
    public Book findBook(ISBN isbn) {...}
    

    P.S. Consider using new Converter SPI instead of Property Editors.

    In general, it’s possible to implement a generic converter for your look-up entities, so it will automatically convert entities from text using id if they have some specific attribute, for example, in one of my projects all @Entity types are being automatically converted using a global ConditionalGenericConverter implementation, so I neither register custom property editors during binding nor implement specific converters for types which are simple @Entity classes with @Id annotated primary keys.

    Also it’s very convenient when Spring automatically converts textual object ids to the actual entities when they are specified as @RequestParam annotated controller method arguments.

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

Sidebar

Related Questions

I'm using the Custom UI Editor for Office provided by Microsoft to create custom
When using the Swing graphical editor in NetBeans is it possible for a custom
I've implemented a custom editor in VS Shell (using an integration package). By default
I'm using Spring CustomNumberEditor editor to bind my float values and I've experimented that
I have a JTable that holds several JPanels using a custom renderer/editor. The JPanel
When using custom assemblies in a visual studio project. How does one check in
I'm aware of using custom configuration values for my custom services, but what if
Setup I am using custom Forms Authentication - all standard stuff. In the Login
i am using custom checkbox buttons in my table view and want to save
I'm using custom class that subclass from UILabel. It works fine unless I change

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.