Galera no estou utilizando o autocomplete para mostrar alguns elementos do meu banco , só que ele só mostra os 5 primeiros independente se eu digite uma letra que tenha nada ver, vejam:
Meu Banco até agr:
Na hora de pesquisar no autocomplete por exemplo queria que completasse o nome do celular positivo mas não acontece porque ele nem mostrar o “Positivo” mostra:
Meu Bean :
@ManagedBean
@SessionScoped
public class CellBean {
private FabricanteDAO cda = new FabricanteDAO();
private Fabricante selecionado;
//instâncias Fabricante
private Fabricante fabricante = new Fabricante();
private List lstFabricantes = new ArrayList<>();
public CellBean()
{
lstFabricantes = cda.buscarFabricantes();
}
/*
METODOS FABRICANTE
*/
public List<Fabricante> completeFabricante(){
return cda.buscarFabricantes();
}
public String clear(){
this.selecionado = null;
return "";
}//METODOS GETTERS E SETTERS...
Meu DAO:
public class FabricanteDAO {
public void salvarFabricante(Fabricante f)
{
try {
Connection conexao = BancoDados.getConexao();
PreparedStatement sql;
if(f.getId() == null)
{
//INSTRUÇÃO SQL
sql = conexao.prepareCall("INSERT INTO tbfabricantes(nome,pais)VALUES(?,?);");
}else{
sql = conexao.prepareStatement("UPDATE tbfabricantes SET nome=?,pais=? WHERE id=? ");
sql.setInt(3, f.getId());
}
sql.setString(1, f.getNome());
sql.setString(2, f.getPais());
sql.execute();
BancoDados.fecharConexao();
} catch (SQLException ex) {
Logger.getLogger(CellDAO.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void excluirFabricante(Fabricante fa)
{
try {
Connection conexao = BancoDados.getConexao();
PreparedStatement sql;
//INSTRUÇÃO SQL
sql = conexao.prepareStatement("DELETE FROM tbfabricantes WHERE id=?");
sql.setInt(1, fa.getId());
sql.executeUpdate();
BancoDados.fecharConexao();
} catch (SQLException ex) {
Logger.getLogger(CellDAO.class.getName()).log(Level.SEVERE, null, ex);
}
}
public List <Fabricante> buscarFabricantes()
{
try {
Connection conexao = BancoDados.getConexao();
//INSTRUÇÃO SQL
PreparedStatement sql = conexao.prepareCall("SELECT * FROM tbfabricantes");
ResultSet rs = sql.executeQuery();
List <Fabricante> lstFabricantes = new ArrayList<>();
while(rs.next())
{
Fabricante fabricante = new Fabricante();
fabricante.setId(rs.getInt("id"));
fabricante.setNome(rs.getString("nome"));
fabricante.setPais(rs.getString("pais"));
lstFabricantes.add(fabricante);
}
return lstFabricantes;
} catch (SQLException ex) {
Logger.getLogger(CellDAO.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}}
Minha Entidade:
public class Fabricante {
private String nome;
private String pais;
private Integer id;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getPais() {
return pais;
}
public void setPais(String pais) {
this.pais = pais;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Override
public String toString()
{
return getNome();
}
@Override
public int hashCode() {
int hash = 3;
hash = 97 * hash + Objects.hashCode(this.id);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Fabricante other = (Fabricante) obj;
if (!Objects.equals(this.id, other.id)) {
return false;
}
return true;
}}
Meu converter:
@FacesConverter(“FabricanteConverter”)
public class FabricanteConverter implements Converter
{
FabricanteDAO dao = new FabricanteDAO();
@Override
public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
if(string != null && string.trim().length() > 0)
{try{
Fabricante f = new Fabricante();
f.setNome(string);
return f;
}catch(Exception f){
throw new ConverterException(“Não foi possivel obter o fabricante” + string + “.” + f.getMessage());
}
}
return null;
}
@Override
public String getAsString(FacesContext fc, UIComponent uic, Object o) {
if (o != null && o instanceof Fabricante) {
return ((Fabricante) o).getNome();
}
return "";
}
}
Meu XHTML:
<h:form>
<p:fieldset legend=“Cadastro Fabricante”>
<p:toolbar>
<p:toolbarGroup>
<p:commandButton icon=“ui-icon-home” value=“adicionar” action="#{cellBean.adicionarFabricante()}" update="@form"></p:commandButton>
</p:toolbarGroup>
</p:toolbar>
<p:panelGrid columns="2" styleClass="showcase-text-align-center" columnClasses="p-col-12 p-md-6 p-lg-3, p-col-12 p-md-6 p-lg-3, p-col-12 p-md-6 p-lg-3, p-col-12 p-md-6 p-lg-3">
<p:outputLabel value="Fabricante:" for="complete" />
<p:autoComplete id="complete" forceSelection="true"
maxResults="5" value="#{cellBean.fabricante}" converter="FabricanteConverter" completeMethod="#{cellBean.completeFabricante()}"
var="fabri" itemLabel="#{fabri.nome}" itemValue="#{fabri}"/>
<h:outputLabel value="Fabricante"></h:outputLabel>
<p:inputText value="1"></p:inputText>
<h:outputLabel value="Pais"></h:outputLabel>
<p:inputText value="2"></p:inputText>
</p:panelGrid>
</p:fieldset>
</h:form>
Alguem poderia me ajudar a resolver essa buxa?
PS: Sou novato, pode ser uma coisa obvia mas qualquer ajuda vale