How to edit an entity in google sitebricks is the correct way. Now I did it like this.
@Show("/WEB-INF/templates/adm/editentry.html")
@Decorated
@At("/adm/entry/:id")
public class EditEntry extends AdminLayout {
@Inject
private EntryService entryService;
private Entry entry = new Entry();
public Entry getEntry() {
return entry;
}
public void setEntry(Entry entry) {
this.entry = entry;
}
@Get
public void getForm(@Named("id") String id) {
this.entry = entryService.get(id);
}
@Post
public String save() {
Entry exist = entryService.get(entry.getId());
if (exist == null) {
FlashMap.setErrorMessage("No entry found with id:" + entry.getId());
} else {
if (StringUtils.isBlank(entry.getExcerpt())) {
entry.setExcerpt(entry.getContent());
}
entry.setBlog(exist.getBlog());
entry.setType(exist.getType());
entry.setStatus(exist.getStatus());
entry.setAuthor(exist.getAuthor());
entryService.saveOrUpdate(entry);
}
return request.getContextPath() + "/adm/entries";
}
}
At the POST method I load a exist entry from database,then set the not modified fields back into the entry from the form binding. then do a update to the database.
Is this the correct way in sitebrciks? Is there a way for just update entry in save method just like the entry create way. thanks.