binding expression error

Hi All,

I want to do an interesting thing and up to now did not find any solution to solve it.

I want to set the focus property of an element.
Given a simple image object with a clientside click event setfocusitem(‘elementid’);

There is a script block on page to handle this click event.
Here is my javascript code:


function setfocusitem(item){
	setTimeout(function() {   
		var elem = CAF.model("#{activePageBean.clientIds['"+item+"']}");  
		elem.setFocused(true);
	}, 1000);
}

It gets binding expression error.
My question is that, how to concatenate the correct expression string in javascript.
I want to use this javascript function from page, from more controls with different parameter, so it means the parameter ‘elementid’ is always different.

Many thanks for your help.

Zsolt

Resolving expressions is a server-side operation. So you can’t do the same logic from the client-side javascript.

So you would either have to always pass the fully qualified controlId to the setfocusitem function and then to the logic like below:

function setfocusitem(item) {
	setTimeout(function() {   
		var elem = CAF.model(item);  
		elem.setFocused(true);
	}, 1000);
}

Or concat the relative part of the id to an ancestor that was resolved on the server-side with something like this:

function setfocusitem(item){
	setTimeout(function() {   
		var elem = CAF.model("#{caf:cid('defaultForm')}" + ":" + item);  
		elem.setFocused(true);
	}, 1000);
}
1 Like

Hi Eric,

Thanks for your answer.
I use the fully qualified controlId, and your first suggestion is working well.

Many thanks and have a nice day.

Zsolt