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

  • Home
  • SEARCH
  • 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 6677637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:08:47+00:00 2026-05-26T04:08:47+00:00

I need to set the null value string for a dropDownChoice component. The default

  • 0

I need to set the null value string for a dropDownChoice component. The default value for null choice is “Choose One”, which is hardcoded in the Wicket AbstractSingleChoice class.

The usual way of overriding this is to define a property resource.

However my DropdownChoice component is dynamically generated at runtime, and added to a panel (which is within a datatable). The DropDownChoice is not specifically referenced in the markup.

I’m looking for suggestions on how to programmatically override the default null value string in this situation. It would be nice if the DropDownChoice constructor had an additional parameter for this.

Do I need to programmatically create a new property resource?

Hope this makes sense.

  • 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-26T04:08:48+00:00Added an answer on May 26, 2026 at 4:08 am

    You can override AbstractSingleSelectChoice.getNullKey() and AbstractSingleSelectChoice.getNullValidKey() in order to make Wicket retrieve a localized resource from a .properties or .xml file that does not have the component id as part of the key. This is documented in this JIRA issue: Open DropDownChoice null value internationalization key

    For instance:

    DropDownChoice ddc = new DropDownChoice(id, model, choices){
       @Override
       protected String getNullKey(){ return "customDdcNullValue"; }
       @Override
       protected String getNullValidKey(){ return "customDdcNullValue"; }
    }
    

    Will retrieve the <option>‘s text from the customDdcNullValue property.

    These methods seem to have been added in version 1.4.4, if you’re on 1.3, you could always use an IChoiceRenderer with the DropDownChoice that returns the proper String in the case of null value. Note that you could retrieve it from resources (with getString(), or StringResourceModel), or grab the value from database/cache if necessary. This may depend on how are you already localizing the choices for non-null values.

    Also, you could use the source code of AbstractSingleSelectChoice.getDefaultChoice() to roll your own DropDownChoice with this behavior.

    UPDATE: Another way of handling this is to provide your own custom value that represents null, or no-choice. Just remember to use setNullValid(false) on the DropDownChoice to prevent null from appearing when there is a selected value, and initialize the ddc’s model with your no-selection value when you still don’t know its value in order to avoid Wicket provide null in the getDefaultChoice() call.

    When defining the value for your no-selection option, pay special attention to this part of AbstractSingleSelectChoice.getDefaultChoice():

    // Null is not valid. Is it selected anyway?
    if ((selected == null) || getNoSelectionValue().equals(selected) ||
          selected.equals(EMPTY_STRING))
    {
    

    Take into account that getNoSelectionValue() returns -1, so please do not use -1, or an empty string, as your custom null value. I learnt this the hard way, believe me, it’s not pleasing.

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

Sidebar

Related Questions

I need to set a dependency property on a control (Slider.Value) in my code
I need to set up some RewriteRules to redirect a URL which has a
I have a column in the database which is Name its string with null
I need to change border background color based of the textblock text string value
I need to initialize a set of static String values stored in an XML
I need to set the height of every textbox on my form, some of
I need to set the text within a DIV element dynamically. What is the
I need to set up an instance of SQL Server 2005 with SQL_Latin1_General_CP850_Bin as
I need to set up this scenario: A SQL Server 2005 database will create
We need to set up a secure certificate on an Apache reverse proxy. We've

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.