Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » AbstractSmartField - parsing for an exact value(Default parsing behaviour )
AbstractSmartField - parsing for an exact value [message #1851001] Thu, 24 March 2022 10:52 Go to next message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
Hi there everyone,

I have some issues with the default behaviour of the AbstractSmartField. When one types a text into the field, it displays the closest matches to the typed text. This is fine and works very well allowing the user to make the best choice.

However, in my use case, when a row in a table needs editing, the data is displayed in a form. I have a smartfield on the form for Drivers licence categories https://www.gov.uk/driving-licence-categories

If the Person selected in the table has a driver's licence type of say "Category A", after filling the form (using the parseAndSetValue method for smartfields), the smartfield complains that there are
"multiple results for "Category A"". It looks like it parses for the closest results BUT not for an exact result.

Is there any way I can get it to parse for an exact result?

Cheers,

JD
Re: AbstractSmartField - parsing for an exact value [message #1851003 is a reply to message #1851001] Thu, 24 March 2022 11:32 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
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 Go to previous messageGo to next message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
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 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
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 #1851021 is a reply to message #1851007] Thu, 24 March 2022 16:44 Go to previous messageGo to next message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
Thanks for the clarification, Andre. I'll cleanup my code and follow your advice.

Cheers,

JD
Re: AbstractSmartField - parsing for an exact value [message #1851115 is a reply to message #1851021] Mon, 28 March 2022 10:26 Go to previous messageGo to next message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
Hi there Andre,

I found a solution for the problem. I would like to share it here for the benefit of others who might have the same problem.

I just replaced the parseAndSetValue method with the setValueByLookupRow method and passed the first item in the list returned by callTextLookup as a parameter to it.

      // Driver's license SmartField
      if (!StringUtility.isNullOrEmpty(employee.driversLicense().get())) {
        // getDriversLicenseField().parseAndSetValue(employee.driversLicense().get());
        getDriversLicenseField().setValueByLookupRow(
            getDriversLicenseField().callTextLookup(employee.driversLicense().get(), 0).get(0));
      }


This ensures that the exact Lookup row corresponding to the value of employee.driversLicense().get() is returned.

Thanks a lot for your assistance and clarification.

Cheers,

JD
Re: AbstractSmartField - parsing for an exact value [message #1851117 is a reply to message #1851115] Mon, 28 March 2022 10:49 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
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
Re: AbstractSmartField - parsing for an exact value [message #1851198 is a reply to message #1851117] Wed, 30 March 2022 11:55 Go to previous message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
Hi there Andre,

I finally decided to modify the SQL view query on the backend and instead of returning text labels of foreign keys in the Employee view, the query returns the actual integer foreign keys.

I then discovered that when these keys are passed to the Eclipse Scout smartfields, everything functions correctly! Methods like setValue(KEY) finds the correct text associated with the key because the keys are unique.

Thnaks a lot for your clarification. I really appreciate it.

Cheers,

JD
Previous Topic:Working with Tile view in Table
Next Topic:Get data for form from database
Goto Forum:
  


Current Time: Mon Mar 04 09:53:50 GMT 2024

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

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

Back to the top