-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
using the form attribute (proxy objects) is it possible to retrieve the original object which has been proxied in the validator class?
Example:
public class CustomValidator extends AbstractValidator {
@Override
public void validate(ValidationContext ctx) {
MyObj proxy = (MyObj) ctx.getBindContext().getValidatorArg("proxy");
// get original object from proxy
}
}
I didn't find the ProxyHelper class useful.
Thanks
Hey there,
If you are retrieving a FormProxyObject, you can do getOriginObject() on it to retrieve the real bean that was proxied as form binding. (using ctx.getProperty to retrieve the currently modified object, which is the same result as passing it as a validator argument in your original sample)
((org.zkoss.bind.proxy.FormProxyObject)ctx.getProperty().getBase()).getOriginObject()
If you are using form proxy, I'd suggest being careful when you edit the original object while a proxy exist. You may overwrite changes when the proxy is written back to the origin.
Asked: 2022-09-13 16:13:16 +0800
Seen: 11 times
Last updated: Sep 15 '22