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;