Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the way you transfer data object from client to server for persisting datas using GWT?
    primarykey
    data
    text
    <p>If you use JPA or another kind of persistence, you probably have a way to save a record that is sent to client via ajax.</p> <p><strong>EDIT : the interface is done with GWT, so all ajax call are classic java method (converted to javascript equivalent)</strong></p> <p>Let's take the class Person which is an entity in database. Person has four fields : <code>name, birthday, id, email</code></p> <p>When you load a person from server via ajax, you generally send to client a Person object.</p> <p>In your Person editor, you display the name, the birthday and the email. When the Person object is edited you may want to display the id.</p> <p>There are two cases : </p> <ul> <li>save person : only email can be changed but you can display id</li> <li>create person : email, name and birthday can be changed</li> </ul> <p>When you send the just edited datas to server, what's the way you proceed ?</p> <p>I see several approaches :</p> <ul> <li>send a Person object. In this case you must take care of data you persist and not only make the person object you received from client to persist mode because a hacker can send data you may not want to be changed (and you can't trust on interface to disabled these changes). In this case, there is several approaches too : <ul> <li>use two functions (save and create), create a new Person object on server (or load the persisted instance via the id if you are in the save method) and copy all fields you want from the client Person object to the persisted one</li> <li>use one function (saveOrCreate) and check if id exists. It is equivalent to the above approach by merging the two functions in one with a big "if"</li> </ul></li> <li>send datas to the server (email, birthday, name, id (in case of edit)). When you do that, create a new Person object (or load the persisted one) and copy datas to this persisted instance.</li> </ul> <p>To summary you have one of the following method signature (just for edit case):</p> <ul> <li><code>Person savePerson(Person person);</code></li> <li><code>Person savePerson(String id, String email);</code></li> </ul> <p>I see pros and cons for each approach. For example the first allow quick change on the Person model without modifying all savePerson calls. But it is less readable than the second approach to know what is really saved.</p> <p>I don't know what is the best one and if you know another way to do that. So, how do you do ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload