The suggestion is triggered when the user starts writing a value for the property. The application queries the database and suggests possible values for that field. When a suggested value is selected by the user, it replaces any other value previously entered for the property.
It is important to note that this feature suggests values for a property, but also allows the user to enter new values if none of the suggested ones is suitable.
The suggest can be used with properties of type string, text with no extra care. It may also be used with other types, such as date, datetime, time, etc., as long as the suggested values are properly formatted to be valid for the input box.
More than one suggest element can be used for a single property at the same time. The values suggested will correspond to the results of both expressions merged.
Be careful when using the suggest element with expressions that might return a large set of values as this may result in poor performance.
This HQL expression suggests all existing city values that contain the current entered value as part of their name.
<property name="city" label="City" > ... <suggest expr="SELECT a.city FROM Address as a WHERE a.city LIKE concat('%', ?, '%')"/> ... </property>
The next example suggests all existing city values in the Address entity and all the name values in the MyCity entity that start with the current entered value.
<property name="city" label="City" > ... <suggest expr="SELECT a.city FROM Address as a WHERE a.city LIKE concat(?, '%')"/> <suggest expr="SELECT m.name FROM MyCity as m WHERE m.name LIKE concat(?, '%')"/> ... </property>
Using the suggest element with properties of type date.
<property name="dateOfBirth" label="Date of Birth" type="date"> <suggest expr="SELECT DATE_FORMAT(dateOfBirth, '%d/%m/%Y') FROM Seller WHERE DATE_FORMAT(dateOfBirth, '%d/%m/%Y') LIKE concat('%', ?, '%')" /> </property>
RESTful API: /(entityname)/suggest(propertyname)/(.*) maps to Java Class: (basepackage).(entityname)Services.java suggest(propertyname)()
For example, registers the /Address/suggestcity/(.*) service in the MainControllerAbstract REST Controller that maps to the suggestCity() method in the AddressServicesAbstract class.
Generates the suggestCity() method in the AddressServicesAbstract class.