0

>>org.zkoss.zk.ui.UiException: Cannot find the specified databind bean expression

asked 2012-12-11 16:37:10 +0800

srossi gravatar image srossi
55 1

Hi all,
followup from here (where you can find code)
I have a grid built in java with model and databind also set in java, i use a row renderer, where i add beans and bindings
everything works fine(changes in UI are reflected to beans) except when I add a new row on my grid model:
I get an error on the onAfterRender Event, where i call binder.loadAll()

	public void onAfterRender(Event event){
		for(Binding binding : binder.getAllBindings()){
			System.out.println("----> binding: " + binding._expression);
		}
		binder.loadAll()
	}

here's the output (sysout + Exception):
...
----> binding: beanid.pL1
...

ERROR org.zkoss - >>org.zkoss.zk.ui.UiException: Cannot find the specified databind bean expression:beanid.pL1
>> at org.zkoss.zkplus.databind.DataBinder.myGetBeanWithExpression(DataBinder.java:988)

Here's org.zkoss.zkplus.databind.DataBinder.myGetBeanWithExpression

private Object myGetBeanWithExpression(Component comp, String path, boolean registerNode) {
Object bean = null;
	BindingNode currentNode = _pathTree;
	final List nodeids = parseExpression(path, ".");
	final Iterator it = nodeids.iterator();
	if (it != null && it.hasNext()) {
		String nodeid = (String) it.next(); //<----- Here, nodeid is correct (beanid)
		currentNode = currentNode.getKidNode(nodeid);  //<----- no result from .getKidNode(nodeid)
		if (currentNode == null) {
			throw new UiException("Cannot find the specified databind bean expression:" + path);   //<----- I get this Exception
		}
		bean = lookupBean(comp, nodeid);
		if (registerNode) {
			registerBeanNode(bean, currentNode);
		}

So in the binder there is a binding with the correct path, but the binder can't see it.
I suppose there's some initialization method on the binder which is not working.
How i correctly refresh the binder?

Thanks for your attention
Stefano

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2012-12-12 09:05:26 +0800

srossi gravatar image srossi
55 1

I've done some debug on zk and it seems that:
- kidNode of a certain BindingNode are added only in BindingNode class at line 133, method addBinding
- BindingNode.addBinding is called only by DataBinder class, method setupPathTree, at line 844
- method DataBinder.setupPathTree is called only by DataBinder.init() at line 676
- init method is called by every "refresh" like operations, such as loadall, saveall etc
BUT
- init has a condition which prevent re-initialization after first time one of the refresh method is called

	
protected void init() {
		if (!_init) {
			_init = true;

so if I create a new DataBinder, then I add beans and bindings to it, and finally , for example, I call a binder.loadAll(), init condition will be set to true
and if at late time i add a new beans or binding to the same binder, it won't correctly create the new Binding Node.

So I ask to zk developers, is this correct or it's a bug?
how can i add binding to existing databinder without recreating it (i've seen several example where is suggested to re-instantiate a new DataBinder)

Thank you
Stefano

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-11 16:37:10 +0800

Seen: 72 times

Last updated: Dec 12 '12

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