Skip to main content

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.

Jump to: navigation, search

Difference between revisions of "Scout/Tutorial/3.8/webservices/Create Company Form"

< Scout‎ | Tutorial‎ | 3.8
(Create Company Form)
 
(55 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
{{ScoutPage|cat=Tutorial 3.8}}
 
== Create Company Form ==
 
== Create Company Form ==
On the client node, go to 'Forms'. Right click on the node to create the Company {{ScoutLink|Concepts|Form}} [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_1.png]. As name of the form, enter <code>Company</code> and choose to create the Form ID which is the primary key of the company [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_2.png]. Click next to choose from the artefacts which also should be created [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_3.png]. Uncheck all permissions as {{Scout|Concepts|Security/authorization}} is not part of this tutorial. Also, we uncheck the <code>NewHandler</code> to only access existing companies.
+
On the client node, go to 'Forms'. Right click on the node to create the Company {{ScoutLink|Concepts|Form}} [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_1.png]. As the name of the form, enter <code>Company</code> and choose to create the Form ID which is the primary key of the company [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_2.png]. Click next to choose from the artifacts which also should be created by Scout SDK [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_3.png]. Uncheck all permissions as {{ScoutLink|Concepts|Security|Authorization}} is not part of this tutorial.
  
 +
== Create Form Fields ==
 +
On the <code>CompanyForm</code> node, go to the 'MainBox'. Right click on the MainBox to create the following 9 Form {{ScoutLink|Concepts|Field}}'s [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_4.png]:
  
  As page layout, choose <code>AbstractPageWithTable</code> [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyTablePage_2.png] to create a page representing tabular data. On the next step, enter <code>Company</code> as name for that page and choose to add this page to the <code>MainOutline</code> [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyTablePage_3.png]. By clicking Finish, the page is created and attached to the MainOutline.
+
  '''NameField'''
 +
Type: String Field [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_5.png]
 +
Name: Name [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_6.png]
 +
Class name: NameField
  
== Create columns ==
+
'''SymbolField'''
On the <code>CompanyTablePage</code> node, go to 'Table' | 'Columns'. Right click on the node to create a new {{ScoutLink|Concepts|Column}} [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyTablePage_4.png]. Please add the following three columns to that table:
+
Type: String Field
 +
Name: Symbol
 +
Class name: SymbolField
  
  '''CompanyNrColumn'''
+
  '''TradeTimeField'''
  Type: Long Column [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyTablePage_5.png]
+
  Type: Date Field
  Name: ''Do not fill because column represents primary key and therefore is hidden''
+
  Name: Trade time
  Class name: CompanyNrColumn [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyTablePage_6.png]
+
  Class name: TradeTimeField
  
  '''NameColumn'''
+
  '''ValueLastField'''
  Type: String Column
+
  Type: Double Field
  Name: Name
+
  Name: Value last
  Class name: NameColumn
+
  Class name: ValueLastField
  
  '''SymbolColumn'''
+
  '''ValueOpenField'''
  Type: String Column
+
  Type: Double Field
  Name: Symbol
+
  Name: Value open
  Class name: SymbolColumn
+
  Class name: ValueOpenField
  
To not display the <code>CompanyNr</code> column because of holding the primary key, go to that column in Scout SDK and uncheck <code>Displayable</code> in Scout Property View [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyTablePage_8.png].
+
'''ValueLowField'''
 +
Type: Double Field
 +
Name: Value low
 +
Class name: ValueLowField
  
To have the columns equally distributed over the available space of the table page, go to the {{ScoutLink|Concepts|Table}} node and check <code>Auto Resize Columns</code> in Scout Property View [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyTablePage_9.png].
+
'''ValueHighField'''
 +
Type: Double Field
 +
Name: Value high
 +
Class name: ValueHighField
  
== Create service to load company data from database ==
+
'''VolumeField'''
Finally, we have to populate the table with company data. For that purpose, we create an Outline Service. An Outline Service is just like all other services in Scout. Basically, they are plain [http://en.wikipedia.org/wiki/OSGi OSGi] services which are registered in <code>plugin.xml</code> and are accessible by <code>SERVICES#get(<service name>)</code>. Depending on the service factory chosen in their service registration, they act as proxy for client-server communication, meaning that all service requests are tunneled to the backend. For more details, please refer to {{ScoutLink|Concepts|Communication}}.
+
Type: Long Field
 +
Name: Volume
 +
Class name: VolumeField
  
To create the Outline Service, go to the server node. Right click on the node 'Outline Services' to create the new outline service [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyTablePage_10.png]. Please create the service as follows:
+
'''ChangeField'''
 +
Type: Double Field
 +
Name: Change
 +
Class name: ChangeField
  
'''Service definition [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyTablePage_11.png]'''
+
Because <code>ChangeField</code> represents a procentual value, click on that field and check the property <code>Percent</code> in Scout Property View [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_7.png].
Class name: MainOutlineService
+
Super Type: AbstractService
+
  
'''Service registration [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyTablePage_12.png]'''
+
Furthermore, all stock quote specific fields have to be disabled as those fields cannot be modified because data is provided by a webservice. To to so, select all those fields in Scout SDK and uncheck <code>Enabled</code> in Scout Property View [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_11.png].
On the second wizard page you choose where to create and to register the service.
+
Because the <code>MainOutlineService</code> is used for client-server communication, we are required to have a service interface in the Shared Plug-In with a proxy registration on client-side.
+
  
Double click on the <code>MainOutlineService</code> created to open the corresponding Java class. In there, create the operation <code>getCompanyTableData</code> to load company data from database. Also add the operation signature to the service interface <code>IMainOutlineService</code> to be accessible from client side.
+
As the stock quote symbol can be maximal 5 characters long, this must be constrained on the <code>SymbolField</code> by selecting the field and set the <code>Max Length</code> property in Scout Property View to 5 [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_13.png].
 +
 
 +
== Associate CompanyForm with CompanyTablePage ==
 +
To edit and create companies, you have to add an 'EDIT' and 'NEW' menu to the <code>CompanyTablePage</code>.
 +
On client node, go to the node 'Desktop' | 'Outlines' | 'StandardOutline' | 'Child Pages' | 'CompanyTablePage' | 'Table' | 'Menus'. Click on the menu node to create the following 2 menus [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_8.png]:
 +
 
 +
'''NEW menu [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_9.png]'''
 +
Name: New company...
 +
Class Name: NewCompanyMenu
 +
Super Type: AbstractMenu
 +
Form to start: CompanyForm
 +
Form handler: NewHandler
 +
 
 +
'''EDIT menu [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_10.png]'''
 +
Name: Edit company...
 +
Class Name: EditCompanyMenu
 +
Super Type: AbstractMenu
 +
Form to start: CompanyForm
 +
Form handler: ModifyHandler
 +
 
 +
In the EDIT menu action, we also have to provide the <code>CompanyNr</code> primary key as argument to the <code>CompanyForm</code>. For that reason, double click the <code>EditCompanyMenu</code> to modify the code in <code>execAction()</code> as follows:
  
 
<source lang="java">
 
<source lang="java">
public class MainOutlineService extends AbstractService implements IMainOutlineService {
+
@Override
 +
protected void execAction() throws ProcessingException {
 +
  CompanyForm form = new CompanyForm();
  
   @Override
+
   // Add the following line to set the primary key of the selected company to the form
   public Object[][] getCompanyTableData() throws ProcessingException {
+
   form.setCompanyNr(getCompanyNrColumn().getSelectedValue());
    return SQL.select("" +
+
    
        "SELECT   COMPANY_NR, " +
+
  form.startModify();
        "        NAME, " +
+
  form.waitFor();
        "        SYMBOL " +
+
  if (form.isFormStored()) {
        "FROM     COMPANY ");
+
     reloadPage();
 
   }
 
   }
 
}
 
}
 
</source>
 
</source>
  
== Load company data into CompanyTablePage ==
+
== Load and persist company data ==
Once the <code>MainOutlineService</code> is created to load company data from database, go to <code>CompanyTablePage</code> to consume the service's data.
+
Scout SDK already created a <code>CompanyProcessService</code> in order to load and persist company data.
On the Scout Property View, click on the operation <code>Exec Load Table Data</code> to populate the company table [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyTablePage_13.png]. Implement the method as follows:
+
You only have to implement those operations:
 +
 
 +
For that reason, go to the server node and open the <code>CompanyProcessService</code> by double click on 'Process Services' | 'CompanyProcessService'. You will find the following method stubs:
 +
 
 +
  '''prepareCreate'''
 +
  Is called by <code>CompanyForm#NewHandler</code> prior to open a non-existing company. This is if a company is to be created to show some default values in the form. It is not used by this tutorial.
 +
 
 +
  '''create'''
 +
  Is called by <code>CompanyForm#NewHandler</code> to create a company record in database
 +
 
 +
  '''load'''
 +
  Is called by <code>CompanyForm#ModifyHandler</code> to load a company record from database
 +
 
 +
  '''store'''
 +
  Is called <code>CompanyForm#ModifyHandler</code> to update a company record in database
 +
 
 +
Please implement those method stubs as following:
  
 
<source lang="java">
 
<source lang="java">
public class MainOutlineService extends AbstractService implements IMainOutlineService {
+
public class CompanyProcessService extends AbstractService implements ICompanyProcessService {
  
 
   @Override
 
   @Override
   protected Object[][] execLoadTableData(SearchFilter filter) throws ProcessingException {
+
   public CompanyFormData prepareCreate(CompanyFormData formData) throws ProcessingException {
     return SERVICES.getService(IMainOutlineService.class).getCompanyTableData();
+
    // nop
 +
     return formData;
 +
  }
 +
 
 +
  @Override
 +
  public CompanyFormData create(CompanyFormData formData) throws ProcessingException {
 +
    formData.setCompanyNr(SQL.getSequenceNextval("GLOBAL_SEQ"));
 +
    SQL.insert("" +
 +
        "INSERT INTO COMPANY " +
 +
        "          (COMPANY_NR, " +
 +
        "            NAME, " +
 +
        "            SYMBOL) " +
 +
        "VALUES    (:companyNr, " +
 +
        "            :name, " +
 +
        "            :symbol)"
 +
        , formData);
 +
 
 +
    return formData;
 +
  }
 +
 
 +
  @Override
 +
  public CompanyFormData load(CompanyFormData formData) throws ProcessingException {
 +
    SQL.selectInto("" +
 +
        "SELECT NAME, " +
 +
        "      SYMBOL " +
 +
        "FROM  COMPANY " +
 +
        "WHERE  COMPANY_NR = :companyNr " +
 +
        "INTO  :name, " +
 +
        "      :symbol "
 +
        , formData);
 +
    return formData;
 +
  }
 +
 
 +
  @Override
 +
  public CompanyFormData store(CompanyFormData formData) throws ProcessingException {
 +
    SQL.update("" +
 +
        "UPDATE  COMPANY " +
 +
        "SET      NAME = :name, " +
 +
        "        SYMBOL = :symbol " +
 +
        "WHERE    COMPANY_NR = :companyNr"
 +
        , formData);
 +
 
 +
    return formData;
 
   }
 
   }
 
}
 
}
 
</source>
 
</source>
  
Finally, if you launch the application, you should see something like this:
 
 
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyTablePage_14.png|600px]]
 
  
 
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_1.png|thumb|Create Company Form]]
 
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_1.png|thumb|Create Company Form]]
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_2.png|thumb|Create Company Table Page]]
+
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_2.png|thumb|Create Company Form]]
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_3.png|thumb|Create Company Table Page]]
+
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_3.png|thumb|Create Form artefacts]]
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_4.png|thumb|Create Company Table Page]]
+
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_4.png|thumb|Create Form Field]]
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_5.png|thumb|Create Company Table Page]]
+
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_5.png|thumb|Set datatype for Form Field]]
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_6.png|thumb|Create Company Table Page]]
+
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_6.png|thumb|Set properties of Form Field]]
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_7.png|thumb|Create Company Table Page]]
+
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_8.png|thumb|Create menu on CompanyTablePage]]
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_9.png|thumb|Create the NEW menu]]
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_10.png|thumb|Create the EDIT menu]]
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_7.png|thumb|Set percent mode for the ChangeField]]
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_11.png|thumb|Disable webservice specific fields]]
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_12.png|thumb|Load and persist data in CompanyProcessService]]
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_13.png|thumb|Set maxLength to symbol field]]

