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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:23:40+00:00 2026-05-18T00:23:40+00:00

A fairly common use case occurs where there is a list of Java objects,

  • 0

A fairly common use case occurs where there is a list of Java objects, from which selections can be made on a web form – usually you’d use the primary key of the object as the value so that the controller could either do a lookup, or just bind the key to whichever object is created/updated.

My problem is that the list to choose from are not persistent, keyed objects, they are business models from a service which have no reasonable way to retrieve them based on the data contained. Below is some psuedo code where a list of Foo’s are given to the page, and we can easily communicate to the controller onSubmit the name of Foo, but what if there are other fields of Foo that need to be submitted?

controller:

referenceData() {
    ...
    List foos = fooService.getFoosForBar( bar )
    return { 'foos', foos }
}

jsp:

<form>
   ...
<spring:bind path="formData.foo">
    <select name="<c:out value="${status.expression}" />">
        <c:forEach items="${foos}" var="foo">
            <option value="<c:out value="${foo.name}"/>">
                <c:out value="${foo.name}"/>
            </option>
        </c:forEach>
    </select>
</spring:bind>
   ...
</form>

Some example solutions would be to use hidden fields to submit Foo’s other properties and keep them in sync as the selection is changed, but I prefer not to use JavaScript in a situation like this where it will likely add confusion. There are certainly other ways to accomplish this too.

My question is does there exist any standard practice for accomplishing this? Or should I just come up with my own way of doing so? I’d rather not re-invent wheels if possible, and this is so seemingly common that just winging it may not be the best approach.

  • 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-18T00:23:40+00:00Added an answer on May 18, 2026 at 12:23 am

    Based on your limitations, you must encode the other data memebers of foos as the value of the option.


    <option label="${foo.name}" value="${foo.encodedValues}"/>


    The encodedValues method might look something like this:

    
        private String SEPARATOR = ",";
    
        public String getEncodedValues()
        {
            final StringBuffer returnValue = new StringBuffer();
    
            returnValue.append(field1);
            returnValue.append(SEPARATOR);
            returnValue.append(field2);
            returnValue.append(SEPARATOR);
            returnValue.append(field3);
    
            return returnValue.toString();
        }
    
    

    If you have a number of selects that need to have encoded values, you may want to create a class that does the encoding and decoding of these values to centralize the code.

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

Sidebar

Related Questions

I have a fairly straightforward and common use case. A panel, in which resides
The use of shift + scroll wheel is fairly common for horizontal scrolling. Both
This is a fairly common problem to which I have yet to find an
In my data model I have a fairly common division between my objects/tables/data: Transactional
what I'm trying is fairly common but I can't find any pointers about this
I have a setup which must be fairly common: I have an H2 db,
I'm coming from Java and I'm fairly new to C#, so please bear with
This is a fairly common problem, it probably has a name, I just don't
I'm trying to do a fairly common thing in my PySide GUI application: I
I'm working with a fairly common pattern - a page opens a child window

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.