The default search function is defined in layout file by two controls: txt_search - entry text field and btn_search - button that starts the process. These two elements must be located on toolbar component.
The search function looks for value of the description field. The description field is a field in the attribute data table declared by metadata element #51.
The search function will be disabled if the description field is not defined in layer's metadata.
If parent toolbar has property equal="yes", the user may type "%" in search field (txt_search) to match an arbitrary number of characters. Otherwise the exact search will be performed. By default equal="no", it allows partial-string matching. Searching is case insensitive.
The default search function is simple and suitable for all layers in project. Of course it doesn't allow the complex conditional expressions based on several fields. For advanced search you may use HTML and JavaScript or write your own Search dialogue and embed it in our applet.
HTML form plus JavaScript. Look at the source code for JavaScript function that is called by this simple HTML form. The function creates the complex conditional expression and invokes map's method searchAttribute.
Customized embedded search dialogue allows you to avoid the issues with JavaScript Applet interaction. We wrote the sample Search dialogue FrameSearch.java. You are free to modify it for your needs.
This class is a good example of customized component you may embed in our applet. It is an implementation of two interfaces CarteHostListener and StatusListener, that allow to handle the events of applet and map respectively. To embed this dialogue in applet, it must be declared in applet layout file.
Behind the scene
All searching of the attribute data is performed via method of the class org.alov.map.Carte
searchAttribute(String layerId, String sQuery, int searchType)
This is the main method for searching for the attribute data. It allows looking for data on both client and server sides. In other words, for downloaded part and data that are still on server.
The parameters:
layerId - unique identifier of layer in project file.(It is defined by name attribute). If this parameter is not defined this is the current active layer.
sQuery - the text to compare with value of Description field (metadata #51) or conditional expression, like (NAME LIKE '%ville') AND (POPULATION>100000)
searchtype - determines the type of search. There are four possible values:
1 or 2. Search for Description field value. They are similar, except that the type "2" forces the adding of the patterns "%" on both sides of search string.
3. Applet performs the search and downloads the data from server side if needed. Selection of objects, map repainting and others actions are your responsibility.
4. After the search operation, applet tries to show the attribute window with the results.