|Casting query results [message #1053221]
||Fri, 03 May 2013 04:21
| Bertin Kiekebosch
Registered: August 2011
I have a form witfh some fields and a table on it. Normally to load the data in the processing Service I use the selectInto method to load the fields and the table data.
so to load the formData I have two select into calls
SERVICE.selectInto("the sql", formData);
SERVICE.selectInto("the sql", formData.getTable());
Now I have a more complex case where I have to process the table data myself before I can add it to the formData so I use a 'normal' select to get the table data.
Object tempResults = SERVICE.select("the sql");
Then I process the data which means changing some values, removing records from it etc.
In the end I add the processed records 1 by 1 to the formData with:
The problem with this is that the automatic casting (database types to column types) that Scout does for me is not executed. I solved this by doing it myself for every field like:
tempResults[iRow, iColumn] = TypeCastUtility.castValue(tempResults[iRow, iColumn] , Boolean.class);
The question is, is there a better way to do this? In the way I did it, it works but it is error-prone. If I add a column, change its type etc, change the order of columns etc. I always have to remember to adapt casting.
|Re: Casting query results [message #1053244 is a reply to message #1053221]
||Fri, 03 May 2013 07:15
| Jeremie Bresson
Registered: October 2011
The SDK should generate setter methods on the AbstractTableFieldData contained in your FormData.|
This way, in your for each loop, you can do:
//table is somthing like "formData.getTable()" you can declare it outside of your loop.
int i = table.addRow(ITableHolder.STATUS_NON_CHANGED);
table.setStatus(i, "my Status");
If you send the FormData back and forth between client and server, you will probably also need:
* table.clearRows() before your loop (corresponding to AbstractTableFieldData#clearRows())
* table.setValueSet(true) after your loop (corresponding to AbstractTableFieldData#setValueSet(boolean)). This will indicate that you have set values in the TableFieldData. I think it is an obligation to tell "a table with no rows". Otherwise the form will ignore your TableFieldData when you do importFormData(..) in the client.
Let me know if it works for you.
[Updated on: Fri, 03 May 2013 07:16]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.01763 seconds