Suggest (element)

From JRapid

Jump to: navigation, search

suggest is an element child of property.

Contents

Description

The suggest element is used to indicate that the possible values for a property are to be suggested based on the results of an HQL query specified in the expr attribute.



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 HQL expression for this query receives one and only one parameter. This parameter holds the value currently entered for the field and must be used in the HQL expression.

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.

Usage

<property>
    <suggest 
         expr = HQL
    />
</property>

Example

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>
Suggest example


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>
More than one suggest element for a 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>
Using suggest element for a property of type date

Generates

 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.

See also

Personal tools