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?
– R.Santos
Database. If you want I can put the MODEL classes.
– Rafael Augusto
Each ID receives a specific Passwords? This information is saved in two different tables in the BD as well?
– R.Santos
Yes, each ID has a password. Saved in their respective tables.
– Rafael Augusto
Hello, Rafael! Put the model classes too, please.
– Dherik
Added @Dherik
– Rafael Augusto