title: primefaces autocomplete with pojo
body: <p>I read on SO some QA about the same component, but I feel I'm missing something, because I am one step behind.
  I can't even make the page open when using the primefaces autocomplete component in it.
  The snippet for it is:</p>
  
  <pre><code>&lt;p:autoComplete value="#{indirizzoCtrl.selectedCodiceNazione}"  
              completeMethod="#{indirizzoCtrl.completeNazione}"  
              var="nazione" itemLabel="#{nazione.nome}"   
              itemValue="#{nazione.codiceNazione}" /&gt;
  </code></pre>
  
  <p>Nazione is a Pojo class where <code>CodiceNazione</code> and <code>Nome are</code> two String field (with getter and setter for sure). <code>completeNazione</code> is a method on the ManagedBean that returns <code>List&lt;Nazione&gt;</code>.
  Looking at BalusC explanation <a href="https://stackoverflow.com/a/7653775/333223">here</a>, it seems to me that i don't need any converter involved, because both itemValue and value attributes are mapped to string property.
  Anyway, when I just open the page containing this autocomplete snippet, it crashes with this error:</p>
  
  <pre><code>javax.el.PropertyNotFoundException: /Cliente/Indirizzo.xhtml @23,56 itemValue="#{nazione.codiceNazione}": itemValue="#{nazione.codiceNazione}": Property 'codiceNazione' not found on type java.lang.String
  </code></pre>
  
  <p>Why this is happening? I really can't get it. The method completeNazione hasn't even called yet, so it shouldn't know any <code>Nazione</code> yet.
  What's wrong with it?</p>
  
  <p><strong><em>Edited:</em></strong>
  Following the suggestion, I tried to add a converter, but I still get the same error.
  Here's my converter:</p>
  
  <pre><code>    public class NazioneConverter implements Converter {
  
      final static Logger log = Logger.getLogger(NazioneConverter.class);
  
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
          if (value.trim().equals("")) {  
              return null;  
          } else {  
              try {  
                  IndirizzoRepository ir = new IndirizzoRepository();
                  List&lt;Nazione&gt; nazioni = ir.getNazioneByName(value);
                  if (nazioni.size()==1) return nazioni.get(0);
                  else throw new Exception();
  
              } catch (Exception e) {
                  String msg = "Errore di conversione";
                  log.error(msg, e);
                  throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, "Non è una nazione conosciuta"));  
              }  
          }          
      }
  
      @Override
      public String getAsString(FacesContext context, UIComponent component, Object value) {
          if (value == null || value.equals("")) {  
              return "";  
          } else {  
              return String.valueOf(((Nazione) value).getNome());  
          } 
      }
  
  }
  </code></pre>
  
  <p>now the component in the view looks like:</p>
  
  <pre><code>&lt;p:autoComplete value="#{indirizzoCtrl.indirizzo.nazione.codiceNazione}"  
              completeMethod="#{indirizzoCtrl.completeNazione}"  
              var="nazione" itemLabel="#{nazione.nome}" converter="#{nazioneConverter}"
              itemValue="#{nazione.codiceNazione}" forceSelection="true"  /&gt;
  </code></pre>
  
  <p>But still don't working. The converter is not even invoked: I registered it in my faces-config.xml file.
  I also tried itemValue="#{nazione}" as in the primefaces showcase but the problem became the <code>ItemLabel</code> attribute, mapped to <code>nazione.nome</code>.
  What am I doing wrong?</p>