I don't have any specific use-case for this but I'm interested on how to do
this properly.

There is a DropDownChoice that displays list of Batches.
Now the display option should be "id" and "name" concated together and
the DropDownChoice selection model will be only the name.

Batch is simple entity/DTO with Long id and String name, something like:

public class Batch implements Serializable {
    private Long id;
    private String name;

DropDownChoice is added to form that has CompoundPropertyModel for example
like this:

public class ResultDto implement Serializable {
    private String batchName;

the only solution I can think of is custom IChoiceRenderer but looks nasty

    List<Batch> batches = Lists.newArrayList();
    List<String> names

    add(new DropDownChoice<>(" batchName ", names, new
IChoiceRenderer<String>() {
            public Object getDisplayValue(String name) {

                Batch batch1 = batches.stream().filter(batch ->

                return batch1.getId() + " - " + batch1.getName();

            public String getIdValue(String object, int index) {
                return String.valueOf(index);

            public String getObject(String id, IModel<? extends List<?
extends String>> choices) {
                return batches.get(Integer.valueOf(id)).getName()

Surely there has to be a better way to do this!


Reply via email to