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/minicrm/Write The Second Page"

< Scout‎ | Tutorial‎ | minicrm
(Using a table page as a child page to another page)
m (fix double redirection)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{ScoutPage|cat=Tutorial}}
+
#REDIRECT [[Scout/Tutorial/3.8/Minicrm/Write the second page]]
{{note|Scout Tutorial|This page belongs to the {{ScoutLink|Tutorial|minicrm|Minicrm Tutorial}}. }}
+
 
+
We already have a page for companies. Quickly create a second top-level page for persons. Then reuse the same page as child page for the existing company page.
+
 
+
== A new table page ==
+
 
+
Here are some notes to guide you:
+
 
+
Add <tt>getPersonTableData</tt> to the '''StandardOutlineService'''. Use <tt>SELECT PERSON_NR, LAST_NAME, FIRST_NAME FROM PERSON</tt> as your SQL statement.
+
 
+
[[Image:Person.jpg]]
+
 
+
If you edited StandardOutlineService manually, make sure to add <tt>getPersonTableData</tt> to the interface '''IStandardOutlineService''' as well.
+
 
+
<tt>getPersonTableData</tt> doesn't need a parameter, unless you want to create a '''PersonSearchForm''' as well; you don't need to do this for the tutorial, but it might be an excellent excercise
+
 
+
Add a '''New Page...''' to ''Child Pages'' of the '''StandardOutline'''; it uses the ''AbstractPageWithTable'' template, has the name ''Person'' and the type name ''PersonTablePage''
+
 
+
This is how the '''StandardOutline has two child pages''', now:
+
 
+
<source lang="java">
+
protected void execCreateChildPages(Collection<IPage> pageList) throws ProcessingException {
+
  CompanyTablePage companyTablePage = new CompanyTablePage();
+
  pageList.add(companyTablePage);
+
  PersonTablePage personTablePage = new PersonTablePage();
+
  pageList.add(personTablePage);
+
}
+
</source>
+
 
+
This is how the '''PersonTablePage loads data''' from the outline service:
+
 
+
<source lang="java">
+
@Override
+
protected Object[][] execLoadTableData(SearchFilter filter) throws ProcessingException {
+
  return SERVICES.getService(IStandardOutlineService.class).getPersonTableData();
+
}
+
</source>
+
 
+
Add the following '''columns''' to the table inside the ''PersonTablePage'':
+
 
+
{| cellpadding="10"
+
!Table Column Template
+
!Name
+
!Type Name
+
!Note
+
|-
+
|Long Column
+
|(empty)
+
|PersonNrColumn
+
|not displayable
+
|-
+
|String Column
+
|Last Name
+
|LastNameColumn
+
|width 200
+
|-
+
|String Column
+
|First Name
+
|FirstNameColumn
+
|width 200
+
|}
+
 
+
Test it! The login I keep using is username '''admin''' password '''manager'''. This is what it should look like:
+
 
+
[[Image:Scout Application With Person Page.png]]
+
 
+
== Using a table page as a child page to another page ==
+
 
+
Return to the '''CompanyTablePage''', click through to ''Child Page'', and pick '''Add Page...''' (we don't need to create a ''new'' page because we want to reuse the ''person table page''), and pick '''PersonTablePage'''.
+
 
+
If you test your application now, you will see the complete list of people under every single company. What you're missing is a way to pass '''the currently selected company to the SQL statement selecting the persons'''.
+
 
+
This is what we want, basically:
+
 
+
# when the ''child page'' is created using <tt>execCreateChildPage</tt>, the value of the ''CompanyNrColumn'' acting as the parent is copied into a '''variable on the PersonTablePage'''
+
# the ''PersonTablePage'' uses the variable as an argument in its call to '''getPersonTableData''' on the ''standard outline service'' (this requires a change to the service implementation and to the service interface)
+
# ''getPersonTableData'' will then use the variable in its <tt>WHERE</tt> clause in order to select the appropriate persons
+
 
+
First, return to the '''PersonTablePage''', click through to ''Variables'', and pick '''New Property Bean...''' from the context menu. Use '''CompanyNr''' for the ''Name'' and use '''Long''' for the ''Bean Type''.
+
 
+
[[Image:newPropertyBean_personTablePage.png]]
+
 
+
[[Image:NewPropertyBean_1.png]]
+
 
+
[[Image:Scout Variable For Table Page.png]]
+
 
+
But how do we set it? We need to set the '''CompanyNr''' when the ''person table page'' is being created '''by its parent'''. Return to the '''CompanyTablePage''' and click on the '''Exec Create Child Page''' link in the ''Properties'' view. Change it as follows:
+
 
+
<source lang="java">
+
@Override
+
protected IPage execCreateChildPage(ITableRow row) throws ProcessingException {
+
  PersonTablePage childPage = new PersonTablePage();
+
  childPage.setCompanyNr(getTable().getCompanyNrColumn().getValue(row));
+
  return childPage;
+
}
+
</source>
+
 
+
Notice how we get to use the ''row'' argument.
+
 
+
So now, as the ''person table page'' instance is created, it "knows" what its company is. It's stored in the ''CompanyNr'' variable. Now all we need to do is pass this number on to the ''outline service''.
+
 
+
Go to the '''PersonTablePage''' and click on '''Exec Load Table Data''' in the ''Properties'' view. Change its definition as follows:
+
 
+
<source lang="java">
+
@Override
+
protected Object[][] execLoadTableData(SearchFilter filter) throws ProcessingException {
+
  return SERVICES.getService(IStandardOutlineService.class).getPersonTableData(getCompanyNr());
+
}
+
</source>
+
 
+
You'll note that this produces an error because the ''outline service'' is not yet ready to accept an extra parameter!
+
 
+
Return to the '''StandardOutlineService''' and click on '''IStandardOutlineService''' to change the interface for ''getPersonTableData'' as follows:
+
 
+
<source lang="java">
+
public Object[][] getPersonTableData(Long companyNr) throws ProcessingException;
+
</source>
+
 
+
Now go to the '''StandardOutlineService''' and change its definition of ''getPersonTableData'' as follows:
+
 
+
<source lang="java">
+
public Object[][] getPersonTableData(Long companyNr) throws ProcessingException {
+
  if (companyNr == null) {
+
    return SQL.select("SELECT PERSON_NR, LAST_NAME, FIRST_NAME FROM PERSON");
+
  } else {
+
    return SQL.select("" +
+
"SELECT PERSON_NR, LAST_NAME, FIRST_NAME" +
+
" FROM PERSON WHERE COMPANY_NR = :companyNr",
+
new NVPair("companyNr", companyNr));
+
  }
+
}
+
</source>
+
 
+
Done!
+
 
+
Notice how we used '''NVPair''' to match a bind variable with a variable value. When we wrote our {{ScoutLink|Tutorial|Add a form|first form}} we just used the '''form data''' object to provide the bind variables, relying on the ''naming conventions''. Here, we can no longer do that and need to be explicit about it.
+
 
+
Test it. Make sure you restart the server since you changed the services.
+
 
+
[[Image:Scout Minicrm Company with Persons.png]]
+
[[Image:Scout Minicrm Company without Persons.png]]
+

Latest revision as of 05:10, 26 September 2012

Back to the top