0

Attach PhaseListener to specific Component?

asked 2018-11-26 19:24:30 +0800

tisaksen gravatar image tisaksen
46 6

Hi

I'm simply wondering if there is any way to attach a PhaseListener to a specific component? It's a little tedious to handle "everything" within the same PhaseListener.

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2018-11-28 10:02:57 +0800

cor3000 gravatar image cor3000
6280 2 7

since ZK 8 you can add additional phase listeners via BinderCtrl#addPhaseListener(PhaseListener)

If you want to make it component specific you can pass the component as a constructor arg e.g.:

@Init
public void init(
        @ContextParam(ContextType.BINDER) BinderCtrl binderCtrl, 
        @ContextParam(ContextType.VIEW) Component view ) {
    binderCtrl.addPhaseListener(new MyPhaseListener(view));
}

Based on the information you provided so far I can't tell if that's helpful for your case. Since I almost never had to add a PhaseListener myself I could imagine there's an alternative that doesn't require changing the internals.

link publish delete flag offensive edit
0

answered 2018-11-29 21:20:02 +0800

tisaksen gravatar image tisaksen
46 6

The idea was to "intercept" the binding process to create the bound object (myObject) on demand but I don't know if this is possible.

<textbox value="@bind(vm.myObject.myProperty)"/>

Then in the PhaseListener do proper setup of "myObject" in prePhase:

public void prePhase(Phase phase, BindContext bindContext) {
    //if phase is INITIAL_BIND(not sure which phase it would be in this case) then create myObject etc..
}

Another idea is to intercept the validation phase to get immediate single field validation without executing the command, just like "save before command" but without executing the commmand if validation fails. This is to avoid numerous error messages at once.

http://books.zkoss.org/zk-mvvm-book/8.0/data_binding/validator.html

link publish delete flag offensive edit

Comments

you have a very special scenario here ... I would be surprised if anyone in the forum has ever done something similar. I haven't encountered this scenario myself. I suggest asking ZK support directly if this is urgent.

cor3000 ( 2018-11-30 12:30:56 +0800 )edit

You're probably right, I will contact support to check out my options. Thank you :-)

tisaksen ( 2018-11-30 15:10:21 +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
2 followers

RSS

Stats

Asked: 2018-11-26 19:24:30 +0800

Seen: 7 times

Last updated: Nov 29 '18

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