title: How can `p:autocomplete` be made to show its selected value, after a postback (or, "partial" postback)?
body: <p><em><strong>(java7,  jsf/mojarra v2.1.11,  primefaces v3.4.2)</em></strong></p>
  
  <h1>Problem</h1>
  
  <p>I have a form with an <code>p:autocomplete</code> input field that the user is required to populate, along with other fields (shown, below).</p>
  
  <p>Right now, <strong><em>after the page is returned with validation and/or required errors</em></strong>, the value that the user has set no longer displays.   This is in contrast to all the other fields which still show their values that have been entered/set by the user. </p>
  
  <h1>Question:</h1>
  
  <p>Why doesnt this field display the user entered value?  Can I force it to display the value?</p>
  
  <p>(Again, initially, the selected value is visible in the <code>p:autocomplete</code> input box.  But, after the page is submitted and returned with validation erriors, the selected value is no longer displayed)</p>
  
  <h1>The tag looks like this:</h1>
  
  <pre><code>&lt;p:autoComplete
      id="code"
      requiredMessage="code value required"
      converter="acConverter"
      style="overflow: hidden"
      maxResults="200"
      scrollHeight="150"
      dropdown="false"
      value="#{testBean.parmMap['code']}"
      completeMethod="#{testBean.codeListComplete}"
      var="entry"
      itemLabel="#{entry.split(':')[1]}"
      itemValue="#{entry.split(':')[0]}"
      minQueryLength="1"
      forceSelection="true"&gt;
  &lt;/p:autoComplete&gt;   
  </code></pre>
  
  <p>Right now, if a user submits the form and the form is posted back with various form validation errors, then, even if the user has correctly selected from the <code>p:autocomplete</code>, the associated input field does not show what they have selected (although it is apparently saved in the request/memory).</p>
  
  <hr>
  
  <hr>
  
  <hr>
  
  <hr>
  
  <hr>
  
  <p><em><strong>FYI - Below is more info if you need it (otherwise, you can just ignore it)...</em></strong></p>
  
  <p><em><strong>index.xhtml...</em></strong></p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:c="http://java.sun.com/jsp/jstl/core"
        xmlns:p="http://primefaces.org/ui"&gt;
      &lt;f:view contentType="text/html"&gt;
          &lt;h:head&gt;
              &lt;title&gt;test autocomplete...&lt;/title&gt;
              &lt;meta charset="utf-8" /&gt;
          &lt;/h:head&gt;
          &lt;h:body&gt;
              &lt;h:form id="queryForm"&gt;
  
                  &lt;f:event type="postValidate" listener="#{testBean.validate}" /&gt;
                  &lt;p:panel id="queryPanel"  header="test autocomplete..." style="width:100%;"&gt;
  
                      &lt;p:autoComplete
                          id="code"
                          requiredMessage="code value required"
                          converter="acConverter"
                          style="overflow: hidden"
                          maxResults="200"
                          scrollHeight="150"
                          dropdown="false"
                          value="#{testBean.parmMap['code']}"
                          completeMethod="#{testBean.codeListComplete}"
                          var="entry"
                          itemLabel="#{entry.split(':')[1]}"
                          itemValue="#{entry.split(':')[0]}"
                          minQueryLength="1"
                          forceSelection="true"&gt;
                      &lt;/p:autoComplete&gt;
  
                      &lt;br/&gt;
                      &lt;br/&gt;
  
                      &lt;p:commandButton
                          id="submit"
                          value="Submit"
                          type="submit"
                          update="@form"
                          process="@form"
                          action="#{testBean.submitQuery}"
                          style="width:150px;"
                          styleClass="button"/&gt;
  
                      &lt;p:commandButton
                          value="Reset"
                          update="@form"
                          onclick="location.reload();return true;"
                          process="@this"
                          actionListener="#{testBean.reset}"
                          immediate="true"
                          ajax="false"/&gt;
  
                  &lt;/p:panel&gt;
              &lt;/h:form&gt;
  
              &lt;h:outputStylesheet library="styles"    name="query.css"      /&gt;
              &lt;h:outputScript      library="primefaces" name="/jquery/jquery.js" /&gt;
              &lt;h:outputScript      library="primefaces" name="/jquery/plugins/ui/jquery-ui.custom.js" /&gt;
              &lt;h:outputScript     library="primefaces" name="/jquery/plugins/inputmask/maskedinput.js" /&gt;
  
          &lt;/h:body&gt;
      &lt;/f:view&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><em><strong>TestBean.java...</em></strong></p>
  
  <pre><code>package aaa.bbb.ccc.war;
  
  import java.io.Serializable;
  import java.text.ParseException;
  import java.util.ArrayList;
  import java.util.LinkedHashMap;
  import java.util.List;
  import javax.faces.application.FacesMessage;
  import javax.faces.component.UIForm;
  import javax.faces.component.UIInput;
  import javax.faces.context.FacesContext;
  import javax.faces.event.ActionEvent;
  import javax.faces.event.ComponentSystemEvent;
  import org.apache.commons.lang.StringUtils;
  import org.primefaces.context.RequestContext;
  import org.springframework.context.annotation.Scope;
  import org.springframework.stereotype.Component;
  
  @Component("testBean")
  @Scope("request")
  public class TestBean implements Serializable
  {
      public TestBean()
      {
          parmMap = this.getParmMap();
          FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("parmMap", parmMap);
      }
  
      public void reset(ActionEvent event)
      {
          RequestContext.getCurrentInstance().reset("queryForm:queryPanel");
          LinkedHashMap&lt;String, Object&gt; m = new LinkedHashMap&lt;String, Object&gt;();
          FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("parmMap");
          setParmMap(m);
      }
  
      public String submitQuery()
      {
          FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("hitlistData");
  
          System.out.println("TestBean_________________________submitQuery()____________________parmMap contains:" + this.getParmMap().toString());
  
          if (this.getParmMap().isEmpty())
          {
              return "";
          }
  
          return "/page2.xhtml?faces-redirect=true";
      }
  
      private static LinkedHashMap&lt;String, Object&gt; parmMap;
      public LinkedHashMap&lt;String, Object&gt; getParmMap()
      {
          LinkedHashMap&lt;String, Object&gt; map = (LinkedHashMap&lt;String, Object&gt;) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("parmMap");
  
          if (null == map)
          {
              map = new LinkedHashMap&lt;String, Object&gt;();
          }
  
          return map;
      }
  
      public void setParmMap(LinkedHashMap&lt;String, Object&gt; map)
      {
          parmMap = map;
          FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("parmMap", parmMap);
      }
  
      public void validate(ComponentSystemEvent e) throws ParseException
      {
          LinkedHashMap parmMap = this.getParmMap();
          UIForm queryForm = (UIForm) e.getComponent();
          FacesContext fc = FacesContext.getCurrentInstance();
  
          UIInput code_c = (UIInput) queryForm.findComponent("code");
          String code = (String) code_c.getValue();
  
          try
          {
              if (StringUtils.isBlank(code))
              {
                  code_c.setSubmittedValue("");
                  code_c.setValid(false);
                  fc.addMessage(code_c.getClientId(), new FacesMessage(FacesMessage.SEVERITY_ERROR, code_c.getRequiredMessage(), code_c.getRequiredMessage()));
              }
  
              if (fc.getMessageList().size() &gt; 0)
              {
                  fc.renderResponse();
              }
          }
          catch (Exception e1)
          {
              e1.printStackTrace();
          }
      }
  
      private static List&lt;String&gt; codeList;
      public static List&lt;String&gt; getCodeList()
      {
          codeList = (List&lt;String&gt;) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("codeList");
  
          if (null == codeList)
          {
              codeList = new ArrayList&lt;String&gt;();
              codeList.add("keyaaaa:valaaaa");
              codeList.add("keybbbb:valbbbb");
              codeList.add("keycccc:valcccc");
              codeList.add("keydddd:valdddd");
              codeList.add("keyeeee:valeeee");
              codeList.add("keyffff:valffff");
              codeList.add("keygggg:valgggg");
              codeList.add("keyhhhh:valhhhh");
              FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("codeList", codeList);
          }
  
          return codeList;
      }
  
      public void setCodeList(List&lt;String&gt; list)
      {
          codeList = list;
      }
  
      public static List&lt;String&gt; codeListComplete(String s)       //autocomplete "completeMethod"...
      {
          List&lt;String&gt; list = getCodeList();
          List&lt;String&gt; suggestions = new ArrayList&lt;String&gt;();
          for (String ss : list)
          {
              if (ss.toLowerCase().contains(s.toLowerCase()))
              {
                  suggestions.add(ss);
              }
          }
  
          return suggestions;
      }
  
  }
  </code></pre>
  
  <p><em><strong>ACConverter.java  (I created this in an unsuccessful attempt to remove the string value "null")...</em></strong></p>
  
  <pre><code>package aaa.bbb.ccc.war;
  
  import javax.faces.application.FacesMessage;
  import javax.faces.component.UIComponent;
  import javax.faces.component.UIInput;
  import javax.faces.context.FacesContext;
  import javax.faces.convert.Converter;
  import javax.faces.convert.ConverterException;
  import javax.faces.convert.FacesConverter;
  import org.apache.commons.lang.StringUtils;
  
  @FacesConverter("acConverter")
  public class ACConverter implements Converter
  {
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value)
      {
          try
          {
              if (StringUtils.isBlank(value) || String.valueOf(value).equalsIgnoreCase("null"))
              {
                  return "";
              }
          }
          catch (Exception e)
          {
              UIInput input = (UIInput) component;
              FacesMessage msg = new FacesMessage(input.getConverterMessage(),input.getConverterMessage());
              msg.setSeverity(FacesMessage.SEVERITY_ERROR);
              throw new ConverterException(msg);
          }
  
          return value;
      }
  
      @Override
      public String getAsString(FacesContext context, UIComponent component, Object value)
      {
          return (null==value?"":String.valueOf(value));
      }
  }
  </code></pre>