0

Tree is backed by a Controller. Need it to visibly reflect change in an underlying object ?

asked 2012-12-19 16:27:24 +0800

rickcr gravatar image rickcr
704 7

I have a Tree that is backed by a Controller.

The Tree is used on a page that is backed by a ViewModel.

The issue is when one of the underlying objects of the tree nodes is modified in the ViewModel, I can't get the reflected change to show up in the UI. (The data is being changed I just can't see it... the label isn't reflecting the change.)

I thought maybe wiring up the Tree in the view model and then doing a notifyChange would do the trick but that doesn't seem to help.

For example I thought this would work...

//ViewModel
@Wire("#cbgTree")
protected Tree cbgTree;

@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) org.zkoss.zk.ui.Component view){
	Selectors.wireComponents(view, this, false);
}

@Command
@NotifyChange({"cbgTree"})
public void updateBuyerGroup() {
             //stuff happens that ends up affecting the underlying objects in the tree
  }

The tree on the page is set up like...

<borderlayout id="bld" apply="com.ncs.ncsapp.web.controller.CBGTreeController" >
	<north height="100%" border="0" >
		<panel height="100%" title="Create Complex Buyergraphics" sclass="highlight">						
			<panelchildren>
				<tree id="cbgTree"  vflex="true" droppable="true"  >
					  <treecols sizable="true">
							<treecol label="Blocks"  width="100%"/>
					  </treecols>	
					  <treechildren id="cbgTreeChildren" droppable="true">
					  </treechildren>
				</tree>
			</panelchildren>

I also tried wiring the "cbgChildren" id in my ViewModel but that didn't work either.

How could I force the tree to "redisplay" if the data backing one of the nodes changes ? (

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2012-12-20 01:26:14 +0800

paowang gravatar image paowang
140 6

updated 2012-12-20 01:27:48 +0800

Can you provide complete code for reproducing?
Normally, we don't suggest mix MVVM and MVC.

link publish delete flag offensive edit

answered 2012-12-20 06:37:54 +0800

rickcr gravatar image rickcr
704 7

@paowan *sigh* this is what is so frustrating. In another thread I talked about how I use a ViewModel for everything and then I got a lot of replies how the ZK team recommends not using a VM for everything. Now, here is a case where I'm not using a ViewModel to support my tree component and you're saying it's not a good approach to have them mixed? I really wish the ZK team would right up some good best practices samples on how and when these should be mixed and how to do effectively.

The Tree is backed by a Controller that is very UI specific .. nodes need to be created based on various conditions (the tree represents a complex boolean editor for example showing (A and B) OR (C and D) .. parenthesis are generated based on things the user drops into the tree, etc.) I definitely don't want all this tree logic stuck in my ViewModel.. .it's a lot of code and is specific to the tree itself.

I could try to come up with an external example but it'll take some time.

Can someone confirm in theory if a tree label should automatically refresh and display correctly in the UI if the tree is used on a zul that is backed by a view model but the tree itself is backed by a SelectorComposer ? Before I work on an example I'd like to know if 'in theory' it should be pretty simple for it to work?

link publish delete flag offensive edit

answered 2012-12-20 10:05:39 +0800

paowang gravatar image paowang
140 6

updated 2012-12-20 10:06:20 +0800

Okay. Now, I understand the complex saturation you met.
Mixing them might be better for such case.
So, this article may help you:
http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/MVVM/Advance/Communication_between_ViewModel_and_Composer

link publish delete flag offensive edit

answered 2012-12-20 15:48:47 +0800

rickcr gravatar image rickcr
704 7

Yes Paowang that is exactly how I'm communicating between the two (Based on that article.)

The issue is I was hoping to get a change reflected visibly in the tree if the underlying data changed. Currently I'm having to call the controller method that rebuilds the whole tree from scratch again. It works, but this doesn't seem ideal.

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2012-12-19 16:27:24 +0800

Seen: 46 times

Last updated: Dec 20 '12

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