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.8/webservices/Create Company Form"
(→Load and persist company data) |
(→Load and persist company data) |
||
Line 110: | Line 110: | ||
Implement those methods as follows: | Implement those methods as follows: | ||
+ | <source lang="java"> | ||
+ | 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; | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
Revision as of 17:07, 8 November 2011
Contents
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 artefacts 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 [7]
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 [8].
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 [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' | 'MainOutline' | '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 CompanyProcessService
in order to load and persist company data.
You only have to implement those CRUD 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 opening a non-existing company
create
Is called CompanyForm#NewHandler
to create a company record in database
load
Is called by CompanyForm#ModifyHandler
to load company data from database
store
Is called CompanyForm#ModifyHandler
to update company data in database
Implement those methods as follows:
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; } } </code> [[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_11.png|thumb|Disable webservice specific fields]] [[Image:org.eclipse.scout.tutorial.jaxws.CreateCompanyForm_12.png|thumb|Load and persist data in CompanyProcessService]]