Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Populating smartfields and list boxes from a JSON document(Beginner question: populating smartfields and listboxes from a JSON document)
Populating smartfields and list boxes from a JSON document [message #1849990] Thu, 10 February 2022 12:40 Go to next message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
Hello there everyone,

Whenever forms are loaded in my Scout application, I want the form's smartfields and listboxes to be populated with data retrieved from a remote REST server.

For example, I have the JSON document below:

[
    {
        "resultat": {
            "resource": "/genre",
            "genre": [
                {
                    "numero": 1,
                    "description": "Feminin"
                },
                {
                    "numero": 2,
                    "description": "Masculin"
                },
                {
                    "numero": 3,
                    "description": "X"
                }
            ]
        }
    },
    {
        "resultat": {
            "resource": "/typepartenaire",
            "type_partenaire": [
                {
                    "numero": 1,
                    "description": "Association"
                },
                {
                    "numero": 2,
                    "description": "Autre"
                },
                {
                    "numero": 3,
                    "description": "Conscription"
                },
                {
                    "numero": 7,
                    "description": "Employeur public (non-marchande)"
                },
                {
                    "numero": 4,
                    "description": "Entreprise (marchande)"
                },
                {
                    "numero": 5,
                    "description": "Formateur"
                },
                {
                    "numero": 6,
                    "description": "Hôpital"
                }
            ]
        }
    },
    {
        "resultat": {
            "resource": "/typepartenairecontact",
            "type_partenaire_contact": [
                {
                    "numero": 10,
                    "description": "Administratif"
                },
                {
                    "numero": 2,
                    "description": "Assistante Sociale"
                },
                {
                    "numero": 7,
                    "description": "Autres Travailleurs Associatif"
                },
                {
                    "numero": 3,
                    "description": "Autres Travailleurs Sociaux"
                },
                {
                    "numero": 4,
                    "description": "Bénévoles"
                },
                {
                    "numero": 5,
                    "description": "Juriste"
                },
                {
                    "numero": 1,
                    "description": "Médiateur"
                },
                {
                    "numero": 11,
                    "description": "Politique"
                },
                {
                    "numero": 6,
                    "description": "Soignants"
                },
                {
                    "numero": 9,
                    "description": "Écrivaine Public"
                },
                {
                    "numero": 8,
                    "description": "Éducateur"
                }
            ]
        }
    }
]


The form's smartfields and listboxes present a standard textual data and reduces the risk of misspellings. At the back end, what is stored in the database is the numeric code corresponding to the description labels in the JSON document above. so the user selects a certain text BUT the text's number will be saved in the database.

In the document above, there are 3 types of resources: genre, type_partenaire and type_partenaire_contact. Each one of these resources will have its own smartfield/listbox on the form.

Can anyone please help me with ideas on how to load and present the data above in smartfields ond listboxes?

Thanks a million,

JD
Re: Populating smartfields and list boxes from a JSON document [message #1849991 is a reply to message #1849990] Thu, 10 February 2022 13:09 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

Is your question related to Scout Classic (Java) or Scout JS? The solution looks different for the two flavors.

Cheers, André


Eclipse Scout Homepage | Documentation | GitHub
Re: Populating smartfields and list boxes from a JSON document [message #1849995 is a reply to message #1849990] Thu, 10 February 2022 14:12 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. I am using Scout Classic version 11.

JD
Re: Populating smartfields and list boxes from a JSON document [message #1849998 is a reply to message #1849995] Thu, 10 February 2022 14: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
Ok, in this case I'd suggest you implement an ILookupService in your Scout backend server --> MyRestCallLookupService.

This class provides the API required for the SmartField to work. You must implement methods like getDataByText or getDataByKey and as a result return ILookupRows. The implementation of that service will call your specific REST service with the required request parameters and processes and transforms the results. In your case you would map the "numero" property from your JSON to the "key" property of the LookupRow and the "description" to the "text" property. For the REST calls you could use the org.eclipse.scout.rt.rest.client.AbstractRestClientHelper.

In the Scout client you'll implement a MyRestLookupCall class which extends org.eclipse.scout.rt.shared.services.lookup.LookupCall and implement the getConfiguredService method, where you'd reference the MyRestCallLookupService.

I'd suggest to check this chapter here in the Scout documentation: https://eclipsescout.github.io/11.0/technical-guide.html#lookup-call

Your case should be pretty much what is described there, and in place of the "//compute result: corresponding lookup rows" comment you'd implement your specific REST logic, as described above.

Hope that helps,
André


Eclipse Scout Homepage | Documentation | GitHub
Re: Populating smartfields and list boxes from a JSON document [message #1850516 is a reply to message #1849998] Mon, 07 March 2022 14:00 Go to previous messageGo to next message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
Hi there Andre,

Thanks a lot for the tips. I've had to do a lot of refactoring and reading the Scout documentation again.

Thus far, I've gotten the SmartFields and ListBoxes in my application to work. I have tended to retrieve the information I need when forms are being initialized, and then use a LocalLookupCall to populate the widgets successfully. I however notice a little lag when loading a form that has many SmartFields; for example, I have a form with about 35 SmartFields and Listboxes. The lag is not a major problem but I may have to resort to fetching information from the Server directly into the widgets for some other forms.

I have 2 questions:
a) will using threads in execCreateLookupRows() and the various getDataXXX functions speed up the process

b) how do I create SmartFields and ListBoxes with Tree based content?

Thanks a million,

JD
Re: Populating smartfields and list boxes from a JSON document [message #1850521 is a reply to message #1850516] Mon, 07 March 2022 14:35 Go to previous message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
J D wrote on Mon, 07 March 2022 14:00
Hi there Andre,

Thanks a lot for the tips. I've had to do a lot of refactoring and reading the Scout documentation again.

Thus far, I've gotten the SmartFields and ListBoxes in my application to work. I have tended to retrieve the information I need when forms are being initialized, and then use a LocalLookupCall to populate the widgets successfully. I however notice a little lag when loading a form that has many SmartFields; for example, I have a form with about 35 SmartFields and Listboxes. The lag is not a major problem but I may have to resort to fetching information from the Server directly into the widgets for some other forms.

I have 2 questions:
a) will using threads in execCreateLookupRows() and the various getDataXXX functions speed up the process?

b) how do I create SmartFields and ListBoxes with Tree based content?

Thanks a million,

JD

Previous Topic:Alert "unsafe file upload" by upload to scout application
Next Topic:Scout wiht CesiumJS
Goto Forum:
  


Current Time: Wed Feb 28 22:06:57 GMT 2024

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

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

Back to the top