Latest revision as of 03:55, 24 April 2012

The Scout documentation has been moved to https://eclipsescout.github.io/.

Create Company Form

On the client node, go to 'Forms'. Right click on the node to create the Company The Scout documentation has been moved to https://eclipsescout.github.io/. [1]. As the name of the form, enter Company and choose to create the Form ID which is the primary key of the company [2]. Click next to choose from the artifacts which also should be created by Scout SDK [3]. Uncheck all permissions as The Scout documentation has been moved to https://eclipsescout.github.io/. is not part of this tutorial.

Create Form Fields

On the CompanyForm node, go to the 'MainBox'. Right click on the MainBox to create the following 9 Form The Scout documentation has been moved to https://eclipsescout.github.io/.'s [4]:

NameField
Type: String Field [5]
Name: Name [6]
Class name: NameField
SymbolField
Type: String Field
Name: Symbol
Class name: SymbolField
TradeTimeField
Type: Date Field
Name: Trade time
Class name: TradeTimeField
ValueLastField
Type: Double Field
Name: Value last
Class name: ValueLastField
ValueOpenField
Type: Double Field
Name: Value open
Class name: ValueOpenField
ValueLowField
Type: Double Field
Name: Value low
Class name: ValueLowField
ValueHighField
Type: Double Field
Name: Value high
Class name: ValueHighField
VolumeField
Type: Long Field
Name: Volume
Class name: VolumeField
ChangeField
Type: Double Field
Name: Change
Class name: ChangeField

