1

First of all, Thanks a lot all of you for your continuous support.

I have a problem releated .xhtml and 'f:ajax'.

I am setting richfaces:collapsiblepanel 'expanded' attribute by bean variable which is default collapsed and on blur event it gets expanded. I want to set focus a UIComponent after f:ajax request compeleted. And for that I have written a function in javascript and called it in 'onevent' of f:ajax.

But onevent function fires before panel open and I can not able to set focus on UIComponent which are define in that collapsible panel.

How can I setFocus or How can I fire that function after ajax request compeleted ?

Thanks in advance.

Rong Nguyen
  • 4,143
  • 5
  • 27
  • 53
Kevin Shah
  • 43
  • 1
  • 5

1 Answers1

3

Your js function should look like this

function doTheFocus(data) {
    if (data.status === 'success') {
        //here goes the js code that will set the focus
        //this code will be executed only when the ajax will be done
    }
}

And here is how your f:ajax will look like

<f:ajax onevent="doTheFocus" />

If you want to call the js function of the focus when the panel is opened you can try

<rich:collapsiblePanel onswitch="doTheFocus"

or (I'm not sure...)

<rich:collapsiblePanel onswitch="doTheFocus()"

If you eventually will use the onswitch , you might be needed to add some logic inside doTheFocus function to check if the panel is expanded or not...

Daniel
  • 36,833
  • 10
  • 119
  • 200
  • On more thing.. I am generating dynamic richfaces:collapsible panel.I am using h:commandbutton to fire action for generating panel. So How to set focus to new generated richfaces:collapsible panel. As initially for 'f:ajax' I am not able to get id for 'render' element. – Kevin Shah Apr 24 '13 at 05:54
  • you can create your *dynamic richfaces:collapsible panel* inside some wrapper with a known id, and point the `f:ajax` to render that already known wrapper... – Daniel Apr 24 '13 at 06:06
  • Yes I have done that. I have wrapped the – Kevin Shah Apr 24 '13 at 06:17