lundi 21 mars 2016

JavaFX Sqlite check TextField wether its empty

I am struggling right now to check all my InputFields wether they == "".

I found many solutions here but somehow it doesnt work.

I have a RegistrationModal and a RegistrationController.

In the modal I tryed to check the fields like that:

public boolean RegisterUser(String user, String vorname, String nachname) throws SQLException {

    PreparedStatement preparedStatement = null;

    if (user == "" || vorname == "" || nachname == "") {
        System.out.println("Fill in all fields");
        return false;
    }
// Here follows the SQL query the prepared statement and exequte
}

But it it never uses this if statement, I have no idea why?

I also tryed to catch the empty element in the controller:

public void Absenden(ActionEvent event) {
    try {
        if (registerModel.RegisterUser(txt_user.getText(), txt_vorname.getText(),
                txt_nachname.getText())) {


            if (registerModel.RegisterUser(txt_user.getText().trim().isEmpty(), txt_vorname.getText().trim().isEmpty(),
                    txt_nachname.getText().trim().isEmpty())) {
                System.out.println("False! Do something?");
            }


            // Here opens the new window with a notification Registration was successfull
            ((Node) event.getSource()).getScene().getWindow().hide();
}

Here I had errors so thats why two if statement which already seems weird, I had to autogenerate a new method in model to make this work with booleans, but still it never used this if statement.

I tryed to give only relevant code, otherwise it would be much more.

Maybe someone has an idea.

Thanks

Aucun commentaire:

Enregistrer un commentaire