0
I have a question: how could I check if the fields of my Jtextfields are empty before adding to the arraylist? as would be the validation in this part of code?
Endereco enderecoPJ=new Endereco();
PessoaJuridica pessoaJuridica=new PessoaJuridica();
pessoaJuridica.setNome(tfNome.getText());
pessoaJuridica.setSobrenome(tfSobrenome.getText());
pessoaJuridica.setCnpj((Long.valueOf(tfIndentificador.getText())));
enderecoPJ.setBairro(tfBairro.getText());
enderecoPJ.setCep(Long.valueOf(tfCep.getText()));
enderecoPJ.setCidade((String)cbCidades.getSelectedItem());
enderecoPJ.setNum(Integer.valueOf(tfNum.getText()));
enderecoPJ.setRua(tfRua.getText());
pessoaControler.pj.add(pessoaJuridica);
JOptionPane.showMessageDialog(null, "Cadastrado com Sucesso !");
I believe that the answer to this question marked as duplicate is the solution. In short, just apply
trim()
and then validate in an if withisEmpty()
– user28595
I believe the question marked as duplicate is not very applicable in my code, I want to check all fields, after checking, if any field has empty I can not add in arraylist, otherwise it add
– Viny_Hidan
The logic applied in the two answers is exactly this. In one of them I even made a point about how to validate this.
– user28595