Primefaces slider <p:slider>: detect sliding - ajax

Is it possible to detect the event "while sliding" in a primefaces slider?
I have a poll (every 3 seconds the sliders are updated) to update the sliders' values (as multiple clients can use the slide).
When I am sliding and a periodic ajax call is made (by <p:poll>), the slider returns to its initial position. This behavior is understandable, because the form itself is refreshed.
I need to avoid this: when I'm sliding, I want the poll to stop. When I stop sliding the ajax event "slideEnd" is called. In this event, I would return the poll refresh process normally.
Is this possible? What would I need?
Edit: I found out about onSlide and onSlideStart attributes of <p:slider>. I used something like:
<p:slider for="porta2005" minValue="0.0" maxValue="100.0" step="1" styleClass="width-100" onSlide="#{dimmerBean.slideStart()}">
<p:ajax event="slideEnd" listener="#{dimmerBean.mudaTensao2005}" update="tensao2005"/>
</p:slider>
But the method slideStart() is called on every poll request inside bean, not only when I effectively slide. Is it wrong to call a bean method inside onSlide like this?
I am using Primefaces 6.1.

The onSlide, onSlideStart, and onSlideEnd are client side callbacks. So if a backing bean method is put in these attributes, it will be called during render, and not during the actual event.
From the documentation:
Name Default Type Description
onSlide null String Client side callback to execute during sliding.
And a little below this:
Client Side Callbacks
Slider provides three callbacks to hook-in your custom javascript, onSlideStart, onSlide and
onSlideEnd. All of these callbacks receive two parameters; slide event and the ui object containing
information about the event.
You can stop polling by using the poll widget functions. Suppose your p:poll has a widgetVar attribute as myPoll, you can pause it during sliding as shown.
<p:slider for="porta2005" minValue="0.0" maxValue="100.0" step="1" styleClass="width-100"
onSlideStart="PF('myPoll').stop()" onSlideEnd="PF('myPoll').start()">

Related

Text in CKEDITOR field not being submitted in the first submission

The text in ckeditor field is not sent when submitting forms for the first time (only on the second time, third time, etc).
For example, If try to create an article's post and submit the form I'll get a validation error: 'The field body is required'. If try to submit again (for the second time or third time), It will work well.
The real problem is when editing! For example, when editing a form the field 'body', among others fields, is filled out with the data from the database. In other words, there are already text in the ckeditor field.
If I try to submit the form for the first time it will not update the body because the text in the ckeditor is not sent; what is sent is the default value (the old article's body, which was filled out with data from the DB).
Therefore, it won't edit unless I get a validation error in other field (if I get a validation error, I'll have to submit again, and that will work).
How to solve this problem? Is this an known bug in CKEDITOR 4? If I don't solve it the users will feel frustrated if they have to submit the form at least twice to edit or to create an article.
Here is a list of plugins I'm using (may be useful to solve the problem):
a11yhelp, about, api, autocomplete, autocorrect, browser, clipboard, colordialog, copyformatting, crossereference, dialog, div, docprops, find, googlesearch, image, link, liststyle, magicline, mathjax, openlink, pastecode, pastefromword, preview, quicktable, scayt, section, showblocks, sourcedialog, specialchar, table, tableselection, tabletools, tabletoolstoolbar, texttransform, widget, wsc
By the way, I downloaded ckeditor using ckeditor builder in their official website.
I opened this issue in GitHub and a guy figured out the problem. His proposed solution worked wel!! Here is what he said:
Workaround
As the issue is more tricky to fix than it seems, for now I propose a
simple workaround: invoke ajaxRequest not on $( document ).ready,
but rather on editor's loaded event:
CKEDITOR.replace( 'editor', {
on: {
loaded: function() {ajaxRequest();}
}
});
Explanation of the issue
The issue is connected with how DOM listeners are registered for given
element:
The order of event listeners for a particular event type will always
be:
The event listeners registered with addEventListener() before the first time the event handler's value was set to non-null
Then the callback to which it is currently set, if any
Finally, the event listeners registered with addEventListener() after the first time the event handler's value was set to non-null.
In case of CKEditor 4, the value of the form's element is modified by
editor._attachToForm private method, which adds event listener to
form's submit event:
ckeditor-dev/core/editor.js form.on( 'submit', onSubmit );
However this listener is added on loaded event, which is fired
asynchronously when editor is loaded – so after registering
synchronous onsubmit handler with the validation logic. This way
editor's field is updated after validating.
Proposed solutions
Update editor's element on formdata event. This way we would have
total control over data being submitted and we would be sure that
correct data is set before submit event. The problem with this
solution is the fact that browsers' support is non-existent; the event
will appear in Chrome 77, however it is still not known if and when
the support will appear in Firefox or Safari.
Update editor's element on every change in the editor's content thanks
to change event. This solution will also fix cases, where some other
scripts are using value not from the editor, but directly from the
replaced textarea – they would get fresh data more often then only
after submitting the form. However this solution requires #1364, which
connects with a pretty big refactoring.
NOTE: AjaxRequest is the function I was using to submit the form togehter with Jquery.

