Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Scout/Tutorial/3.7/Minicrm/Add a search form"
(→Create Search Form) |
(→Adding Fields) |
||
Line 28: | Line 28: | ||
== Adding Fields == | == Adding Fields == | ||
+ | |||
+ | Add a field to the ''search form'': right-click the ''CompanySearchForm'' and pick '''New Form Field...''' from the menu. | ||
[[Image:Scout New Form Field.png]] | [[Image:Scout New Form Field.png]] | ||
+ | |||
+ | Pick '''String Field''' from the list and click ''Next''. Set the name to ''Name'' and click ''Finish''. | ||
[[Image:Scout New String Form Field.png]] | [[Image:Scout New String Form Field.png]] | ||
+ | |||
+ | This is already enough to show a functional ''search form'': | ||
+ | |||
+ | [[Image:Scout Minicrm With Search Form.png]] | ||
== Adapt the outline service operation getCompanyTableData == | == Adapt the outline service operation getCompanyTableData == |
Revision as of 11:42, 12 October 2010
Once we have created a table page and implemented the service to get the table data we can take advantage of a feature the Scout SDK offers: it can create a search form based on the information it already has.
The alternative, of course, is to create the search form manually.
Create Search Form
Go to the CompanyTablePage, right click and choose Create Search Form. The created Search Form will contain a field for each column of the table based on who it is created.
Use Company as the name and click Next.
Done! What did Scout SDK do?
- it created a CompanySearchForm in the client plugin
- it created a CompanySearchFormData in the shared plugin
- it set the Search Form property of the CompanyTablePage to CompanySearchForm
There is one missing piece, obviously. The service that gets the actual data needs to build some sort of constraint (a WHERE clause to the SQL statement) to filter the rows returned.
Adding Fields
Add a field to the search form: right-click the CompanySearchForm and pick New Form Field... from the menu.
Pick String Field from the list and click Next. Set the name to Name and click Finish.
This is already enough to show a functional search form:
Adapt the outline service operation getCompanyTableData
In order to constrain the SQL statement for the Company Outline we have to adapt the service operation getCompanyTableData and add a parameter searchFilter of the type CompanySearchFormData to the method. Do that for both the service interface and service implementation (IStandardOutlineService and StandardOutlineService).
Now simply change the SQL statement in the following way:public Object[][] getCompanyTableData(CompanySearchFormData filter) throws ProcessingException { StringBuilder statement = new StringBuilder(); statement.append( "SELECT COMPANY_NR, SHORT_NAME, NAME " + "FROM COMPANY " + "WHERE 1=1 "); if(!StringUtility.isNullOrEmpty(filter.getShortname().getValue())){ statement.append("AND UPPER(SHORT_NAME) LIKE UPPER(:shortname || '%')"); } if(!StringUtility.isNullOrEmpty(filter.getName().getValue())){ statement.append("AND UPPER(NAME) LIKE UPPER(:name || '%')"); } return SQL.select(statement.toString(), filter); }
You can use :<name of field in formdata> to directly access the FormData object and the values that are held in its inner classes (corresponding to the field on the Form associated to the FormData). You don't need to surround the value by ' as it would have been necessary in a common SQL statement as this is already done by Scout itself.
Now we need to forward the CompanySearchFormData to the server. Therefore go to the method execLoadTableData in the CompaniesTablePage and add a new parameter to the service call according to its interface definition. The needed CompanySearchFormData is held in the parameter filter of type SearchFilter which is passed to the method execLoadTableData.
return SERVICES.getService(IStandardOutlineService.class).getCompanyTableData((CompanySearchFormData)filter.getFormData());