Hello, I have a primefaces form containing several panels. More specifically (if it helps), in the form there are several panelGrid panels, with several panelGroup sub-panels in each panelGrid. Inside those panelGroup sub-panels are different fields (i.e. inputText, selectOneMenu, etc...). A user can make a change to any one of those fields in the sub-panel, but not necessarily the first field in the sub-panel. So, I need to "listen" for changes on any one of those fields, to determine if that particular sub-panel has activity going on.
Currently, I have a listener only on the first field (presuming that users will enter a value starting with that field, in most instances). But I'd like to be able to have it so a change event is fired should the user change any of the other fields first. What I am trying to say in a round-about way is that I have no control over which field the user changes first, but there is validation that happens when changes are made. The current method of having a listener on the first field appears to work, but as described, there is no guarantee that that will happen every time.
My apologies for not including code...here is the basic structure of the form:
My question: Is it risky (or does it even make sense) to have an ajax tag calling the same listener bean, inserted on every field within the sub-panel? I am going to do more searching on this, but thought I would also throw this out there, to get a perspective from others.
I should also note I am fairly new to how the ajax event process works (an on-going learning experience currently). I am consulting some online resources on ajax, but I know this website is an excellent (and trusted) resource.
I am using Eclipse and Primefaces 5.0, with JDK 1.7, running on a JBoss EAP 6.2 server.
You don't call a bean. You call a method. The method is a member of a bean. In this case, it's the onControlPerson1Change() method of foreignParty bean.
You can very definitely share a bean between multiple AJAX callers and you can also share a single method between multiple callers. The Ajax Event that's passed as a parameter to the listener will indicate which control fired the method.
What you are planning sounds a lot like something I often do. In which case, my bean would have a "dirty data" flag and the listener method would set that flag true. So I wouldn't really care which control fired the event, since if even a single value changed, it would mean that the form was "dirty".
A non-AJAX variation of this approach would be to attach a valueChangeListener to each field of interest. Since this is a non-AJAX event, the listener would fire when the command (commandButton or commandLink) for the form was triggered, not when the field changed. Since valueChangeListeners only fire if the value is different when the command triggers, any cases where the user changed something and then changed it back before submitting would not invoke their respective listeners.
"privilege" comes from the Latin words for "private" and "law" (legal) and dates to feudal times. To "claim privilege" meant that you were above the laws that applied to the common people.
posted 3 years ago
Thanks for the clarification on "bean" and "method. Duly noted. :thumbup:
I like the "dirty flag" approach. I will likely try that. Thanks!
Paddy spent all of his days in the O'Furniture back yard with this tiny ad: