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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:05:04+00:00 2026-05-13T10:05:04+00:00

I am trying to display my command objects collection field inside a list box.

  • 0

I am trying to display my command objects collection field inside a list box. Inside said collection is a field, id and name. I want use the id as the html option value and the name as the option text. See the code below;

<form:select id="customCollection" path="customCollection" size="10">
    <form:options items="${command.customCollection}" itemValue="id" itemLabel="name"/>
</form:select>

Name prints out fine, but value is left blank. Here is the output HTML;

<option selected="selected" value="">name-value</option>

My initial assumption was that my data was incorrect, but after putting the following code in my page;

<c:forEach items="${command.customCollection}" var="c">
    ${c.id} : ${c.name} <br>
</c:forEach>

both the id and the name are correctly printed out. So my data is correctly being delivering to my view. Which makes me assume I am either using form:options incorrectly or hitting some bug in form:options.

Can anyone help me out here?

EDIT:
Thanks to the help of BacMan and delfuego, I’ve been able to narrow down this issue to my binder.

Previously I was assigning the value in my element to the name of the row, here is my initial binder;

binder.registerCustomEditor(Collection.class, "customCollection",
        new CustomCollectionEditor(Collection.class) {

    @Override
    protected Object convertElement(Object element) {
        String name = null;

        if (element instanceof String) {
            name = (String) element;
        }
        return name != null ? dao.findCustomByName(name) : null;
    }
});

When I remove this code from my initBinder method the row value is correctly inserted into the form, but I need a customEditor to convert said value into a database object.

So this is my new attempt at a binder;

binder.registerCustomEditor(Collection.class, "customCollection",
        new CustomCollectionEditor(Collection.class) {

    @Override
    protected Object convertElement(Object element) {
        Integer id = null;

        if (element instanceof Integer) {
            id = (Integer) element;
        }
        return id != null ? dao.find(Custom.class, id) : null;
    }
});

However this is causing the same behavior as the previous binder and making the value not show up. Any ideas about what I am doing wrong here?

EDIT 2:
As I mentioned above, if I comment out my custom binder then the Custom object does load its id and name correctly for the view portion of the form, but then never binds back into the parent object when I attempt to save it. So I really think the issue is with my binder.

I’ve placed debugging statements inside my convertElement method. Everything looks like it should be worked, the dao is correctly pulling objects from the database. The only behavior that strikes me as suspect is that the convertElement method is called twice for each Custom item.

  • 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-13T10:05:05+00:00Added an answer on May 13, 2026 at 10:05 am

    This is one of those issues that once I understood what was going wrong I don’t understand how it ever worked in the first place.

    I was using CustomCollectionEditor in completely the wrong way. According to Marten Deinum’s post in this thread,

    As I stated in the other thread already the CustomCollectionEditor is to create Collections (List, Set, ?). So it will populate the desired collection with elements of the desired type.

    However it is not intended to convert single elements into a value. It is designed to work on Collections, not on a single Role instance. You want 1 PropertyEditor to do 2 tasks for you.

    So it was creating a unique collection for each element that eventually got nulled out in the Spring code when it attempted to generate the HTML.

    This is what I ended up doing,

    binder.registerCustomEditor(Custom.class,
            new PropertyEditorSupport() {
    
                @Override
                public void setAsText(String text) {
                    Custom custom = dao.find(Custom.class,
                            Integer.parseInt(text));
                    setValue(Custom);
                }
            });
    

    I have no idea why my previous CustomCollectionEditor ever worked with the names as values.

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

Sidebar

Ask A Question

Stats

  • Questions 371k
  • Answers 371k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Using setInterval, you should be able to do something like… May 14, 2026 at 7:05 pm
  • Editorial Team
    Editorial Team added an answer Just playing around with this CSS Style span .LV_validation_message {… May 14, 2026 at 7:05 pm
  • Editorial Team
    Editorial Team added an answer I suggest that you use projection transformations with Deep Zoom… May 14, 2026 at 7:05 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.