|
|
Line 1: |
Line 1: |
− | {{ScoutPage|cat=HowTo 3.8}}
| |
| | | |
− | Your application features a table of data, eg. sub-agreements. You want three menus:
| |
− |
| |
− | # New sub-agreement...
| |
− | # Edit sub-agreement...
| |
− | # Delete sub-agreement
| |
− |
| |
− | When creating a new sub-agreement, you want to show the sub-agreement dialog with no data. When the user clicks the OK button, the data should be inserted into a table.
| |
− |
| |
− | When editing an existing sub-agreement, you want to show the sub-agreement dialog, loading existing data and showing it to the user, and when the user clicks the OK button, the data in the table should be updated.
| |
− |
| |
− | When deleting an existing sub-agreement, you want to show a little confirmation message before the data is deleted from the table.
| |
− |
| |
− | All data modification (insert, update, and delete) should happen on the server. The client will just call the appropriate methods provided by a process service.
| |
− |
| |
− | == Dialog with Fields and Buttons ==
| |
− |
| |
− | # In your projects, find the '''Forms''' folder and create a new form. Provide a name (for humans) and a type name (a Java class).
| |
− | # In the form's MainBox, create a field, an OK button, and a Cancel button.
| |
− |
| |
− | Without an OK button you will not be able to save any changes.
| |
− |
| |
− | Without a Cancel button you will not be able to close the dialog (unless you provide other means of closing it).
| |
− |
| |
− | == Connecting a Process Service ==
| |
− |
| |
− | Loading and storing data is typically done with a Scout Process Service. ([[Create a Scout Process Service|Scout Process Service]]). The process service loads the data in a so called formData-object which is known by the client and the server. After filling the formData-object it is sent to the client where it will be imported into the form. <br/>
| |
− | To connect our form with such a process service you need to do the steps below (this assumes that you already have created a process service).
| |
− |
| |
− | # Create a NEW and a MODIFY handler for your form.
| |
− | # Override the execLoad-Method and call the service to load the data.
| |
− | # Override the execStore-Method and call the service to store the data.
| |
− |
| |
− | Steps 2 and 3 don't have do be done manually if you create the handler with the scout-sdk. Also the formData is created automatically.
| |
− |
| |
− | == Calling the Dialog from a Menu ==
| |
− |
| |
− | This assumes you already have a created a [[Create a Scout Table Page|Scout Table Page]].
| |
− |
| |
− | # Find the table page, drill down to your table, and create the three new menus we mentioned at the top of the page.
| |
− | # The New menu must be visible even if no existing sub-agreement has been selected. Deselect the '''Single Selection Action''' checkbox in order to allow that.
| |
− | # The Delete menu must allow multiple selection. Select the '''Multi Selection Action''' checkbox in order to allow that.
| |
− | # Create an '''Exec Action''' for your menus.
| |
− |
| |
− | '''New''': Note how we make sure to wait until the user is finished.
| |
− |
| |
− | If the user changed anything, we're going to reload the page.
| |
− |
| |
− | @Override
| |
− | public void execAction() throws ProcessingException {
| |
− | SubAgreementForm form = new SubAgreementForm();
| |
− | form.setParentProjectType(getParentProjectType());
| |
− | form.startNew();
| |
− | form.waitFor();
| |
− | if(form.isFormStored()){
| |
− | reloadPage();
| |
− | }
| |
− | }
| |
− |
| |
− | '''Modify''': Note how we make sure to wait until the user is finished.
| |
− |
| |
− | If the user changed anything, we're going to reload the page.
| |
− |
| |
− | @Override
| |
− | public void execAction() throws ProcessingException{
| |
− | SubAgreementForm form = new SubAgreementForm();
| |
− | form.setParentProjectType(getParentProjectType());
| |
− | form.startModify();
| |
− | form.waitFor();
| |
− | if(form.isFormStored()){
| |
− | reloadPage();
| |
− | }
| |
− | }
| |
− |
| |
− | '''Delete''': We do some more heavy lifting here because we don't need to show a dialog.
| |
− | We figure out how many rows have been selected, then we call a process service to delete them.
| |
− | It returns the number of rows deleted. If the numbers don't match, we got an error somewhere
| |
− | on the way.
| |
− |
| |
− | Reload the page if necessary.
| |
− |
| |
− | if(MessageBox.showDeleteConfirmationMessage(getTypeColumn()
| |
− | .getSelectedDisplayTexts())) {
| |
− | ISubAgreementsProcessService svc = SERVICES.getService(ISubAgreementsProcessService.class);
| |
− | int sel=getTypeColumn().getSelectedValues().length;
| |
− | int del=svc.remove(getProjectNo(), getTypeColumnColumn().getSelectedValues());
| |
− | if(sel!=del) {
| |
− | MessageBox.showOkMessage(Texts.get("DeleteMenu"),
| |
− | Texts.get("DeleteNotComplete"), null);
| |
− | }
| |
− | if (del>0) {
| |
− | reloadPage();
| |
− | }
| |
− | }
| |