Hello,

I have an 'Add' method that validates JTextFields to ensure data has been entered into them as well as checking that certain fields only contain digits. This works perfectly for my add method.

But when I try to import it into my 'save' method which is seperate to the add method as it's function is to enable users to edit the Jtextfields, then re-save and re-validate to specific indexes within the array.

When I do this it is aware that there is an error as it gives me the initial error message boxes. So it knows that there is a field missing or a misplaced digit. But it CONTINUES to write to the file regardless.

Any ideas?

private void propertySaveActionPerformed(java.awt.event.ActionEvent evt) {                                             
        for (int i = 0; i < propertyID.length; i++) {
            if (propertyID[i] != null) {//if applicaitonID in the index is not equal to null do:
                if (propertyID[i].equals(oldPropertyID)) {//if the ID's match  up, write to this index in the array
                    // sets each element in the specified index of the array to //corresponding txt
                    propertyID[i] = propertyIDTxt.getText();
                    propertyAddress[i] =  propertyAddressTxt.getText();
                    propertyAddress2[i] =  propertyAddress2Txt.getText();
                    propertyTown[i] = propertyTownTxt.getText();
                    propertyCounty[i] =  propertyTownTxt.getText();
                    propertyPostCode[i] =  propertyCountyTxt.getText();
                    propertyNumBedrooms[i] =  propertyPostCodeTxt.getText();
                    propertyNumBathrooms[i] =  propertyNumBedroomsTxt.getText();
                    propertyNumFloors[i] =  propertyNumBathroomsTxt.getText();
                    propertyRent[i] =  propertyNumFloorsTxt.getText();;
                    propertyFeatures[i] =  propertyRentTxt.getText();
                    
            if (propertyID[i].equals("")) {
            JOptionPane.showMessageDialog(null, "Missing ID!", "Error!", JOptionPane.WARNING_MESSAGE);
            validData = false;
            } else {
            propertyID[i] = propertyIDTxt.getText();    
            validData = true;
             }
            
            if (propertyAddress[i].equals("")) {
            JOptionPane.showMessageDialog(null, "Missing Address!", "Error!", JOptionPane.WARNING_MESSAGE);
            validData = false;
            } else {
           propertyAddress[i] =  propertyAddressTxt.getText();
            validData = true;
             }
            
            if (propertyAddress2[i].equals("")) {
            JOptionPane.showMessageDialog(null, "Missing Address 2!", "Error!", JOptionPane.WARNING_MESSAGE);
            validData = false;
            } else {
            propertyAddress2[i] = propertyAddress2Txt.getText();    
            validData = true;
             }
            
            if (propertyTown[i].equals("")) {
            JOptionPane.showMessageDialog(null, "Missing Town!", "Error!", JOptionPane.WARNING_MESSAGE);
            validData = false;
            } else {
            propertyTown[i] = propertyTownTxt.getText();    
            validData = true;
             }
            
            if (propertyCounty[i].equals("")) {
            JOptionPane.showMessageDialog(null, "Missing County!", "Error!", JOptionPane.WARNING_MESSAGE);
            validData = false;
            } else {
            propertyCounty[i] = propertyCountyTxt.getText();    
            validData = true;
             }
            
            if (propertyPostCode[i].equals("")) {
            JOptionPane.showMessageDialog(null, "Missing Post Code!", "Error!", JOptionPane.WARNING_MESSAGE);
            validData = false;
            } else {
            propertyPostCode[i] = propertyPostCodeTxt.getText();    
            validData = true;
             }
            
            if (propertyNumBedrooms[i].equals("")) {
            JOptionPane.showMessageDialog(null, "Missing Num Bedrooms!", "Error!", JOptionPane.WARNING_MESSAGE);
            validData = false;
            } else {
            propertyNumBedrooms[i] = propertyNumBedroomsTxt.getText();    
            validData = true;
             }
            
            if (propertyNumBathrooms[i].equals("")) {
            JOptionPane.showMessageDialog(null, "Missing Num Bathrooms!", "Error!", JOptionPane.WARNING_MESSAGE);
            validData = false;
            } else {
            propertyNumBathrooms[i] = propertyNumBathroomsTxt.getText();    
            validData = true;
             }
            
            if (propertyNumFloors[i].equals("")) {
            JOptionPane.showMessageDialog(null, "Missing Num Floors!", "Error!", JOptionPane.WARNING_MESSAGE);
            validData = false;
            } else {
            propertyNumFloors[i] = propertyNumFloorsTxt.getText();    
            validData = true;
             }
            
            if (propertyRent[i].equals("")) {
            JOptionPane.showMessageDialog(null, "Missing Rent!", "Error!", JOptionPane.WARNING_MESSAGE);
            validData = false;
            } else {
            propertyRent[i] = propertyRentTxt.getText();    
            validData = true;
             }
            
            if (propertyFeatures[i].equals("")) {
            JOptionPane.showMessageDialog(null, "Missing Features!", "Error!", JOptionPane.WARNING_MESSAGE);
            validData = false;
            } else {
            propertyFeatures[i] = propertyFeaturesTxt.getText();    
            validData = true;
             }
            
            if (validData == false) {
                JOptionPane.showMessageDialog(null, "Unable To Write To File, Input Error, Try Again", "Error!", JOptionPane.WARNING_MESSAGE);
                clearPropertyText();
            } else{
                    writeToProperty(filename);//writes the informatio to file
                    disablePropertyText();//disables textfields
                    propertyNew.setEnabled(true);//sets some buttons to enabled true/false to validate input and avoid user corrupting data
                    propertyAdd.setEnabled(false);
                    propertyEdit.setEnabled(true);
                    propertySave.setEnabled(false);
                    propertyDelete.setEnabled(true);
                    propertyNext.setEnabled(true);
                    propertyPrev.setEnabled(true);
            }
                    
               }
            }
        }
      
        
   }

Thank you for your time.

it is aware that there is an error

What is the "it" that is aware?
What error is there?

it CONTINUES to write to the file regardless.

Is the writing to the file controlled by the value of a variable?
Where is the variable given a value?
Is the variable's value changed?

If needed, can you make a small simple program (SSCCE) to show the problem?

Edited 4 Years Ago by NormR1: n/a

This article has been dead for over six months. Start a new discussion instead.