6 Replies Latest reply on Sep 11, 2008 6:58 AM by ilya_shaikovsky

    actionListener on a4j:commandLink not called

    jhaley

      Using a binding, I am dynamically building a set of panelBarItems inside of a panelBar. Inside of each panelBar I have a dataTable with a column of a4j:commandLink "Add" links. Visually this is being built properly, but when I click on my any of my "Add" links nothing happens. By nothing I mean my method does not get called and I receive no errors. The add link is mapped an actionEvent called "addArticle", but it never gets called. I'm stuck and am looking for some assistance.

      <a4j:region>
       <rich:panelBar id="availableArticlesPanelBar" height="100%" width="200" binding="#{surveyCtrl.panelBar}" />
      </a4j:region>
      

       /**
       * Programmatically builds the RichFaces PanelBar component.
       *
       * @param panelBar
       */
       public void setPanelBar(HtmlPanelBar panelBar) {
       HtmlPanelBarItem panelBarItem;
       panelBar.getChildren().clear();
       Integer iCount = 0;
      
       List categoriesByRoomTypeList = getCategoriesByRoomType(new Integer(
       this.categoryBasedOn).intValue());
       dynamicLists = new List[categoriesByRoomTypeList.size()];
      
       for (Iterator i = categoriesByRoomTypeList.iterator(); i.hasNext();) {
       CategoryDTO category = (CategoryDTO) i.next();
      
       // create <rich:panelBarItem label="category.getCategoryName()"
       // id=""panelBarItem_" + iCount.toString()" >
       panelBarItem = new HtmlPanelBarItem();
       panelBarItem.setLabel(category.getCategoryName());
       panelBarItem.setId("panelBarItem_" + iCount);
      
       dynamicLists[iCount] = category.getArticles();
      
       // Create <rich:dataTable align="center" width="100%"
       // id=""dynamicLists_" + iCount"
       // onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
       // onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
       // cellpadding="0" cellspacing="0"
       // border="0" var="dynamicItem" value="#{surveyCtrl.dynamicLists[" +
       // iCount + "]}"">
       HtmlDataTable dynamicDataTable = new HtmlDataTable();
       dynamicDataTable.setAlign("center");
       dynamicDataTable.setWidth("100%");
       dynamicDataTable.setId("dynamicLists_" + iCount);
       dynamicDataTable
       .setOnRowMouseOver("this.style.backgroundColor='#F1F1F1'");
       dynamicDataTable
       .setOnRowMouseOut("this.style.backgroundColor='#FFFFFF'");
      
       dynamicDataTable.setCellpadding("0");
       dynamicDataTable.setCellspacing("0");
       dynamicDataTable.setBorder("0");
       dynamicDataTable.setVar("dynamicItem");
       dynamicDataTable.setValueExpression("value", createValueExpression(
       "#{surveyCtrl.dynamicLists[" + iCount + "]}", List.class));
      
       // Create <h:column id="column">.
       HtmlColumn column = new HtmlColumn();
       column.setId("column");
      
       dynamicDataTable.getChildren().add(column);
      
       // <h:panelGrid columns="2" cellpadding="0" cellspacing="0"
       // width="100%"
       // columnClasses="panelGridColumnLeft,panelGridColumnRight" id="">
       HtmlPanelGrid panelGrid = new HtmlPanelGrid();
       panelGrid.setColumns(2);
       panelGrid.setCellpadding("0");
       panelGrid.setCellspacing("0");
       panelGrid.setWidth("100%");
       panelGrid
       .setColumnClasses("panelGridColumnLeft,panelGridColumnRight");
       panelGrid.setId("panelGrid");
      
       column.getChildren().add(panelGrid);
      
       // Create <h:outputText id="articleName_ + iCount"
       // value="#{dynamicItem[" + jCount++; + "]}">
       HtmlOutputText output = new HtmlOutputText();
       output.setId("articleName");
       output.setValueExpression("value", createValueExpression(
       "#{dynamicItem.articleName}", String.class));
      
       panelGrid.getChildren().add(output);
      
       // <a4j:commandLink immediate="true" limitToList="true"
       // ajaxSingle="true" value="#{labels['l.pages.survey.survey.add']}"
       // actionListener="#{surveyCtrl.addArticle}"
       // reRender="scrollableDataTable">
       HtmlAjaxCommandLink ajaxCommandLink = new HtmlAjaxCommandLink();
       ajaxCommandLink.setImmediate(true);
       ajaxCommandLink.setLimitToList(true);
       ajaxCommandLink.setAjaxSingle(true);
       ajaxCommandLink.setId("ajaxCmdLink");
       ajaxCommandLink.setReRender("scrollableDataTable");
       ajaxCommandLink.setValueExpression("value", createValueExpression(
       "#{labels['l.pages.survey.survey.add']}", String.class));
      
       ajaxCommandLink.setActionExpression(createActionExpression(
       "#{surveyCtrl.addArticle}", String.class));
      
       // <f:param name="selected" value="#{row.id}"/>
       UIParameter param = new UIParameter();
       param.setName("selected");
       param.setValueExpression("value", createValueExpression(
       "#{dynamicItem.id}", String.class));
       param.setId("param");
      
       ajaxCommandLink.getChildren().add(param);
      
       panelGrid.getChildren().add(ajaxCommandLink);
      
       // dynamicDataTable.getChildren().add(column);
       panelBarItem.getChildren().add(dynamicDataTable);
      
       panelBar.getChildren().add(panelBarItem);
       iCount++;
       }
      
       this.panelBar = panelBar;
       }
      
      
      
      
       public ValueExpression createValueExpression(String valueExpression, Class<?> valueType) {
       FacesContext facesContext = FacesContext.getCurrentInstance();
       return facesContext.getApplication().getExpressionFactory().createValueExpression(
       facesContext.getELContext(), valueExpression, valueType);
       }
      
      
       public MethodExpression createActionExpression(String actionExpression, Class<?> returnType) {
       FacesContext facesContext = FacesContext.getCurrentInstance();
       return facesContext.getApplication().getExpressionFactory().createMethodExpression(
       facesContext.getELContext(), actionExpression, returnType, new Class[0]);
       }
      
      
      
      public void addArticle(ActionEvent event) {
       System.out.println("@@@@@ addArticle @@@@@");
       String selectedId = (String)getParam("selected");
      
       SelArtlDTO selectedArticle = new SelArtlDTO();
       selectedArticle.setSelArtlName(selectedId);
       quote.getWorkingSelectedRoom().getSelectedArticles().add(selectedArticle);
      }
      


        • 1. Re: actionListener on a4j:commandLink not called
          nbelaevski

          Hi,

          What is RF version?

          • 2. Re: actionListener on a4j:commandLink not called
            jhaley

            I'm using RichFaces 3.2.1. In addition, I've tried this with IE6, FireFox 3 and Safari. It works in none of these browsers and no script errors are reported.

            • 3. Re: actionListener on a4j:commandLink not called
              jhaley

              I've tried using RichFaces 3.2.2. Unfortunately I'm having the same problem. Hope someone can point out what I'm missing.

              • 4. Re: actionListener on a4j:commandLink not called
                stefan.mohr

                Are you doing a reRender on any component on the page? I've been having issues with buttons not working after a reRender but haven't narrowed to down to exactly what tag on what control is misbehaving.

                • 5. Re: actionListener on a4j:commandLink not called
                  jhaley

                  Yes I am doing a reRender. In addition, I solved my problem by not using a binding. Below is my tag-based solution. I'm still curious what was wrong with my initial attempt.

                  <rich:panelBar id="availableArticlesPanelBar" height="100%" width="200" >
                   <c:forEach items="#{surveyCtrl.categoryList}" var="cat">
                   <rich:panelBarItem label="#{cat.categoryName}">
                   <rich:dataTable align="center" width="100%"
                   onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
                   onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
                   cellpadding="0" cellspacing="0"
                   border="0" var="row" value="#{cat.articles}">
                   <h:column>
                   <h:panelGrid columns="2" cellpadding="0" cellspacing="0" width="100%" columnClasses="panelGridColumnLeft,panelGridColumnRight">
                   <h:outputText value="#{row.articleName}"/>
                  
                   <a4j:region>
                   <a4j:commandLink immediate="true" limitToList="true" ajaxSingle="true" value="#{labels['l.pages.survey.survey.add']}" actionListener="#{surveyCtrl.addArticle}" reRender="scrollableDataTable">
                   <f:param name="selected" value="#{row.id}"/>
                   </a4j:commandLink>
                   </a4j:region>
                   </h:panelGrid>
                   </h:column>
                   </rich:dataTable>
                   </rich:panelBarItem>
                   </c:forEach>
                  </rich:panelBar>
                  


                  • 6. Re: actionListener on a4j:commandLink not called
                    ilya_shaikovsky

                    haev you used phase tracker in order to check how the request was went through JSF lifecycle? a4j:log also usefull in this cases in order to check client side updates execution.