Some time ago I blogged on how to set focus on a component after an Ajax request in RichFaces. As a quick review, every tag that fires an Ajax request has focus attribute which points to the id of the component on which to set focus after the request. It works fine but only for simple tags such as from h: tag library. When you start using components from rich: tag library such as rich:calendar, there are several focusable elements which are rendered and the above approach won’t work.
There is a workaround, let’s take rich:calendar as an example.
...
The above won’t set the focus because of the problem I described. Using Firebug we can find the input field that was rendered and its id. Here is the rendered HTML:
We can now see that client id of the input field is j_id2:calInputDate. form is the form id, cal is calendar id and then InputDate is appended as well. So, we would have use form:calInputDate as the client id in focus.
...
Another and better option is to use #{rich:clientId}, one of the built-in JavaScript functions in RichFaces:
...
This way we don’t have to worry about the form id.
You can always view all RichFaces components by going to RichFaces Components Demo.
Leave a reply to Poner el foco en un control con RichFaces « Compartir el conocimiento – Esteban de Ortúzar Cancel reply