p:textEditor and p:editor: how listen continuously for value change and focus change

UI Components for JSF
Post Reply
webel
Posts: 87
Joined: 18 Sep 2010, 09:29
Location: Sydney, Australia
Contact:

21 Jul 2017, 04:57

Related post: onchange missing, other solutions?

I have multiple requirements, which I'd prefer to address without client-side JavaScript gymnastics (i.e. purely with Java backing bean listeners).

R1. I need to be able to display continuously the current character count (vs. max allowed characters) below a p:textEditor or p:editor field (which p:inputTextarea offers nicely out-of-the-box).

R2. I need to be able to alert users to the fact that they have not saved changes (so I need to detect blur and focus events). One reason for this is that the editors are being used inside a composite component that in turn may be used many times inside a p:tab and p:accordionPanel with many other form fields and button. Each encapsulated editor has its own Save button. A user might close a tab/accordion or move to another tab/accordion without saving, so I want a running warning message that the value has changed and has not been saved, and I want to growl users if they move away from the form field without saving changes.

My first issue is that the valueChangeListener of p:editor and p:textEditor only seems to fire when I Save the changed value with p:commandButton that processes the editor. Neither p:editor nor p:textEditor seem to support p:ajax listeners:

Code: Select all

Unable to attach behavior to non-ClientBehaviorHolder parent
(This also means I can't just listen to 'focus' and 'blur' events.)

[I tried pe:ckEditor, which does permit p:ajax listening, but it has multiple other issues. For example, on catching the indeed continuous value change via p:ajax the value obtained form the UIinput source is always one character behind the actual input, breaking R1 (continuous character count).
It also does not seem to offer PrimeFaces Core style API ops that work with widgetVar such as clear(). And it does not seem to work with p:resetInput.
It does however enable detection of 'blur' and 'focus'.]

In any case, I would like to know how with p:textEditor and p:editor:

- Continuously catch value changes and process them in backing bean listeners.

- Catch when users leave the editor field without having saved changes.

- Catch when users close a tab containing an editor without having saved changes.
Primefaces 6.1
JSF Mojarra 2.3.0
(Netbeans 8.2+Glassfish 4.1.1 OR Payara 4.1)
Mac OS X "Yosemite" 10.10.5 / Linux CentOS 6.7

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 38 guests