Foren
ServiceBuilder Selective update
Corné Aussems, geändert vor 13 Jahren.
ServiceBuilder Selective update
Liferay Legend Beiträge: 1313 Beitrittsdatum: 03.10.06 Neueste Beiträge
Im used to having a selective update on my interface;
ie; only update the fields that are not NULL
I would like to re-use the ModelImpl as a TransferObject,
I know it is a horror to some, but i'm a lazy sob
Is it possible to implement something easier than this ?
ie; only update the fields that are not NULL
I would like to re-use the ModelImpl as a TransferObject,
I know it is a horror to some, but i'm a lazy sob
Is it possible to implement something easier than this ?
public Product updateProduct(final Product updateOnProduct) throws SystemException {
Product persistentProduct = productPersistence.fetchByPrimaryKey(updateOnProduct.getPrimaryKey());
// sadly this copies the null values over so i need my own copieer
BeanPropertiesUtil.copyProperties(updateOnProduct,persistentProduct );
persitentProduct .setModifiedDate(DateUtil.newDate());
return productPersistence.update(persistentProduct, false);
}
Pete van de Water, geändert vor 13 Jahren.
RE: ServiceBuilder Selective update
New Member Beiträge: 12 Beitrittsdatum: 18.08.10 Neueste Beiträge
You could pre-populate the DTO so that the values won't be null. Spring will then bind the additional values on top of it. Eg:
@ModelAttribute
Product getProduct(@RequestParam(value = "primaryKey") Long primaryKey){
return productPersistence.fetchByPrimaryKey(primaryKey);
}
@ModelAttribute
Product getProduct(@RequestParam(value = "primaryKey") Long primaryKey){
return productPersistence.fetchByPrimaryKey(primaryKey);
}