Skip to main content
Jump to: navigation, search

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

< Scout‎ | Tutorial‎ | 3.9‎ | webservices
(update images for 3.9)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{ScoutPage|cat=Tutorial 3.9}}
 
{{ScoutPage|cat=Tutorial 3.9}}
 
== 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 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.
+
On the client node, go to <tt>Forms</tt>. Right click on the node to create the Company {{ScoutLink|Concepts|Form}}
 +
 
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_1.png|Create Company Form]]
 +
 
 +
As the name of the form, enter <tt>Company</tt> and choose to create the Form ID which is the primary key of the company.
 +
 
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_3.9_2.png|Create Company Form]]
 +
 
 +
Click next to choose from the artifacts which also should be created by Scout SDK.
 +
 
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_3.9_3.png|Create Form artefacts]]
 +
 
 +
Uncheck all permissions as {{ScoutLink|Concepts|Security|Authorization}} is not part of this tutorial.
  
 
== Create Form Fields ==
 
== 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]:
+
On the <tt>CompanyForm</tt> node, go to the <tt>MainBox</tt>. Right click on the MainBox to create the following 9 Form {{ScoutLink|Concepts|Field}}'s:
 +
 
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_4.png|Create Form Field]]
  
 
  '''NameField'''
 
  '''NameField'''
  Type: String Field [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_5.png]
+
  Type: String Field
  Name: Name [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_6.png]
+
  Name: Name
 
  Class name: NameField
 
  Class name: NameField
 +
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_5.png|Set datatype for Form Field]] [[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_6.png|Set properties of Form Field]]
  
 
  '''SymbolField'''
 
  '''SymbolField'''
Line 51: Line 67:
 
  Class name: ChangeField
 
  Class name: ChangeField
  
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].
+
Because <tt>ChangeField</tt> represents a procentual value, click on that field and check the property <tt>Percent</tt> in Scout Property View.
  
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].
+
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_7.png|Set percent mode for the ChangeField]]
  
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].
+
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 <tt>Enabled</tt> in Scout Property View
 +
 
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_11.png|Disable webservice specific fields]]
 +
 
 +
As the stock quote symbol can be maximal 5 characters long, this must be constrained on the <tt>SymbolField</tt> by selecting the field and set the <tt>Max Length</tt> property in Scout Property View to 5
 +
 
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_13.png|Set maxLength to symbol field]]
  
 
== Associate CompanyForm with CompanyTablePage ==
 
== Associate CompanyForm with CompanyTablePage ==
To edit and create companies, you have to add an 'EDIT' and 'NEW' menu to the <code>CompanyTablePage</code>.
+
To edit and create companies, you have to add an <tt>EDIT</tt> and <tt>NEW</tt> menu to the <tt>CompanyTablePage</tt>.
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]:
+
On client node, go to the node <tt>Desktop > Outlines > StandardOutline > Child Pages > CompanyTablePage > Table > Menus</tt>. Click on the menu node to create the following 2 menus:
 +
 
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_8.png|Create menu on CompanyTablePage]]
  
  '''NEW menu [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_9.png]'''
+
  '''NEW menu'''
 
  Name: New company...
 
  Name: New company...
 
  Class Name: NewCompanyMenu
 
  Class Name: NewCompanyMenu
Line 68: Line 92:
 
  Form handler: NewHandler
 
  Form handler: NewHandler
  
'''EDIT menu [http://wiki.eclipse.org/Image:Org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_10.png]'''
+
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_9.png|Create the NEW menu]]
 +
 
 +
'''EDIT menu'''
 
  Name: Edit company...
 
  Name: Edit company...
 
  Class Name: EditCompanyMenu
 
  Class Name: EditCompanyMenu
Line 75: Line 101:
 
  Form handler: ModifyHandler
 
  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:
+
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_10.png|Create the EDIT menu]]
 +
 
 +
In the EDIT menu action, we also have to provide the <tt>CompanyNr</tt> primary key as argument to the <tt>CompanyForm</tt>. For that reason, double click the <tt>EditCompanyMenu</tt> to modify the code in <tt>execAction()</tt> as follows:
  
 
<source lang="java">
 
<source lang="java">
Line 94: Line 122:
  
 
== Load and persist company data ==
 
== Load and persist company data ==
Scout SDK already created a <code>CompanyService</code> in order to load and persist company data.
+
Scout SDK already created a <tt>CompanyService</tt> in order to load and persist company data.
 
You only have to implement those operations:
 
You only have to implement those operations:
  
For that reason, go to the server node and open the <code>CompanyService</code> by double click on 'Services' | 'CompanyService'. You will find the following method stubs:
+
For that reason, go to the server node and open the <tt>CompanyService</tt> by double click on <tt>Services > CompanyService</tt>.  
 +
 
 +
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_12_3.9.png|Load and persist data in CompanyService]]
 +
 
 +
You will find the following method stubs:
  
 
   '''prepareCreate'''
 
   '''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.
+
   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'''
 
   '''create'''
Line 165: Line 198:
 
</source>
 
</source>
  
 
+
''You can continue the [[{{BASEPAGENAME}}/Webservices_with_JAX-WS|webservices tutorial]].''
[[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 Form]]
+
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_3.png|thumb|Create Form artefacts]]
+
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_4.png|thumb|Create Form Field]]
+
[[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|Set properties of Form Field]]
+
[[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 CompanyService]]
+
[[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_13.png|thumb|Set maxLength to symbol field]]
+

Latest revision as of 13:47, 21 August 2013


Scout
Wiki Home
Website
DownloadGit
Community
ForumsBlogTwitterG+
Bugzilla
Bugzilla

Create Company Form

On the client node, go to Forms. Right click on the node to create the Company Form

Create Company Form

As the name of the form, enter Company and choose to create the Form ID which is the primary key of the company.

Create Company Form

Click next to choose from the artifacts which also should be created by Scout SDK.

Create Form artefacts

Uncheck all permissions as Authorization 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 Field's:

Create Form Field

NameField
Type: String Field
Name: Name
Class name: NameField

Set datatype for Form Field Set properties of Form Field

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.

Set percent mode for the ChangeField

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

Disable webservice specific fields

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

Set maxLength to symbol field

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:

Create menu on CompanyTablePage

NEW menu
Name: New company...
Class Name: NewCompanyMenu
Super Type: AbstractMenu
Form to start: CompanyForm
Form handler: NewHandler

Create the NEW menu

EDIT menu
Name: Edit company...
Class Name: EditCompanyMenu
Super Type: AbstractMenu
Form to start: CompanyForm
Form handler: ModifyHandler

Create the EDIT menu

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 CompanyService 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 CompanyService by double click on Services > CompanyService.

Load and persist data in CompanyService

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 CompanyService extends AbstractService implements ICompanyService {
 
  @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;
  }
}

You can continue the webservices tutorial.

Back to the top