1 Reply Latest reply on Oct 31, 2015 3:15 PM by Arnie Morein

    Ajax not calling listener, opening modal panel anyway.

    Arnie Morein Novice

      I have a bean that displays a list of records on a tab page in a data grid. The last column, Action, contains a rich:dropDownMenu with two actions: Edit and View.

       

      The menus are supposed to execute a method on the list's bean to prepare a variable that will be used by the modal panel's bean to configure itself and read the requisite data; only they are never called and modal panel always appears. So, using another example from here, I altered their construct below. (Note: the okToOpen variable is set elsewhere in the class to false.)

       

      <rich:dropDownMenu label="#{messages.getString('application.lbl.cmdHover')}" >
          <rich:menuItem id="menuInfoPersonCommentEdit"
              actionListener="#{infoPersonCommentList.editListener}"
              execute="@this" mode="ajax"
              data="#{infoPersonCommentList.okToOpen}"
              oncomplete="if (event.data) { #{rich:component('modalInfoPersonCommentEdit')}.show(); } else { alert('not ok to open'); } " 
              label="#{messages.getString('application.lbl.linkEdit')}" 
              render="panelModalInfoPersonCommentEdit" >
              <f:param name="cid" value="#{javax.enterprise.context.conversation.id}" />
          </rich:menuItem>
          <rich:menuItem id="menuInfoPersonCommentView"
              actionListener="#{infoPersonCommentList.viewListener}" 
              execute="@this" mode="ajax"
              label="#{messages.getString('application.lbl.linkView')}"
              data="#{infoPersonCommentList.okToOpen}"
              oncomplete="if (event.data) { #{rich:component('modalInfoPersonCommentEdit')}.show(); } else { alert('not ok to open'); } " 
              render="panelModalInfoPersonCommentEdit" >
              <f:param name="cid" value="#{javax.enterprise.context.conversation.id}" />
          </rich:menuItem>
      </rich:dropDownMenu>
      
      

       

      So now, all I get is the alert, and no logging from the bean that it was called (break points confirm no calls). The bean methods are pretty simple:

       

      public void editListener(ActionEvent event) {
          okToOpen = false;
          InfoPersonCommentDTO dto = getDataModel().getRowData();
          if ( dto != null ) {
              infoPersonCommentDTOEdit.setBaseActionPageModeEnum(BaseActionPageModeEnum.EDIT);
              infoPersonCommentDTOEdit.setObjectId(dto.getId());
              infoPersonCommentDTOEdit.setReadOnly(Boolean.FALSE);
              infoPersonCommentDTOEdit.setDoResetForWork(Boolean.TRUE);
              okToOpen = true;
          }
      }
      
      

       

      The values in infoPersonCommentDTOEdit are then produced (CDI) from this bean for injection into the bean that manages the modal panel, which isn't called either when the modal panel opens.

       

      Which bring up the next topic which -may- be related. I want the focus put into a field when the modal panel opens and in order to initialize the panel, I use an f:event on the preRenderView method of the modal panel bean to trigger the initialization. This kind of set up works fine with page A to page B event handling using h:commandButtons and JSF navigations. But things just aren't happening when ajax gets enabled and I have no idea why.

        • 1. Re: Ajax not calling listener, opening modal panel anyway.
          Arnie Morein Novice

          I have confirmed via logging that the preRenderView method is being called before the modal panel appears - IF - the list bean's listener method actually gets called.

           

          If I repeatedly select edit or view from the menu, it is mostly failure. On a hunch, I ui:removed the menu and put in plain a4j:commandLinks - and oh Look: it works correctly, every time!

           

          UGH. So, that made me remember about rich:contextMenu, so I replaced the rich:dropDownMenu and used the click event - works as desired; with the exception of the hover effect of the dropDownMenu. I tried showEvent="hover" and nothing happens. I tried targeting it to an outputLabel and using "onmouseover" and again nothing happens.

           

          So that fixes the weird menu behavior though the allowed interface isn't what was desired.