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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:24:03+00:00 2026-05-11T04:24:03+00:00

Let’s say I have the following command object: class BreakfastSelectCommand{ List<Breakfast> possibleBreakfasts; Breakfast selectedBreakfast;

  • 0

Let’s say I have the following command object:

class BreakfastSelectCommand{     List<Breakfast> possibleBreakfasts;     Breakfast selectedBreakfast; } 

How can I have spring populate ‘selectedBreakfast’ with a breakfast from the list?

I was figuring I’d do something like this in my jsp:

<form:radiobuttons items='${possibleBreakfasts}' path='selectedBreakfast'  /> 

But this doesn’t seem to work. Any ideas?

thanks,

-Morgan

  • 1 1 Answer
  • 3 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. 2026-05-11T04:24:04+00:00Added an answer on May 11, 2026 at 4:24 am

    The key to it all of this is the PropertyEditor.

    You need to define a PropertyEditor for your Breakfast class and then configure the ServletDataBinder using registerCustomEditor in the initBinder method of your controller.

    example:

    public class BreakfastPropertyEditor extends PropertyEditorSupport{     public void setAsText(String incomming){         Breakfast b = yourDao.findById( Integer.parseInt(incomming));         setValue(b);     }     public String getAsText(){         return ((Breakfast)getValue()).getId();     } } 

    note you’ll be needing some null checking etc, but you get the idea. In your controller:

    public BreakfastFooBarController extends SimpleFormController {     @Override     protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) {         binder.registerCustomEditor(Breakfast.class, new BreakfastPropertyEditor(yourDao));     } } 

    things to watch out for:

    • PropertyEditor’s are not thread safe
    • if you need spring beans, either manually inject them or define them in spring as prototype scope and use method injection into your controller
    • throw IllegalArgumentException if the inbound parameter is not valid/not found, spring will convert this into a binding error correctly

    hope this helps.

    Edit (in response to the comment): It looks a little strange in the given example because BreakfastSelectCommand doesn’t look like an entity, I’m not sure what the actual scenario you have is. Say it is an entity, for example like Person with a breakfast property then the formBackingObject() method would load the Person object from the the PersonDao and return it as the command. The binding phase would then change the breakfast property depending on the selected value, such that the command that arrives in onSubmit has the breakfast property all set up.

    Depending on the implementation of your DAO objects calling them twice or attempting to load the same entity twice doesn’t actually mean that you will get two SQL statements being run. This applies particularly to Hibernate, where it guarantees that it will return the same object that is in it’s session for a given identifier, thus running letting the binding attempt to load the Breakfast selection even through it hasn’t changed shouldn’t result in any undue overhead.

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

Sidebar

Related Questions

Let me explain best with an example. Say you have node class that can
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say I have the following classes : public class MyProductCode { private String
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say we have the following: abstract class A; class B : public A;
Let's say I have the following tables: class Module { long MID // PK
Let's say I have a table with a Color column. Color can have various
Let's say I have a sortable list like this: $(.song-list).sortable({ handle : '.pos_handle', axis
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>

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.