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 |
J D Messages: 100 Registered: February 2021 |
Senior 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 #1849998 is a reply to message #1849995] |
Thu, 10 February 2022 14:49 |
|
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
|
|
| | |
Goto Forum:
Current Time: Thu May 09 00:40:28 GMT 2024
Powered by FUDForum. Page generated in 0.04533 seconds
|