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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:15:16+00:00 2026-06-10T15:15:16+00:00

I am creating a form with a select-box in my web application. I am

  • 0

I am creating a form with a select-box in my web application. I am using the DropDownChoice + ChoiceRenderer combination in the below described way. It works fine, but for one thing – in does not preselect default values.

I have been struggling with this for quite a long time. I have found several examples on the Internet which were said to work but they didn’t work for me.

My codebase looks like this (unrelated parts have been omitted or simplified to improve clarity):

Business Entities

public class MultivalueType
{
    private Long id;
    private String label;
    private String description;

    public MultivalueType(Long id, String label, String description) 
    {
        this.id = id
        this.label = label;
        this.description = description;
    }

    public Long getId()
    {
        return id;
    }

    public String getLabel() 
    {
        return label;
    }

    public String getDescription() 
    {
        return description;
    }
}

public class PropertySettings
{
    private Long id;
    private String property;
    private MultivalueType multivalueType;

    public PropertySettings(Long id, String property, MultivalueType multivalueType) 
    {
        this.id = id;
        this.property = property;
        this.multivalueType = multivalueType;
    }

    public MultivalueType getMultivalueType()
    {
        return multivalueType;
    }
}

DAO

public class PropertySettingsDao
{
    ...
    @Override
    public PropertySettings load(Long id)
    {
        String query = " ... query ... ";
        Object[] params = { id };
        return getJdbcTemplate().queryForObject(query, params, getRowMapper());
}
    ...
}

Form class

PropertySettings property = propertySettingsDao.load(propertyId);
IModel<PropertySettings> formModel = new CompoundPropertyModel<PropertySettings>(property);

Form<PropertySettings> form = new Form<PropertySettings>("editPropertyForm", formModel)
{
    @Override
    protected void onSubmit()
    {
        PropertySettings propertySettings = this.getModelObject();
        ...         
    }
};

form.add(createEnumSelectbox(multivalueTypeDao, new PropertyModel<MultivalueType>(property, "multivalueType"), "multivalueType", true));

add(form);

Creating select-box

protected DropDownChoice<MultivalueType> createEnumSelectbox(DaoForEntityWithSurrogateKey<MultivalueType> dao, IModel<MultivalueType> model, String componentName, boolean required)
{
    // create the model
    IModel<List<MultivalueType>> choices = createModelForListView(dao);

    // prepare the select-box renderer
    ChoiceRenderer<MultivalueType> renderer = new ChoiceRenderer<MultivalueType>("label", "id");

    // create the select-box component
    DropDownChoice<MultivalueType> selectBox = new DropDownChoice<MultivalueType>
    (
        componentName,
        model,
        choices,
        renderer
    );

    // mark the select-box as a required form field
    selectBox.setRequired(required);

    return selectBox;
}

protected IModel<List<MultivalueType>> createModelForListView(final DaoForEntityWithSurrogateKey<MultivalueType> dao)
{
    return new LoadableDetachableModel<List<MultivalueType>>() 
    {
        @Override
        protected List<BO> load() 
        {
            return dao.loadAll();
        }
     };
}

Note that I’m setting the default MultivalueType instance (redundantly) both as a CompundPropertyModel of the Form component and directly as a model of the DropDownChoice component. Based on what I have found on the Internet, this should be enough for the select-box to preselect the corresponding value when the page loads, but it does not work.

I have verified that the property variable in the Form component (obtained from the DAO) really contains valid data.

Also note that everything works fine but for the preselecting – I’m getting correctly populated propertySettings variable in the onSubmit method of the form.

  • 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-10T15:15:17+00:00Added an answer on June 10, 2026 at 3:15 pm

    I’ve finally managed to find the problem.

    I’ve realized that when I display the form, Wicket logs the following warning:

    Model returned object ... which is not available in the list of selected objects.
    

    Based on that error message I’ve found out that in order for the preselecting of default options to work, the Business Entities must override the equals method (see the corresponding JIRA ticket). At least in Wicket version 1.5.4, which I’m using.

    Hope this helps others who will get stuck with the same problem!

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

Sidebar

Related Questions

I am creating a select box for a form using this in _form.html.erb <%=
Related post: Populating a select box in a form using related ID in MVC3
I am creating a web page that has 3 basic elements, select box, button,
I was creating a form like this : if select b, the textbox is
In my form fancy select boxes are used. Which resulting in creating some spans
I am creating one form in html using table. Which have one Drop down
I am creating a form using Cake.In the form there is a $this->Form->button($i); element.
I am creating a form in CakePHP.A snippet of the code is given below.
I am creating a form, and giving user three options. They can select only
I am creating a search box form, but I would like to give the

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.