2 Replies Latest reply on Nov 6, 2008 10:54 AM by Ahsan Javed

    Unable to reRender programatically using A4J in custom compo

    Ahsan Javed Newbie

      Hi,
      I am new to JSF and stuck with reRender functionality of Ajax4Jsf. I have to write an ajax enabled custom JSF component that contains several simple child components such as text box and selectOneMenu. for the convinience I assume one text box and one combo box. I have to update the content of text box when I change the value in selectOneMenu. but I am unable to do so, Everything is working fine as per JSF life cycle. Here is the code of my encodeBegin method.


      public void encodeBegin(FacesContext context) throws IOException {
       super.encodeBegin(context);
       this.getChildren().clear();
       Application application = FacesContext.getCurrentInstance().getApplication();
      
       HtmlForm htmlForm = new HtmlForm();
       htmlForm.setId("reportConfigureForm");
       this.getChildren().add(htmlForm);
      
       HtmlSelectOneMenu htmlSelectOneMenu = new HtmlSelectOneMenu();
       htmlSelectOneMenu.setId("selectedReportType");
       htmlSelectOneMenu.setStyleClass("dropdown");
       htmlSelectOneMenu.setRequired(true);
      
       ValueBinding valueBinding = application.createValueBinding("#{" + getReportBeanName() + ".selectedReport}");
       htmlSelectOneMenu.setValueBinding("value", valueBinding);
      
       UISelectItems uiSelectItems = new UISelectItems();
       List<SelectItem> selectItems = new ArrayList<SelectItem>();
       for (Map.Entry<String, String> report : getReportBean().getReports().entrySet()) {
       selectItems.add(new SelectItem(report.getKey(), report.getValue()));
       }
       uiSelectItems.setValue(selectItems.toArray(new SelectItem[selectItems.size()]));
       htmlSelectOneMenu.getChildren().add(uiSelectItems);
      
       HtmlAjaxSupport htmlAjaxSupport = new HtmlAjaxSupport();
       htmlAjaxSupport.setEvent("onchange");
       htmlAjaxSupport.setReRender("testInputText");
       htmlSelectOneMenu.getFacets().put("a4jsupport", htmlAjaxSupport);
      
       HtmlInputText htmlInputText = new HtmlInputText();
       htmlInputText.setId("testInputText");
       ValueBinding testInputTextBinding = application.createValueBinding("#{" + getReportBeanName() + ".selectedReport}");
       htmlInputText.setValueBinding("value", testInputTextBinding);
      
       htmlForm.getChildren().add(htmlSelectOneMenu);
       htmlForm.getChildren().add(htmlInputText);
       }



      What i think is that I am passing the invalid component id tp setReRender method thats why it is not getting rendered. Please let me know if I am doing wrong, or point me to any tutorial for the same. Also please point me to any better ways of doing the same. I am also not very happy about the way I populated the htmlSelectOneMenu. I thought that for every JSF tag we have corresponding java class but was unable to find one corresponding to <f:selectItems>, hence I used above way for populating the htmlOneMenu.

      Thanks in Advance
      Ahsan