Because ChangeField represents a procentual value, click on that field and check the property Percent in Scout Property View [7].

Furthermore, all stock quote specific fields have to be disabled as those fields cannot be modified because data is provided by a webservice. To to so, select all those fields in Scout SDK and uncheck Enabled in Scout Property View [8].

As the stock quote symbol can be maximal 5 characters long, this must be constrained on the SymbolField by selecting the field and set the Max Length property in Scout Property View to 5 [9].

Associate CompanyForm with CompanyTablePage

To edit and create companies, you have to add an 'EDIT' and 'NEW' menu to the CompanyTablePage. On client node, go to the node 'Desktop' | 'Outlines' | 'StandardOutline' | 'Child Pages' | 'CompanyTablePage' | 'Table' | 'Menus'. Click on the menu node to create the following 2 menus [10]:

NEW menu [11]
Name: New company...
Class Name: NewCompanyMenu
Super Type: AbstractMenu
Form to start: CompanyForm
Form handler: NewHandler
EDIT menu [12]
Name: Edit company...
Class Name: EditCompanyMenu
Super Type: AbstractMenu
Form to start: CompanyForm
Form handler: ModifyHandler

In the EDIT menu action, we also have to provide the CompanyNr primary key as argument to the CompanyForm. For that reason, double click the EditCompanyMenu to modify the code in execAction() as follows:

