<p:autoComplete /> bug?

UI Components for JSF
Post Reply
User avatar
pitutos
Posts: 52
Joined: 23 Jul 2010, 01:28

28 Feb 2011, 00:07

Hi all,

When I implement p:autoComplete without the selectListener property, the value of the component doesn't persist in the managed bean. It's a bug or it's my code?

This is my code

XHTML (a part of it)

Code: Select all

                <h:outputText value="País:" styleClass="text" />
                <p:autoComplete value="#{persona.paísSelected}"
                                var="país" itemLabel="#{país.país}" itemValue="#{país}"
                                completeMethod="#{persona.autocompletePaíses}" converter="países"
                                maxResults="8" selectListener="#{persona.handleSelect}" 
                                forceSelection="true" onSelectUpdate="growl" />
Converter

Code: Select all

package ar.com.fatarco.model.converters;

import ar.com.fatarco.model.dao.PersonaDAO;
import ar.com.fatarco.model.entities.País;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

/**
 *
 * @author pitutos
 */
public class PaísConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        try {
            return PersonaDAO.getPaís(value);
        } catch (SQLException ex) {
            Logger.getLogger(PaísConverter.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value != null || !value.equals("")) {
            País país = (País) value;
            return país.getPaís();
        }

        return "";
    }

}
ManagedBean

Code: Select all

package ar.com.fatarco.controllers;

import ar.com.fatarco.model.dao.PersonaDAO;
import ar.com.fatarco.model.entities.País;
import ar.com.fatarco.model.entities.Persona;
import ar.com.fatarco.model.entities.Provincia;
import ar.com.fatarco.model.entities.TipoDocumento;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.event.SelectEvent;

/**
 *
 * @author pitutos
 */
@ManagedBean(name="persona")
@ViewScoped
public class PersonaController implements Serializable {

    private Persona persona;
    private List<TipoDocumento> tiposDocumentos;
    private List<País> países;
    private List<Provincia> provincias;
    private País paísSelected;
    private Provincia provinciaSelected;

    /** Creates a new instance of PersonaController */
    public PersonaController() {
        persona = new Persona();
        populateTiposDocumentos();
    }

    public Persona getPersona() {
        return persona;
    }

    public void setPersona(Persona persona) {
        this.persona = persona;
    }

    private void populateTiposDocumentos() {
        try {
            tiposDocumentos = PersonaDAO.getTiposDocumentos();
        } catch (SQLException ex) {
            Logger.getLogger(PersonaController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public List<País> autocompletePaíses(String paísQuery) {
        try {
            return PersonaDAO.getPaíses(paísQuery);
        } catch (SQLException ex) {
            Logger.getLogger(PersonaController.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    public List<Provincia> autocompleteProvincias(String provinciaQuery) {
        try {
            int idPaís = paísSelected.getIdPaís();
            return PersonaDAO.getProvincias(idPaís, provinciaQuery);
        } catch (SQLException ex) {
            Logger.getLogger(PersonaController.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    public List<TipoDocumento> getTiposDocumentos() {
        return tiposDocumentos;
    }

    public List<País> getPaíses() {
        return países;
    }

    public List<Provincia> getProvincias() {
        return provincias;
    }

    public País getPaísSelected() {
        return paísSelected;
    }

    public void setPaísSelected(País paísSelected) {
        this.paísSelected = paísSelected;
    }

    public Provincia getProvinciaSelected() {
        return provinciaSelected;
    }

    public void setProvinciaSelected(Provincia provinciaSelected) {
        this.provinciaSelected = provinciaSelected;
    }

    public void handleSelect(SelectEvent event) {
        // TODO: No persiste el valor si esta propiedad
    }
}
I'm using PF-2.2.1, NetBeans 6.9.1, GlassFish v3 and Maven (NB Plugin)
NetBeans 7.1
Mojarra-2.1.7
PrimeFaces-3.0.1
Tomcat 7.0.22

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

28 Feb 2011, 12:23

Maybe you are getting a conversion error? Do you have a messages component on page? Do you submit the form with or without ajax?

User avatar
pitutos
Posts: 52
Joined: 23 Jul 2010, 01:28

28 Feb 2011, 15:04

Conversion works fine, I've a growl component on page and I use ajax for submit :roll: :lol:
NetBeans 7.1
Mojarra-2.1.7
PrimeFaces-3.0.1
Tomcat 7.0.22

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 26 guests