Menu

Primefaces SelectCheckboxMenu input focus on show

Goal

Primefaces selectCheckboxMenu component having automatic focus on input on show

Description

This recipe will use this suggestion, proposed as a feature improvement for the Primefaces selectCheckboxMenu component. The idea is to allow the filtering input of the component to gain focus automatically when the user clicks the combo to display the options

How to

Basically, all you have to do is add the following Javascript function to any of Javascript files you have for your own application.

The previous Javascript code defines postShow as a function where the filterInput gets the focus when the selectCheckboxMenu gets its onShow event called.

Explanations

The credits of this solution are not mine (they are from the person that proposed the solution, Denis something.. if you get to this link, thank you 🙂 ). Still, due to its usefulness, I decided to create this recipe to document a little bit the proposal and what it achieves.