Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » TablePageData and SearchForm
TablePageData and SearchForm [message #1413318] Thu, 28 August 2014 09:10 Go to next message
Nils Israel is currently offline Nils IsraelFriend
Messages: 72
Registered: May 2010
Member
Hi,
I am testing the cool new feature TablePageData. Without a searchform it is working fine. But let's say there is a TablePage with 3 Columns: IDColumn, NameColumn and TownColumn.
The corresponding SearchForm has two fields: NameField and TownField.

Without TablePageData the relevant lines in the OutlineService are:

public Object[][] getUserData(UserSearchForm formData){
	StringBuilder statement = new StringBuilder();
	statement.append(""
	+"SELECT "
	+"	id, "
	+"	name, "
	+"	town "
	+"FROM "
	+"	users "
	+"WHERE 1=1 ");
	if (!StringUtility.isNullOrEmpty(formData.getName().getValue())){
		statement.append(" AND name like :name ");
	}
	if (!StringUtility.isNullOrEmpty(formData.getTown().getValue())){
		statement.append(" AND town like :town ");
	}
	return SQL.select(statement.toString(), formData);
}



With the TablePageData the lines are:

public UserTablePageData getUserData(UserSearchForm formData){
	UserTablePageData = new UserTablePageData();
	StringBuilder statement = new StringBuilder();
	statement.append(""
	+"SELECT "
	+"	id, "
	+"	name, "
	+"	town "
	+"FROM "
	+"	users "
	+"WHERE 1=1 ");
	if (!StringUtility.isNullOrEmpty(formData.getName().getValue())){
		statement.append(" AND name like :name ");
	}
	if (!StringUtility.isNullOrEmpty(formData.getTown().getValue())){
		statement.append(" AND town like :town ");
	}

	statement.append(""
	+"INTO "
	+"	:{id} "
	+"	:{name}, "
	+"	:{town}");
	SQL.selectInto(statement.toString(), formData, tablePageData);
	return tablePageData;
}


But now I get a ProcessingException:
expected a single value for ":{name}" but got multiple values.


Obviously the problem occurs because the field in the SearchForm an the column in the TablePageData have the same name.

It gets strange when I change the order of the bind bases:

SQL.selectInto(statement.toString(), tablePageData, formData);


I get all table rows and no error message if I leave the search fields empty. And so I thought this may be a workaround. But if I fill the name or the town field with a search string that should lead to some rows I get an empty (no rows) TablePageData. The strange thing is, that the debug log doesn't even show a sql query. So there is an empty TablePageData and no error message indicating that something has gone wrong.

Is there something I can do without changing the column or the search field names?

Kind regards,
Nils
Re: TablePageData and SearchForm [message #1413390 is a reply to message #1413318] Thu, 28 August 2014 12:24 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
This is a really interesting point. Thanks for your detailed description.

Quick/untested idea:
I think you can provide a name to the tableData with NVPair (class org.eclipse.scout.commons.holders.NVPair):
SQL.selectInto(statement.toString(), formData, new NVPair("table", tablePageData));


And then in your bindings:
INTO
   :{table.id} 
   :{table.name}, 
   :{table.town}



If this does'nt work, fell free to tell me. We need to find a solution for your problem.

___
Edit 08.09.2014:
By the way, I have written "untested", but I wrote the exact same code for the MiniCRM example on GitHub in october 2013. See StandardOutlineService.

[Updated on: Mon, 08 September 2014 18:42]

Report message to a moderator

Re: TablePageData and SearchForm [message #1413417 is a reply to message #1413390] Thu, 28 August 2014 13:17 Go to previous messageGo to next message
Dennis Geesen is currently offline Dennis GeesenFriend
Messages: 46
Registered: June 2014
Member
Sometime ago I was looking into the parser for the SQL binding and found a special keyword to mark output tokens: [OUT]
so, another approach would be something like:
INTO :[OUT]name 


However, I've never tested that option before. So, maybe one of the scout team knows more about it?!
Re: TablePageData and SearchForm [message #1413427 is a reply to message #1413390] Thu, 28 August 2014 13:41 Go to previous messageGo to next message
Nils Israel is currently offline Nils IsraelFriend
Messages: 72
Registered: May 2010
Member
Hi Jeremie and Dennis,
thanks for your help.

I tried both and the approach from Jeremie is working. So I added a note to the wiki (Concepts,New and Noteworthy).

Kind regards,
Nils
Re: TablePageData and SearchForm [message #1413466 is a reply to message #1413427] Thu, 28 August 2014 15:43 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Notice that in my example the name of the bind is absolutely free. To avoid the confusion with the OUT mentioned by Dennis, I have changed it to table.

Thanks a lot for the update of the documentation. It is nice to see contribution in this area.

This problem of 2 binds having conflicting names occurs in your case with a formData and a tablePageData, but I could imagine a lot of other situation where it could be a problem.

Example: reading from 2 formData in the same query select query for example.

PersonFormData with a property "id"
CompanyFormData with a property also called "id"

Select ... from ... where COMPANY_NR = :id /*from person formData*/ and PERSON_NR = :id /*from company formData*/


You should use the same trick:
SQL.select(query, new NVPair("company", companyFormData ), new NVPair("person", personFormData))


and in the query:
Select ... from ... where COMPANY_NR = :company.id and PERSON_NR = :person.id /*from company formData*/


I think the trick with 2 NVPair will also work for those cases.

I have referenced this forum thread as "TODO" in Sql Service > advanced binding

.
Previous Topic:Exported Scout application not working
Next Topic:Exclude client during server export
Goto Forum:
  


Current Time: Thu Apr 25 13:48:12 GMT 2024

Powered by FUDForum. Page generated in 0.02818 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top