Registration with Validation

2

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

Now, I aim to create a "Enter Time" method where any person will enter an existing team by passing the ID and Password.

I have already done some registration methods, but I am in doubt on how to do this validation if the PasswordTime informed by the Person confers with the PasswordTime of the ID 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:

PersonModel:

@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;

PersonaTimeModel:

@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;
    
asked by anonymous 25.07.2016 / 14:02

1 answer

0

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

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

Another option would be for you to have a Times List in your JSF ManagedBean, display them on the screen via a combobox on the screen (if not many records) in a TimeSelected field on the ManagedBean. Then compare the selected object with those in your list.

    
02.08.2016 / 16:29