Validation of Jdatechooser

Asked

Viewed 304 times

1

I need to validate three dates that are like JDateChooser. These dates are: date of birth, date of admission and date of dismissal.

The date of birth may not be longer than the date of admission or longer than the date of dismissal.

The date of resignation may not be less than the date of admission.

I want to validate the date of admission the moment the user fills in, an alert window will be triggered if that date is less than the date of birth. And the same happens between the date of admission and the date of dismissal.

I’ve tried this validation with an if - Else, but it only works for two cases at once, or just one. And I used the event mouseEntered and set a minimum value for the dates. But I have this error

Exception in thread "AWT-Eventqueue-0" java.lang.Illegalargumentexception

. Would anyone have a suggestion ? Thank you.

Attempt 1

if(dataAdm().getDate().after(dataNasc.getDate())){
      if(dataDem().getDate().after(DataAdm.getDate())){
          mensagem de alerta;
      }
    }

Attempt with the event propertyChange and mouseClicked in the field of admission date.

if(dataAdm().getDate().after(dataNasc.getDate())){
    mensagem de alerta;
}

Screen print

Imagem de exemplo dos campos

actionPerformed

 validacao = new ValidaSuper();
        if (validacao.recebeDadosObrigatorios(nome.getText(), cpf.getText(), orgaoExp.getText(),
                funcao.getText(), email.getText())) {
            if (validacao.validaDadosObrigatorios()) {
                if(dataAdm.getDate().after(dataNasc.getDate())){
                    if(dataDem.getDate().after(dataAdm.getDate())){
                        setDadosObrigatorios();
                        setDados();
                        idCoord = map.insereCoordenador(coord);
                        map.insereTelefoneCoordenador(tel, idCoord);
                        JOptionPane.showMessageDialog(this, "Coordenador(a) inserido(a) com sucesso !!!");
                        limparCampos();
                    }
                }
            }  
        } 
    }catch (UnsupportedEncodingException ex) {
        Logger.getLogger(CadastraCoordenador.class.getName()).log(Level.SEVERE, null, ex);
    }catch (SQLException ex) {
        Logger.getLogger(CadastraCoordenador.class.getName()).log(Level.SEVERE, null, ex);
    }
  • 1

    There are several ways to do, put some code of what you at least tried to give a north to anyone who will answer.

  • The link of the image you sent is broken. You can use the button to attach image in the question form itself.

  • Thanks for the comments.

  • Don’t ask, but wouldn’t the difference between the year of birth and the year of admission be under 14? I take into account that this is employment information.

  • Actually @Diegof would have to be 18 years old for having a registered license, but your reasoning is correct as well. The question is how to validate this question you spoke of and the question of the date of dismissal and date of admission.

  • Where do you validate this? Have some Jbutton that you click and validate everything before saving? If yes, post the actionPerformed in the question for us to verify.

  • First I validated on the sign up button. That’s right.

  • You have to treat it within the actionPerformed of your Jbutton. Logic doesn’t seem wrong, or the problem isn’t in the code you added in the question.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.