Search code examples
spring-roohtml-select

How to display an particlar attribut in a selectbox in a ROO-generated application


I am currently getting myself into Spring-Roo and Spring-MVC. I have a fairly simple application that Roo generated for me. It consists of two entities, Record and Car, where Record has a reference to one particlar car.

After the initial setup I change one of the views to use field:select and display a combobox for selecting available cars and add them to a record.

<field:select field="car" id="c_de_recordcars_domain_Record_car" items="${cars}" path="/cars" />

This tag gives me a headache. As by now, the comboxbox displays all available cars...but it does so by displaying all attributes ( like "Car 1 Tue Jan 18 00:00:00 CET 2011 Friver1"). All I want is that the combobox only shows the name-attribute ("Car 1").

Within the tag, there is only the "itemValue"-Attribute but this only renders the value that is put into the request-param...I need something like "displayValue" where I can point to the java-field that is used to display.

How can I achieve this? Thanks


Solution

  • Spring Roo (using Spring MVC functionality) offers use Application Conversion Service. You should implement method Converter<Car, String> getCarConverter() inside the ApplicationConversionServiceFactoryBean.

    See reference for details.