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
[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.