1 Reply Latest reply on Jan 18, 2011 5:15 AM by ilya_shaikovsky

    Richfaces4: autocomplete converter not receiving value to convert

    jerarckill

      Hello everybody,

       

      in the scope of a proof of concept with JSF2 and Richfaces 4, I am using the <rich:autocomplete> component and I have some problems making it work the way I want.

       

      I am using the <rich:autocomplete> in this way:

       

      <rich:autocomplete mode="client" showButton="true" layout="table" autocompleteList="#{workflowDefinitions}"

           fetchValue="#{wfDefinition.label}" var="wfDefinition" value="#{multiCriteriaBean.basic.workflowDefinition}">

           <f:converter converterId="optionDescriptor"></f:converter>

           <rich:column>

                <h:outputText value="#{wfDefinition.label}"/>

                </rich:column>

                <a4j:ajax event="selectitem" execute="@this" render="selectedWorkflowId"></a4j:ajax>

      </rich:autocomplete>

       

      // Used just as a little debug mechanism: the a4j:ajax event will fire the conversion at change time and the converter will then be called

      <h:outputText id="selectedWorkflowId" value="#{multiCriteriaBean.basic.workflowDefinition.label}" />

       

      I have a converter defined like this:

      @FacesConverter("optionDescriptor")

      public class WorkflowDefinitionConverter implements Converter {

       

         @Override

          public Object getAsObject(FacesContext facesContext, UIComponent component, String workflowDefinitionLabel) {

              for (OptionDescriptor currentWorkflowDefinition : WorkflowDefinitionProducer.getWorkflowDefinitions()) {

                  if (workflowDefinitionLabel.equals(currentWorkflowDefinition.getLabel())) {

                      return currentWorkflowDefinition;

                  }

              }

              throw new ConverterException("WorkflowDefinitionConverter found no matching OptionDescriptor for ' " + workflowDefinitionLabel + "'");

          }

       

          @Override

          public String getAsString(FacesContext facesContext, UIComponent component, Object workflowDefinition) {

              if (!(workflowDefinition instanceof OptionDescriptor)) {

                  throw new ConverterException("WorkflowDefinitionConverter only works with OptionDescriptor objects");

              }

              return ((OptionDescriptor) workflowDefinition).getLabel();

          }

       

      What works:

      The workflowDefinitions are read correctly and displayed as one would expect (see Screenshot-01 given as attachement).  My converter also gets called when an item is selected.

       

      What does not work:

       

      The converter is not passed the string value to convert.  Instead, I just get the empty String (screenshot-02).

       

      Would you have an idea why it is the case?

       

      thank you very much in advance for your time and help!

       

      Jérôme Jadoulle