I am new to MVC
and would like to know where it is validated that the controls of the view have information. For example, to add two numbers in the following example, where is it valid that txtNumero1
and txtNumero2
of a view are not empty?
public class Modelo {
09 //Variables
10 private int valor1;
11 private int valor2;
12
13
14 public Modelo(){}
15
16 public void set_valor1(int val){
17 this.valor1=val;
18 }
19
20 public int get_valor1(){
21 return this.valor1;
22 }
23
24 public void set_valor2(int val){
25 this.valor2=val;
26 }
27
28 public int get_valor2(){
29 return this.valor2;
30 }
31
32 public int sumar(){
33 return this.valor1 + this.valor2;
34
35 }
36 }
Vista
It has a text box ( txtNumero1
), a text box ( txtNumero2
), a text box ( txtResultado
) and a button btnSumar
.
Driver
public class controlador implements ActionListener{
12
13 private vista vista;
14 private Modelo modelo;
15
16
18 public controlador( vista vista , modelo modelo){
19 this.vista = vista;
20 this.modelo = modelo;
21 this.vista.cmdsumar.addActionListener(this);
22 }
23
24
25 public void iniciar_vista(){
26 vista.setTitle( "Sumar" );
27 vista.setLocationRelativeTo(null);
28 }
32
33
36 public void actionPerformed(ActionEvent e) {
37 modelo.set_valor1(Integer.valueOf( vista.txtNumero1.getText() ) );
38 modelo.set_valor2( Integer.valueOf( vista.txtNumero2.getText() ) vista.txtResultado.setText(String.valueOf(modelo.sumar()) );
41 }
42
43 }
Where could I validate? From the model, from the controller or from both?