|
Re: REST frontend questions [message #1838891 is a reply to message #1838890] |
Mon, 08 March 2021 11:15 |
Paolo Bazzi Messages: 33 Registered: January 2017 Location: Switzerland |
Member |
|
|
Hi JD,
J D wrote on Mon, 08 March 2021 09:42Hi there everyone,
I've been working on the project building menus, pages and forms and so far so good. I am very pleased with the default functionality in Eclipse Scout 10 tables. They are really good.
The next steps for me are what Andre advised in his response here https://www.eclipse.org/forums/index.php?t=msg&th=1106874&goto=1837778&#msg_1837778
Following that threw up the following questions:
a) I want to start creating the various entities for the application. I have been reading Chapter 16 Data Objects in the Scout Technical Guide. I created an entity for contacts but I'm not sure if what I did is correct:
public class ContactDo extends DoEntity {
public DoValue<String> contactId() {
return doValue("contactid");
}
public DoValue<String> firstName() {
return doValue("firstname");
}
...
Your data object code looks correct, just the method names and string literals should be identical, see comment below:
J D wrote on Mon, 08 March 2021 09:42
b) My server sends JSON documents with key values in French so for instance, instead of "firstname", it will send "prenom". Should I have return doValue("prenom") instead of return doValue("firstname") and so on in the ContactDo class how will this affect mapping to the table that will display the data?
The name of the attribute method (here for instance firstname()) must be identical to the string literal used within the method (here "firstname"). If the method should have another name than the attribute name within the JSON document, you can use the AttributeName annotation. See the example here: https://eclipsescout.github.io/10.0/technical-guide.html#rename-an-attribute-of-a-data-object-in-a-subclass
Or with your data object:
@AttributeName("prenom")
public DoValue<String> firstName() {
return doValue("prenom");
}
J D wrote on Mon, 08 March 2021 09:42
c) Should all the entities be in their own package or can I put each entity in the package where the Form object and the Page object are located?
It depends whether you want to use the data object classes only in your frontend code or also in your backend code where you load and store the data.
If you use the data objects just for de client/UI layer, you can put them in the same packges as your forms and pages. If you use the data objects also in your REST backend (if it is also Scout-based) then you should put the data objects in a module shared between frontend and backend.
J D wrote on Mon, 08 March 2021 09:42
d) Does the REST frontend need the server part of a regular Scout application or can the client part communicate with my REST server without passing through the Scout server part?
No it does not need to pass through the Scout server part. The Scout client is able to invoke REST endpoints, it just needs a few Scout modules providing the functionality for REST and data objects but not the complete Scout server modules dependencies.
I think this dependencies should enable the REST (and therefore Jackson/Jersey) dependency in order to be able to invoke a REST endpoint from your client:
<!-- JAX-RS Jersey Client -->
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.scout.rt</groupId>
<artifactId>org.eclipse.scout.rt.rest.jersey.client</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.scout.rt</groupId>
<artifactId>org.eclipse.scout.rt.rest.jackson</artifactId>
</dependency>
J D wrote on Mon, 08 March 2021 09:42
e) Do I need to create packages for the REST classes?
That's up to you but not strictly necessary.
Cheers,
Paolo
Eclipse Scout Homepage | Documentation | GitHub
|
|
|
|
Powered by
FUDForum. Page generated in 0.05892 seconds