0

Original object from proxy

asked 2022-09-13 16:13:16 +0800

aUser gravatar image aUser
137 1 4

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

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-09-15 18:57:39 +0800

MDuchemin gravatar image MDuchemin
2298 1 5
ZK Team

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.

link publish delete flag offensive edit

Comments

Thank you!

aUser ( 2022-09-20 18:45:54 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2022-09-13 16:13:16 +0800

Seen: 11 times

Last updated: Sep 15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More