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

    actionListener on a4j:commandLink not called

    Jay Haley Newbie

      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);
      }