set focus?

hot to set focus will be done after a server round trip…if no error

thanks!

PD: don´t work on load of the page with below code in a script block

Is it possible by setting from java?

If the control that is being refreshed by your round trip is a form control or one of the hideable panel controls, then you could try setting the value of the ‘Default Focus’ property of the panel/form control to the id of the input control that you want to have focus after the refresh has completed.

Otherwise you should be able to set the focus progammatically from a script from an action complete listener that is attached to the command control that did the action. For example, something like this in a script block that is outside the control being refreshed:

//declare the custom function and store it on the window object
window.doCustomFocusFn = function(){ 
    CAF.model("#{activePageBean.clientIds['htmlSelectOneMenu1']}").setFocused(true);
} 

//remove the previous reference just in case, so we don't get duplicates
CAF.model("#{activePageBean.clientIds['button']}").removeActionCompleteListener(window.doCustomFocusFn); 

//add a reference to the custom listener
CAF.model("#{activePageBean.clientIds['button']}").addActionCompleteListener(window.doCustomFocusFn); 
1 Like

How I can set ‘Default Focus’ property of the form from java? with control accessor?

or Javascript??

I have multiples dropdows on my screen, all run some action in onChange. I need the focus set dynamically in the dropdow which was executed

You can set the value from the property of the form control in the view editor.

yes, i see this. But ¿ how i can set this value with ID of dropdown the customer changed? considering that are multiple in task

The value can be an expression.

So you can make it dynamic by:

  • add a string field to you page java class.
  • Update the value of that field when appropriate.
  • Bind the ‘Default Focus’ property value to an expression that resolves to your custom string field.

Though, I haven’t verified this, but if the value is changing in the middle of refreshing a control, you might need to use the script approach instead, since this information would probably need to be known on the client side before the action/refresh starts.

Another possibility is to do what you were originally doing in a script block after a short delay.

For example:

setTimeout(function() { 
CAF.model("#{activePageBean.clientIds['htmlSelectOneMenu1']}").setFocused(true);
}, 100);