title: Primefaces populate other columns values based on selection of autocomplete
body: <p>I am using Primefaces AutoComplete and I am getting records from database using Hibernate.</p>
  
  <p>I am able to select values from database when I type in text. What I would like to achieve is when I select a name when I type characters, I would want my other columns in jsf page to get populated. E.g When I select employee name "SMITH" I want employee number, department to get filled with SMITH's employee number and department. </p>
  
  <p>I have the following in jsf page.</p>
  
  <pre><code>&lt;p:autoComplete value="#{myMB.selectedEmployee}"
                              id="basicPojo" minQueryLength="3" 
                              completeMethod="#{myMB.complete}" var="p"
                              itemLabel="#{p.empName}" 
                               converter="#{myconverter}"
                              forceSelection="true"  &gt; 
  
  &lt;h:outputLabel value="Emp Number" /&gt;
                          &lt;h:outputText value="#{p.employeeNumber}" /&gt;
  
  &lt;h:outputLabel value="Department" /&gt;
                          &lt;h:outputText value="#{p.employeeDepartment}" /&gt;
                      &lt;/p:autoComplete&gt;
  </code></pre>
  
  <p>When I select a name, other fields are not getting displayed.</p>
  
  <p>What could be the reason for this? How can I achieve the desired result?</p>
  
  <p>Any help is highly appreciated.</p>
  
  <p><strong>Edit 1</strong></p>
  
  <pre><code>&lt;p:dialog header="Create New Request" style="font-weight:bold"
                      widgetVar="requestNewDialog" resizable="false" 
          id="newDlg"             
      showEffect="fade" hideEffect="fade" appendToBody="true"
          modal="true" position="center top" width="850" height="450"&gt;
                      &lt;h:panelGrid columns="2" cellspacing="2"&gt;
                          &lt;h:outputText value="New Employee No:" /&gt;
                          &lt;h:outputText value="" /&gt;
                      &lt;/h:panelGrid&gt;
                      &lt;p:separator /&gt;
                      &lt;p:panelGrid columns="6"&gt;    
                          &lt;h:outputLabel value="Employee # " for="emp" /&gt;
                          &lt;p:autoComplete value="#
                         {myMB.selectedEmployee}"
                 id="basicPojo" minQueryLength="3" 
                 completeMethod="#{myMB.complete}" var="p"
                 itemLabel="#{p.longName}" 
                         converter="#{employeeNameConverter}"
                 forceSelection="true"  &gt;
                 &lt;p:ajax event="itemSelect" update="num" 
                         listener="#{myMB.handleSelect}"  /&gt;      
              &lt;h:outputLabel value="Name" for="name" /&gt;
              &lt;h:outputText value="#{p.employeeNumber}" /&gt;
              &lt;/p:autoComplete&gt;                       
  
          &lt;h:outputLabel id="num" value="Department" for="dept" /&gt;
          &lt;p:inputText id="dept" value="#{p.employeeNumber}" &gt;
                          &lt;/p:inputText&gt;
            &lt;/p:panelGrid&gt;
       &lt;p:separator /&gt;
           &lt;/p:dialog&gt;
  </code></pre>
  
  <p><strong>ManagedBean</strong> complete Method</p>
  
  <pre><code>public List&lt;Employee&gt; complete(String query) {
          List&lt;Employee&gt; suggestions;
          suggestions = new ArrayList&lt;Employee&gt;();
          try {
  
              EmployeeQueryData q = new EmployeeQueryData ();             
              getService().getEmployee(q,query);              
              employee = q.getResult();    
              for (Employee p : employee) {
                  if (p.getEmpName().toLowerCase().contains(query)); 
                      suggestions.add(p);    //               
              }
          } catch (Exception e) {             
          }    
          return suggestions;
      }
  </code></pre>