# Try to update the content of component A from another component B

reamer
1

Hi Support Team: I have a screen which is composed by more than one components. Each component is defined in a .zul file and with its own ViewModel class. Now, I want to update a field value of component A from component B when I triggered a command of button in component B. Because, component A and B are both the sub component of the screen. So, the global-command does not work.(Global command can only work from sub component and defined in parent component, am i right?)

delete retag edit

Sort by » oldest newest most voted

MDuchemin
2295 1 6

Hey there.

Could you make a small mockup of your current state in ZK fiddle? You are mentioning viewModels and commands, so I assume you are working in MVVM?

There are a few options you can consider. For example, you can use reference binding @ref to pass an object reference to both components, and trigger updates on that.

If you need to do a lot of redrawing when that value change, you can force an <apply> property update to redraw the content of that block entirely.

You can have your component send events, use that event to send commands to the page's parent VM, and update the value from the VM to the other component with notifyChange

You can use eventQueues to post messages between the different VMs of your application.

All of these have advantages and drawbacks. If you can post a short sample, it would be easier to recommend one method specifically.

reamer
1

[hide preview]