Why do the xforms-select and xforms-deselect elements bubble?

According to the XForms specification most events are said to "bubble".
As per the DOM Level 2 Event Specification an event that "bubbles" means that the handlers for this event associated with ancestor elements of the event dispatch target will also receive this event.
For an event to be specified as "bubbles" it means the xf:dispatch action cannot modify the bubble behavior to limit it to the target.
I don't understand what the benefit is of so many xforms events to bubble. For example, xforms-select and xforms-deselect. They apply to xf:item (of xf:select*) and xf:case (of xf:switch, i.e., used in a form with tabs).
Let's say I have an xf:case with an xforms-select handler that will cause a refresh on an expensive rendering widget, just when the tab is actually selected rather than every time the model is updated. Now I also have an xf:select in that same tab. Now whenever the user selects another item in that selection, the xf:case would receive the xforms-select at the bubble phase, doing the costly update operation every time.
This doesn't seem to make sense.
In fact xforms-node-attached has it right: we really want to be specific as to which form element gets the node attached. But apart from that, most events are said to bubble.
I could conform myself better with this issue if I understood the reason for this. Otherwise I am tempted to change my XForms engine to change the definition of xforms-select and xforms-deselect not to bubble.
This is to allow what is known as event delegation:
"Event delegation refers to the process of using event propagation (bubbling) to handle events at a higher level in the DOM than the element on which the event originated. It allows us to attach a single event listener for elements that exist now or in the future." (from an older version of this jQuery doc page)
In general, this is a good thing:
You use less event listeners.
A listener can listen on multiple targets.
You don't need to remove/add listeners as DOM elements are added/removed.
It seems that, in the HTML world, things have moved towards letting everything bubble. For example, the old focus event didn't bubble, and the newer focusin event bubbles.
If you have an event handler which gets activated by events dispatched to multiple targets, in some cases you need the ability to discriminate. This is where event context information is useful. Libraries like jQuery also allow you to associate an event handler filtered by CSS selector, which is neat.
Now in the case of xforms-select specifically, your issue is that you cannot discriminate between this event dispatched to an xf:case vs. an xf:select. This might mean XForms shouldn't have a single event for these two scenarios, or it should have enough event context information to discriminate between the two. I don't think that this is making a case for not letting the event bubble.

Extjs4: beforeshow vs afterrender

What is difference between beforeshow and afrerrender events of extjs components.
Also can I get reference to any document which describes the order in which extjs events fire (or which describes steps which happen before the component is displayed on screen) ?
beforeShow listener is triggered only when you are toggling an extjs component using show()
afterRender is triggered for every extjs component after it has been rendered
Rendering happens before a show; it only makes sense that a component must already be rendered before it can be shown or hidden etc...
I don't know of any great documentation on extJS event occurrences/flow. This thread is about as good as I've seen: Explain ExtJS 4 event handling

Richfaces prohibit event by passing by user

I have a text box and value change listener on it. And there is a save button. The user avoids/bypasses value change listener by directly editing text box value in html code and then saves it. How can i prohibit the user, so that he/she is not able to change value this way? And thus make sure that value change listener is always called.
I am looking for some generic mechanism to stop such cases on all inputs/and event listeners.
Thanks
You need to accept that the user can actually do EVERYTHING he wants with his client (the browser). He can disable Javascript, remove inputs completely, change validation or call Ajax functionality manually. He might not even use a browser and send an HTTP request using a command line tool.
It is just impossible to prohibit such things.
On the other hand I think that in case you use a valueChangeListener on your h:inputText, then it should be called in any case, because it will be evaluated serverside. It might be that you edited it the wrong way and the value actually doesn't change when you save the content of the form. (Check that the value really gets set by adding a breakpoint to your setter).
If you use Ajax functionality using <f:ajax> with event="change" and a listener, then there is no way to prevent bypassing it by manually editing the html. Either check for the changed value in your save method, or use the valueChangeListener instead.

Is it possible to have multiple actions for the action attribute of h:commandLink?

Is it possible to have multiple actions for the action attribute of h:commandLink tag? I want to perform two actions while clicking on the link rendered by h:commandLink tag. An action needs to be performed in a Spring bean, and a pop up window displaying a certain webpage.
No, it is not possible to call two methods in action attribute. And I don't think this is major disadvantage. Encapsulate logic in one method in managed bean, and call those to actions from that method.
No, it's not possible to have multiple actions in a commandLink action. If you want to perform some logic and to display a pop up window just wrap your logic in a single method, and at the bottom add a FacesMessage to the the context. You can do an AJAX partial refresh of the h:messages component to show the message as a "pop up" without reloading the page.

Resources