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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:24:07+00:00 2026-05-31T05:24:07+00:00

I have a problem implementing dropdownchoice in my code. I want to display a

  • 0

I have a problem implementing dropdownchoice in my code. I want to display a list of object of type ProductCategory. This is all well and fine, but when i try to save the form, the whole ProductCategory object is saved, and not just the field from the object which is displayed in the select list.

Here is what my code looks like:

    IModel categories = new LoadableDetachableModel() {
        public List<ProductCategory> load() {
            List<ProductCategory> l = categoryService.findAllProducts();
            return l;
        }
    };

    IChoiceRenderer renderer = new IChoiceRenderer() {
        public Object getDisplayValue(Object obj) {
            ProductCategory category = (ProductCategory) obj;
            return category.getName();
        }

        public String getIdValue(Object obj, int index) {
            ProductCategory category = (ProductCategory) obj;
            return category.getName();
        }
    };

    DropDownChoice<ProductCategory> listCategories = new DropDownChoice<ProductCategory>(
            "productCategory",
            categories,
            renderer
    );

    add(listCategories);

The generated HTML looks something like this:

<select wicket:id="productCategory" name="productCategory">
    <option selected="selected" value="">Vælg en</option>
    <option value="test1">test1</option>
    <option value="test2">test2</option>
</select>

The “productCategory” field exists in an Object of type “Product”, and is of type String.

As i tried to describe; i want to save ProductCategory.getName() to the “productCategory” field in Product, and not the entire ProductCategory Object.
In other words: I want to save “test1” to Product.productCategory, but instead it saves com.test.webapp.domain.ProductCategory@1.

Can anyone please tell how this is done?

Any help is much appreciated.

  • 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-31T05:24:08+00:00Added an answer on May 31, 2026 at 5:24 am

    Your problem is that the model object behind the ddc is of type ProductCategory. On save, this will be casted to the String type – as defined in your model object behind the form.

    I would change the code to have only strings in your choice list.

        public List<String> load() {
            List<String> pcChoices = new ArrayList<String>();
            for(ProductCategory pc : categoryService.findAllProducts()) {
                pcChoices.add(pc.getName());
            }
            return pcChoices;
        }
    

    Doing so, you can also get rid of your choice renderer.

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

Sidebar

Related Questions

I have problem with return statment >.< I want to store all magazine names
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have a problem with a command button (implementing the ICommand). I want, when
I have a slight problem implementing vibration functionality in my application. My code is:
I have problem with implementing Rich Text Editor (all that i tried, e.g. TinyMCE).
I have a problem implementing a for loop. I get this error when I
I have a problem implementing this example in java, tableFilterDemo is a class that
Hi I'm having a problem implementing this method. I have added using System.Management but
I have some problem implementing a segment control. Because i want it to be
I have a problem with the code below. Basically im implementing a polling mechanism,

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.