Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 943
lostiniceland Avatar asked Jan 13 '11 21:01

lostiniceland


People also ask

Which attribute is used with select element?

The form attribute is used to explicitly associate the select element with its form owner. The name attribute represents the element's name.

What component is used to select several options and can be selected for more than one option?

Checkboxes allow a user to select multiple choices.

What is select attribute?

The selected attribute is a boolean attribute. When present, it specifies that an option should be pre-selected when the page loads. The pre-selected option will be displayed first in the drop-down list. Tip: The selected attribute can also be set after the page loads, with a JavaScript.

How do you give a select tag a name in HTML?

The HTML <select> name Attribute is used to specify a name for the drop-down list. It is used to reference the form-data after submitting the form or to reference the element in a JavaScript. Attribute Values: It contains the value i.e name which specify the name for the <select> element.


2 Answers

:) Just spent the whole Sunday struggling out of the same problem. Simply add itemLabel="your field name from Car class".

<field:select field="car" 
              id="c_de_recordcars_domain_Record_car" 
              items="${cars}" 
            **itemLabel="CarName"**
              itemValue="id"
              path="/cars" />
like image 55
Mailis Toompuu Avatar answered Sep 30 '22 17:09

Mailis Toompuu


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.

like image 31
viator Avatar answered Sep 30 '22 16:09

viator