Registration with Validation

Asked

Viewed 65 times

2

currently my system has Person and Time, a person can already create a Time, defining some attributes(name and passwordTime).

Now, I aim to create a "Join Team" method where someone will join an existing team passing the ID and the Senhatime.

I have done some registration methods, but I’m doubtful on how to do this validation if the Senhatime informed by Pessoa checks with the ID Senhatime informed.

Timebean:

public void entrarEmTime(){
            getPessoaTimeDAO().cadastrar(getPessoaTimeMembro(getPessoaBean().usuarioLogado(), getTime()));
            limpaTela();
    }

public PessoaTime getPessoaTimeMembro(Pessoa pessoa, Time time){
        PessoaTime p = new PessoaTime();
        p.setPessoa(pessoa);
        p.setTime(time);
        p.setCargo(Cargo.MEMBRO);
        return p;
    }

enterTime.xhtml:

<h:form class="form-label" id="entrarTime">
                                        <div class="form-group row">
                                            <label for="thread" class="col-md-2">ID Time:</label>
                                            <div class="col-md-10">
                                                <h:inputText value="#{timeMB.time.id}" type="nome"
                                                    class="form-control" id="nome"
                                                    placeholder="Adicione um nome ao seu time" />
                                            </div>
                                        </div>
                                        <div class="form-group row">
                                            <label for="description" class="col-md-2">Senha do
                                                Time:</label>
                                            <div class="col-md-10">
                                                <h:inputSecret value="#{timeMB.time.senhaTime}"
                                                    type="password" class="form-control" id="senha"
                                                    placeholder="Senha do seu Time" />
                                            </div>
                                        </div>
                                        <div class="text-center">
                                            <h:commandButton action="#{timeMB.entrarEmTime()}"
                                                value="Entrar"
                                                class="btn btn-primary btn-lg btn-rounded btn-shadow" />
                                        </div>
                                    </h:form>

Model:

Personal model:

@Entity
public class Pessoa implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column (name = "id_Pessoa")
    private Integer id;

    @Column()
    private String nomeUsuario;

    @Column()
    private String senhaUsuario;

    @Column()
    private String nomeCompleto;

    @Column()
    private String email;

    @Column()
    private Integer idade;

    @OneToMany(mappedBy = "pessoa", cascade = CascadeType.MERGE)
    private List<PessoaTime> listaPessoaTime; 

Timemodel:

@Entity
public class Time implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column (name = "id_Time")
    private int id;

    @Column(nullable = false)
    private String nome;

    @Column(nullable = false)
    private String senhaTime;


    @OneToMany(mappedBy = "time",cascade = CascadeType.MERGE)
    private List<PessoaTime> listaPessoaTime;

    @OneToMany(mappedBy="time",cascade = CascadeType.MERGE)
    private List<CampeonatoTime> listaCampeonatoTime;

Personal timemodel:

@Entity
@Table(name="pessoa_time")
public class PessoaTime implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column (name="id_PessoaTime")
    private Integer id;

    @ManyToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name="id_pessoa")
    private Pessoa pessoa;

    @ManyToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name="id_time")
    private Time time;

    @Enumerated(EnumType.STRING)
    private Cargo cargo;
  • Just to confirm, this registration of Senhatime and ID are saved in Database or Array?

  • Database. If you want I can put the MODEL classes.

  • Each ID receives a specific Passwords? This information is saved in two different tables in the BD as well?

  • Yes, each ID has a password. Saved in their respective tables.

  • Hello, Rafael! Put the model classes too, please.

  • Added @Dherik

Show 1 more comment

1 answer

0

I will not deal with codes here, but only ideas.

You capture the Time Id and password in an object in your Managedbean. In one method, you do a database search for the time id and store it in another temporary variable (scope of method), make the necessary comparisons.


Another option would be to have a Times List in your JSF Managedbean, display them on the screen via a combobox on the screen (if not too many records) in a Timeselected field in Managedbean. Then compare the selected object with the ones in your list.

Browser other questions tagged

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