@Override
protected void execAction() throws ProcessingException {
  CompanyForm form = new CompanyForm();
 
  // Add the following line to set the primary key of the selected company to the form
  form.setCompanyNr(getCompanyNrColumn().getSelectedValue());
 
  form.startModify();
  form.waitFor();
  if (form.isFormStored()) {
    reloadPage();
  }
}

Load and persist company data

Scout SDK already created a CompanyProcessService in order to load and persist company data. You only have to implement those operations:

For that reason, go to the server node and open the CompanyProcessService by double click on 'Process Services' | 'CompanyProcessService'. You will find the following method stubs:

 prepareCreate
 Is called by CompanyForm#NewHandler prior to open a non-existing company. This is if a company is to be created to show some default values in the form. It is not used by this tutorial.
 create
 Is called by CompanyForm#NewHandler to create a company record in database
 load
 Is called by CompanyForm#ModifyHandler to load a company record from database
 store
 Is called CompanyForm#ModifyHandler to update a company record in database

Please implement those method stubs as following:

public class CompanyProcessService extends AbstractService implements ICompanyProcessService {
 
  @Override
  public CompanyFormData prepareCreate(CompanyFormData formData) throws ProcessingException {
    // nop
    return formData;
  }
 
  @Override
  public CompanyFormData create(CompanyFormData formData) throws ProcessingException {
    formData.setCompanyNr(SQL.getSequenceNextval("GLOBAL_SEQ"));
    SQL.insert("" +
        "INSERT INTO COMPANY " +
        "           (COMPANY_NR, " +
        "            NAME, " +
        "            SYMBOL) " +
        "VALUES     (:companyNr, " +
        "            :name, " +
        "            :symbol)"
        , formData);
 
    return formData;
  }
 
  @Override
  public CompanyFormData load(CompanyFormData formData) throws ProcessingException {
    SQL.selectInto("" +
        "SELECT NAME, " +
        "       SYMBOL " +
        "FROM   COMPANY " +
        "WHERE  COMPANY_NR = :companyNr " +
        "INTO   :name, " +
        "       :symbol "
        , formData);
    return formData;
  }
 
  @Override
  public CompanyFormData store(CompanyFormData formData) throws ProcessingException {
    SQL.update("" +
        "UPDATE   COMPANY " +
        "SET      NAME = :name, " +
        "         SYMBOL = :symbol " +
        "WHERE    COMPANY_NR = :companyNr"
        , formData);
 
    return formData;
  }
}


Create Company Form
Create Company Form
Create Form artefacts
Create Form Field
Set datatype for Form Field
Set properties of Form Field
Create menu on CompanyTablePage
Create the NEW menu
Create the EDIT menu
Set percent mode for the ChangeField
Disable webservice specific fields
Load and persist data in CompanyProcessService
Set maxLength to symbol field

Back to the top