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
The form attribute is used to explicitly associate the select element with its form owner. The name attribute represents the element's name.
Checkboxes allow a user to select multiple choices.
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.
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.
:) 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" />
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With