|
Re: AbstractSmartField - parsing for an exact value [message #1851003 is a reply to message #1851001] |
Thu, 24 March 2022 11:32 |
|
Hi JD
Ok, so you have a table with a person per row and a column with a driver license for that person, correct?
Like this:
André | Category A
JD | Category A2
And now you can select a person from the table, and show that data in a form, right?
How exactly do you set the value in your DriverLicenseField? I assume you use the String-based text from the table. In that case you should use the ID/key of the driver license CodeType instead - because this is unique, other than the text of the codes.
Thus you should use a SmartColumn to display the driver license in the table, which gives you the key and the text for each possible driver license. Or you could store the key of the driver license in an invisible column.
Cheers,
André
Eclipse Scout Homepage | Documentation | GitHub
|
|
|
Re: AbstractSmartField - parsing for an exact value [message #1851004 is a reply to message #1851003] |
Thu, 24 March 2022 11:57 |
J D Messages: 102 Registered: February 2021 |
Senior Member |
|
|
Hi there Andre,
Thanks for your reply. The Drive's License smartfield is one of several smartfields I have that are based on LookupCalls not on CodeTypes because the contents are dynamic - additions, deletions etc. CodeTypes and their contents do not change, if I remember correctly. I was considering introducing a Map<Integer, String> into the field definition to handle the search for keys/values but I wonder if it is not an overkill. The idea is to locate the exact text in the Map structure, retrieve its key and then search for the key in the smartfield.
This is how I used to do it in JavaFX. What do you think of this?
Cheers,
JD
[Updated on: Thu, 24 March 2022 11:59] Report message to a moderator
|
|
|
Re: AbstractSmartField - parsing for an exact value [message #1851007 is a reply to message #1851004] |
Thu, 24 March 2022 12:56 |
|
Usually one would implement an (I)LookupService to lookup dynamic data used in SmartFields, or more specific: to lookup one or more keys for a given (search) text. Or in dummy-code:
DriverLicenseSmartField { // client
getConfiguredLookupCall() {
return DriverLicenseLookupCall.class;
}
}
DriverLicenseLookupCall { // shared
getConfiguredService() {
return IDriverLicenseLookupService.class;
}
}
DriverLicenseLookupService implements IDriverLicenseLookupService { // server
getDataByText(call) {
// implement the specific logic to find a driver license by text here and return a collection of results having text _and_ key
}
}
You should not have to fiddle with the SmartField widget. Everything should happen in the LookupService implementation. Everything the SmartField must know is the contract defined by the ILookupService interface. You can implement dozens of different lookup calls, with different data sources, the principle always stays the same.
Eclipse Scout Homepage | Documentation | GitHub
[Updated on: Thu, 24 March 2022 12:56] Report message to a moderator
|
|
|
|
|
Re: AbstractSmartField - parsing for an exact value [message #1851117 is a reply to message #1851115] |
Mon, 28 March 2022 10:49 |
|
Hi JD
Although that may work, it doesn't look correct to my eye ;-) You should achieve the exact same thing simply by setting the value of the SmartField. If the setup of the SmartField is correct, it can be used like any other value field in Scout. The value of the SmartField is always == the key of the referenced entity. Thus:
getDriverLicenseField().setValue(employee.getDriversLicense().getKey());
The SmartField then internally calls the required methods on the ILookupService to load the display text for the given key. Just make sure, your DriversLicense class has a key. The type of this key must be equal to the value type of the SmartField. Internally the smart field sets the correct lookup row and the value automatically, when you click on a row in the propsal chooser table (assuming the key field is set properly on your lookup row instance).
class DriversLicense {
Integer getKey() {
return m_key;
}
}
class DriverLicenseField extends AbstractSmartField<Integer> { // <-- the generic type must match the type of the key.
}
When you call smartField.setValue(123 /*the key*/), the framework will call the ILookupService#getDataByKey() method which loads the LookupRow including the text for the unique key.
Eclipse Scout Homepage | Documentation | GitHub
|
|
|
|
Powered by
FUDForum. Page generated in 0.71292 seconds