2 Replies Latest reply on Sep 27, 2007 7:07 AM by maksimkaszynski

    Programatically create a suggestion box with SetpropertyActi

    lucasmachado

      I am trying to programatically create a suggestion box with a nested setPropertyActionListener .

      I already build richfaces from SVN so my code is with RF-923 already fixed.

      The code above works fine in my app, so I dont believe is a implementation problem.

      <h:inputText value="#{someCtrl.nome}" styleClass="txt" style="width:190px;" id="grupoNome" />
      
      
      <rich:suggestionbox id="grupos" for="grupoNome" var="grupo" suggestionAction="#{someCtrl.nomes}" requestDelay="500" >
      <h:column>
      <h:outputText value="#{grupo.razaoSocial}" />
      </h:column>
      
      <a4j:support event="onselect" reRender="grupoNome" id="supportSetProperty">
      <f:setPropertyActionListener target="#{someCtrl.idGrupo}" value="#{grupo.id}"/>
      </a4j:support>
      </rich:suggestionbox>
      


      The problem is that i am trying to modify the component tree and create this components programatically on the fly.

      // Create input text
      String idInputRazaoSocial="pessoaJuridicaRazaoSocial";
      
      HtmlInputText inputRazaoSocial = (HtmlInputText) context.getApplication().createComponent(HtmlInputText.COMPONENT_TYPE);
      ValueExpression ve = context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(), "#{ctrl.razaoSocial}",String.class);
      inputRazaoSocial.setValueExpression("value", ve);
      inputRazaoSocial.setId(idInputRazaoSocial);
      
      panelGroup.getChildren().add(inputRazaoSocial);
      inputRazaoSocial.setParent(panelGroup);
      
      // Create suggestion box
      
      HtmlSuggestionBox suggestionBox= (HtmlSuggestionBox) context.getApplication().createComponent(HtmlSuggestionBox.COMPONENT_TYPE);
      
      suggestionBox.setFor(idInputRazaoSocial);
      
      MethodBinding mb = context.getApplication().createMethodBinding("#{"+UIPessoaJuridicaComponent.CTRL_NAME+".ctrls['"+originalComponent.getClientId(context)+"'].autocompleteNome}",new Class[]{String.class});
      
      suggestionBox.setSuggestionAction(mb);
      suggestionBox.setVar("row");
      suggestionBox.setRows(10);
      suggestionBox.setWidth("300");
      suggestionBox.setCellpadding("1");
      suggestionBox.setId("suggestNome");
      
      HtmlColumn column = (HtmlColumn) context.getApplication().createComponent(HtmlColumn.COMPONENT_TYPE);
      
      suggestionBox.getChildren().add(column);
      column.setParent(suggestionBox);
      
      HtmlOutputText labelColumn = (HtmlOutputText) context.getApplication().createComponent(HtmlOutputText.COMPONENT_TYPE);
      ValueExpression ve = context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(),"#{row.razaoSocial}",String.class);
      labelColumn.setValueExpression("value", ve);
      
      column.getChildren().add(labelColumn);
      labelColumn.setParent(column);
      
      
      panelGroup.getChildren().add(suggestionBox);
      suggestionBox.setParent(panelGroup);
      
      // Done creating suggestion box
      // Creating HtmlAjaxSupport
      
      HtmlAjaxSupport a4jSupportComponent = (HtmlAjaxSupport)context.getApplication()
       .createComponent(HtmlAjaxSupport.COMPONENT_TYPE);
      a4jSupportComponent.setEvent("onselect");
      a4jSupportComponent.setReRender(otherComponentId);
      a4jSupportComponent.setId(support_razaoSocial");
      
      ValueExpression target = context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(), "#{ctrl.id}", Long.class);
      
      ValueExpression propertyValue = context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(),"#{row.id}", Long.class);
      
      SetPropertyActionListenerImpl listener = new SetPropertyActionListenerImpl(target,propertyValue);
      a4jSupportComponent.addActionListener(listener);
      
      suggestionBox.getChildren().add(a4jSupportComponent);
      a4jSupportComponent.setParent(suggestionBox);
      
      


      The code renders fine, the suggestion box works but the ajaxsupport doesn't rerender or calls the setPropertyActionListener

      I have noted that when the component tree is generated by xhtml the HtmlAjaxSupport component isn't on the children list of htmlSuggestion, because of that i am suspecting that the problem is in how I add the HtmlAjaxSupport component on the tree.

      Any ideas about how to make this work?