• Post Reply Bookmark Topic Watch Topic
  • New Topic

invoking action when panel loses focus (primefaces)

 
Randy Maddocks
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, is it at all possible to put some kind of listener on a primefaces panel, panelGrid or panelGroup? I need to be able to have it so when a user exits the panel, by pressing the TAB key or clicking outside the panel itself, an action in a backing bean is invoked. I can't attach a listener to any components inside the panel because values can be entered in them in any order - users don't have to enter values based on the component's position or flow within the panel. As far as alternatives, I am thinking even beyond panel - maybe there is some other container I could use that itself holds components like inputText and selectonemenu, and which supports a listener. I am using primefaces 5.0, jsf 2.2 and jdk 1.7. Any ideas or thoughts would be most welcome. My apologies for not including code - I just thought I'd put this question out there first. Thanks you!
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
None of the panel controls - or for that matter the underlying HTML controls used to render them are input controls, and therefore they cannot receive focus, so there's no way to attach an onblur event listener.

Tabbed controls and dialogs have select/deselect/show/hide events, so you can attach events to them. Expandable panels can have events attached to the expand/collapse actions.

A common case is to put an event on an entire page; frequently it will pop up a dialog saying "are you sure you want to exit this page?" However an AJAX event should be possible here as well.

Panels are basically visual (output) controls, so the normal practice in HTML is that they aren't going to have an event identity of their own, the way some desktop GUIs do. If you really wanted to, you could tie onfocus and onblur events to all input controls on the page and fake it, but, as you said, that's not a very pretty solution.
 
Randy Maddocks
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

As always, your reply is very much appreciated. I hadn't considered a dialog popup, that is definitely an option I am going to try! This is the great thing about excellent websites like this one - you can spend hours working on a problem, and when you need a different perspective you know there is a site like this with numerous experts in their own right that we can present our problem to.

I am hoping that the primefaces developers do come out with a panel that has listener capabilities - I think it would be a very useful feature.

Many thanks sir, cheers!
 
Randy Maddocks
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I should revise my note about hoping primefaces developers come out with panels that are capable of supporting listeners - I know you clearly explained that because they are not input controls they cannot receive focus. Let me reword that part of my reply - it would be great if they could find a way around that, and make a panel be able to respond to mouse and key actions. I didn't want it to sound like I hadn't paid attention to that part of your reply!
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the basic panelGrid control can deal with mouse and key events. It just doesn't receive/lose focus.
 
Randy Maddocks
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Understood, thanks again Tim!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!