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

HI Zsolt,

It is not possible to concatenate the binding expression once it is loaded. The state of binding expression will change to a static element ID.
A binding expression is parsed before they are loaded and only the resultant value is displayed on UI.

Not the best approach, but a workaround to your requirement is as below.

var desiredID = "htmlInputText";
var currButton = 'htmlCommandButton'
var eleStr = "#{activePageBean.clientIds['htmlCommandButton']}";
var dynamicID = eleStr.replace("htmlCommandButton", "htmlInputText")
alert(eleStr);
var ele = document.getElementById(dynamicID); 
alert(ele.value);

Here, once the binding expression is loaded to the neighbouring element, you can update the ID portion of it to point the desired element. This ID string will change depending on the hierarchy on the element position in the CAF screen.