3

I have this action ActionFindPeople and I want to search in a db a people by name and surname inserted in 2 different text fields.

public class ActionFindPeople extends AbstractAction{

    private Control control;

    public ActionFindPeople (Control control) {
        this.control = control;
        this.putValue(Action.NAME, "FIND");
        this.putValue(Action.SHORT_DESCRIPTION, "Find People");
        this.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_F));
        this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("CTRL F"));
    }

    public void actionPerformed(ActionEvent e) {

        Vist vist = (Vist) this.control.getVist();
        PanelInitial pi = (PanelInitial ) vist.getUnderVist(Costant.PANEL_INITIAL);
        PannelResult pr = (PannelResult) vist.getUnderVist(Costant.PANEL_RESULT);
        Model model = (Model) this.control.getModel();

        String name = pi.getTextFieldName().getText();
        String surname = pi.getTextFieldSurname().getText();

        Db db=  (Db) control.getModel().getBean(Costant.DB);

        Person personToFind = findPerson(name, surname, db);
        if(personToFind != null) {
            model.putBean(Costant.PERSON_FOUND, personToFind );
            prp.changeComponent((Person) this.control.getModel().getBean(Costant.PERSON_FOUND));
            vist.changePanel();
        } else {
            vist.windowError("Insesistent people for " + name+ " " + surname);
        }
    }

    public Person findPerson(String name, String surname, Db db) {
        List<Person> listPerson = db.getListPerson();
        for (Person p : listPerson){
            if(p.getName().equalsIgnoreCase(name) && p.getSurname().equalsIgnoreCase(surname)){
                return p;
            }
        }
        return null;
    }

}

I want try to put the people that have name and surname equals in a jTable, but when i ll do it, if people exists it turn me back all the people in the DataBase! How can i solve this problem??? Here is it also the code for refresh the Model of Table.

public void refreshModel() {

    Model model = (Model) this.vist.getModel();
    Person person = (Person) model.getBean(Costanti.PERSON);
    Db a = (Db) model.getBean(Costanti.DB);

    ModelTable mt = new ModelTable (a);
    this.jTable.setModel(mt);
    this.jTable.setSelectionMode(SINGLE_SELECTION);
    this.jScrollPane1.setViewportView(this.jTable);

}
Marc C
  • 73
  • 1
  • 8
  • 1
    Not sure if I fully understand your question/problem, but you may want to look at [table sorting and filtering](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting). You can use the a regex filter with firstname|surname. If this is a problem with db querying, maybe you should show you db access code. If this is just a matter of the table not updating with new data, I don't think the code you've provided gives enough detail, as you have many references to custom classes we cannot see, along with not being able to see any component interaction flow – Paul Samsotha Aug 13 '14 at 16:20
  • the database is a DAOmock... can u help me? – Marc C Aug 13 '14 at 16:27

0 Answers0