3

I ran into a very interesting issue. Here is my scenario:

My Goal

  • Use a SelectManyCheckbox with a nested tooltip.
  • Use SelectManyCheckbox onHide event to fire an Ajax (ActionListener) call and update the
  • SelectManyCheckbox label and nested tooltip text.

My Approach

  • Use a remoteCommand and tie it to the SelectManyCheckbox onHide event

XHTML

<p:selectCheckboxMenu id="sourceFilter"
                onHide="sourceFilterCommand();"
                value="#{viewRevenueBean.sourceSelectManyMenu.selectedValues}" 
                label="#{viewRevenueBean.sourceSelectManyMenu.label}"
                filter="true" filterMatchMode="contains"
                validator="#{viewRevenueBean.sourceSelectManyMenu.validate}"
                widgetVar="srcFilterDropDown">
                <f:selectItems id="sourceItems"
                              value="#{viewRevenueBean.sourceSelectManyMenu.availableItems}" 
                              var="source" itemLabel="#{source.label}" itemValue="#{source.value}" />
                <f:convertNumber type="number" />
                                    <p:tooltip id="srcToolTip" 
                                for="sourceFilter" 
                        value="#{viewRevenueBean.sourceSelectManyMenu.tooltipText}" 
                        showEffect="fade" 
                            hideEffect="fade"/>
                <p:remoteCommand name="sourceFilterCommand" update="sourceFilter"
                    actionListener=#{viewRevenueBean.sourceSelectManyMenu.defaultEventHandler}"/>       
</p:selectCheckboxMenu>

My Results

  • Ajax (Action Listener) gets fired and SelectManyCheckbox label and nested tooltip are updated (expected behavior).
  • In Firebug, I noticed that each onHide event Ajax call is multiplying the preceding number of server side requests by two (unexpected behavior).

e.g

1st onHide event  = 1 Request
2nd onHide event  = 2 Requests
3rd onHide event  = 4 Requests  
4th onHide event  = 8 Requests  
5th onHide event  = 16 Requests

etc.....

This is obviously not desired and leads to a big slow down after just a couple onHide events.

Experiments I tried

  • I created a p:command button which accomplished the desired Ajax call and correct element updates (without the multiplied request issue) . I then proceeded to steal it's Ajax JavaScript call via Firebug and placed it in my own JavaScript function, which I then used as my onHide callback. Again, I experience the same unwanted result, the label and tooltip are updated, but the requests start to multiply.

  • I tried placing the remoteCommand in different locations (outside the menu, inside it's own form etc). It doesn't make a difference. The problem is still encountered.

  • I tried simplifying the SelectManyCheckbox scenario (remove tooltip, coverter, tweak various attributes etc) to eliminate other possibilities. No difference.

  • I tried a p:ajax instead of p:remoteCommand using onchange. The Ajax requests work fine but obviously it's not what I am after. I need to trigger it onHide.

  • Instead of a SelectCheckboxMenu , i tried using a SelectManyCheckbox (no label) with onchange and keeping everything else the same. The remoteCommand works fine, the Ajax call gets called once and everything is nice and dandy. [/list] [list] * I tried the PrimeFaces 3.5-SNAPSHOT as well. No difference. Issue is still manifested.

    Haven't found any clues on the forum or the net thus far in regards to this issue. Does this sound like a bug or programmer clumsiness :roll: ? Of course any insight and/or suggestions are highly appreciated.

4

1 回答 1

0

我在使用 p:remoteCommand 时遇到了类似的问题。我不能肯定地说根本原因在您的情况下是相同的,但这也许会有所帮助。

在我的情况下,问题是由 jquery 绑定的多次注册引起的;p:remoteCommand 似乎不使用 $(somesource).off("some_event").on("some_event", some_function)。这意味着 - 据我所知 - 如果您更新包含 p:remoteCommand 的组件,则每次更新时都会一遍又一遍地注册它的操作。这反过来意味着,如果您调用 p:remoteCommand 的名称,它将触发与注册时相同的次数。

你说你试图把它移到外面,仍然遇到同样的问题,所以也许这毕竟不是这个问题。在我的例子中,我使用 ap:commandLink 测试了这个假设,并调用了支持 bean。我的目标是确保删除任何以前的绑定注册,因此通过像上面提到的那样注册绑定:

$(somesource).off("some_event").on("some_event", some_function),然后让some_function点击链接,至少可以检查一下是否解决了问题。

于 2013-01-22T13:33:57.933 回答