1 Reply Latest reply on Feb 25, 2011 9:54 AM by ilya_shaikovsky

    Having issues with rich:autocomplete R4 M6

    rlcaswell

      I'm using Richfaces 4.0.0.20110209-M6 on Glassfish with jsf-api and jsf-impl 2.0.3-b03. running on windows XP.

      I've got a list of beans to use in an autocomplete list to populate a bean value in a jsf managed bean from the onchange event using <a4j:ajax/> tag.

      However, the dropdown  list is populated with what appears to be the converted value and the toString value of the beans in the list.  The selected value appears to populate correctly.  But the selected value is never populated in the managed bean when I tab out of the field also the debugger is never hitting the getAsObject method of the converter.  I'm not sure what is going on here. I'm not sure if this is a bug in the <rich:autocomplete/> tag or if I'm doing something wrong here.

       

      Here is the snippet from the xhtml:

              <h:form >

                 
                  <h:inputText  value="#{exampleController.field1}" >
                      <a4j:ajax event="change" render="testPanel" execute="@this"/>
                      </h:inputText>
                  <rich:autocomplete id="artistInput" value="#{exampleController.bean}" mode="client" minChars="0"
                                 autofill="false"
                                 showButton="true"
                                 autocompleteList="#{exampleController.autoCompleteBeans}"
                                 converter="#{autocompleteBeanConverter}"
                                 itemConverter="#{autocompleteBeanConverter}"
                                >
                  <a4j:ajax event="change" render="testPanel" execute="@this"/>
              </rich:autocomplete>
              <h:inputText  value="#{exampleController.field2}" >
                      <a4j:ajax event="change" render="testPanel" execute="@this"/>
               </h:inputText>

                  <h:panelGrid id="testPanel" columns="3">
                      <rich:panel>
                      <h:outputText value="#{exampleController.field1}"/>
                      </rich:panel>
                      <rich:panel>
                      <h:outputText value="#{exampleController.beanField}" />
                      </rich:panel>
                      <rich:panel>
                      <h:outputText value="#{exampleController.field2}"/>
                      </rich:panel>
                  </h:panelGrid>

              </h:form>

       

      Here are the java classes with accessors ommitted for space sake:

       

      public class AutocompleteBean {

          String field;

      }

       

       

      @ManagedBean(name="autocompleteBeanConverter")
      @SessionScoped
      public class AutocompletBeanConverter implements Converter, Serializable {
          List<AutocompleteBean> beans =
                  Arrays.asList(new AutocompleteBean("1bean"),new AutocompleteBean("2bean"),
                                new AutocompleteBean("3bean"));

          public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) {
              if (StringUtils.isBlank(value)) {
                  return null;
              } else {
                  AutocompleteBean bean = null;
                  String fieldValue = StringUtils.trim(value);
                  for(AutocompleteBean thisBean: beans){
                      if(thisBean.getField().equals(fieldValue)){
                          bean= thisBean;
                      }
                  }
                  return bean;
              }
          }

          public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
              if (value != null) {
                  AutocompleteBean bean = (AutocompleteBean) value;
                  return bean.getField();
              } else {
                  return null;
              }
          }

      }

       

      @ManagedBean(name="exampleController")
      @SessionScoped
      public class ExampleController {


          AutocompleteBean bean;
          String field1;
          String field2;

       

          public AutocompleteBean getBean() {
              return bean;
          }

          public void setBean(AutocompleteBean bean) {
              this.bean = bean;
          }

          public String getBeanField(){
              if(bean!=null){
              return bean.getField();
              }
              else {
                  return null;
              }
          }

          public List<AutocompleteBean> getAutoCompleteBeans(){
              return  Arrays.asList(new AutocompleteBean("1bean"),new AutocompleteBean("2bean"),
                                new AutocompleteBean("3bean"));
          }

      }

        • 1. Having issues with rich:autocomplete R4 M6
          ilya_shaikovsky

          Thanks for your report!! It seems we need to perform some clean-up there And also found one issue reviewing your post.

          http://jira.jboss.org/browse/RF-10617 - the main cause why the converter not works. Just wrong value getting set as submitted from the beginning. So you should be able to see it working after it will bereolved (soon )

           

          http://jira.jboss.org/browse/RF-10614 - task on itemConverter removal. It's really not needed as we need only string representation for fetchValue for client and not need Object restored back at server side. In order to properly output the list for cusom object after this issue will be resolved you could use two ways:

          1) redefine toString in your object

          2) use var and define popup markup using nested components and layout attribute. E.g.:

          <rich:autocomplete mode="cachedAjax" tokens=", " minChars="0"

                                        autoFill="false" selectFirst="false" id="ac3"

                                        value="#{autocompleteBean.svalue2}" var="a"

                                        autocompleteMethod="#{autocompleteBean.autocomplete}"

                                        fetchValue="#{a.state}">

                                        <h:outputText value="#{a.state}" />

          </rich:autocomplete>

           

          P.S. one more optimization request risen during review:http://jira.jboss.org/browse/RF-10618