I think I've found a workaround.
A key of it is to ignore validation after entity was deleted in another context.
To do that you need implement some interface in proxies which can be deleted.
something like:
public interface IgnoreValidator
{
boolean isIgnore();
void setIgnore(boolean ignore);
}
and after delete operation set to all unfrozen beans setIgnore(true)
something like this:
void delete(final List<ENTITY> list)
{
List<ENTITY> toDelete = new ArrayList<>();
for(ENTITY entity : list)
{
if (entity.wasSaved())
{
// send to server only saved entities
// no need to delete unsaved
toDelete.add(entity);
}
}
RequestContext request = getNewRequestContext();
request.delete(toDelete).fire(new Receiver<Void>()
{
@Override
public void onSuccess(Void response)
{
// set ignore validation to all unfrozen beans
for(ENTITY e : list)
{
if (e instanceof IgnoreValidator)
{
AutoBean<ENTITY> bean = AutoBeanUtils.getAutoBean(e);
if (!bean.isFrozen())
{
((IgnoreValidator)e).setIgnore(true);
}
}
}
}
});
}
Also you need to replace default validator by your validator.
Just create 3 classes:
ValidationProvider:
MyValidationProvider which extends HibernateValidator
ValidatorFactory:
ValidatorFactoryDecorator implements ValidatorFactory
Validator:
ValidatorDecorator implements Validator
Your MyValidationProvider must create your ValidatorFactoryDecorator which accepts super.buildValidatorFactory(configurationState) as delegate.
Your ValidatorFactoryDecorator must return ValidatorDecorator which accepts delegate.getValidator() as delegate.
Your validator must decorate default validator and dispatch all method calls to default validator expect method validate.
this method may be implemented something like this:
@Override
public <T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups)
{
if (object instanceof IgnoreValidator)
{
IgnoreValidator deletable = (IgnoreValidator)object;
if (deletable.isIgnore())
{
return Collections.emptySet();
}
}
return delegate.validate(object, groups);
}
thus you will not perform validation those objects that do not need to be validated
do not forget add
META-INF/validation.xml
and
META-INF/services/javax.validation.spi.ValidationProvider
META-INF must be in
ROOT
|_META-INF -- don't put validation.xml here
|_WEB-INF
|__ classes
|_META-INF
|__validation.xml
in META-INF/services/javax.validation.spi.ValidationProvider just add one line - full name of your MyValidationProvider
After you had implemented this.
You will be able to edit proxy A and proxies B in one RequestContext.
and safety delete proxies B in another RequestContext.
After you had fired delete request your B proxies will be marked to ignore validation.
and you can fire save request for A proxy.
I've checked this workaround.
It's seems worked.
Can someone can point any invisible problems of this solution?