0

I am trying to implement within a small JavaFX desktop application a search textfield with auto suggestions like the famous search engines on the web. The auto suggestions are database driven in conjunction with Hibernate. For the textfield I am using ControlsFX library.

I have two issues:

1.) How can I display the correct student's name and first name in the suggestion list? (Presently I see the student object representation e.g. java.lang.object@23c884fb) I even tried with List<String>.

2.) My query doesn't return the correct results. E.g. if I type "a" I expect to get all student names which contain "a".

EntityManager em = JpaUtil.getEntityManager();
                em.getTransaction().begin();
                //System.out.println(searchField.getText());
                Query q = em.createQuery("SELECT s.name, s.firstName FROM Student AS s WHERE s.name like :name");
                q.setParameter("name", ("%" + searchField.getText().toLowerCase().trim() +"%"));

                List<Student> results = (List<Student>) q.getResultList();

                TextFields.bindAutoCompletion(searchField, results);

                em.getTransaction().commit();
                em.close();

Thanks. (I am still learning).

Marko
  • 47
  • 5
  • I think [this](https://stackoverflow.com/questions/50495430/how-to-customize-auto-complete-text-field-suggestion-in-javafx/50495985#50495985) might be a duplicate. It should be very similar. You may want to use `contains` over `startwith`. – SedJ601 Jul 17 '23 at 21:04

0 Answers0