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.