2
I am using the Datatable Drag And Drop component. Contextualizing is as follows:
I got a rap sheet based on footsteps. Where in the first step I enter the information of an Edict X, what is manipulated by editalBean, already in the second step I have the Drag and Drop component with the Disciplines to be chosen, so far so good. If I don’t even suggest documentation I can make it work. But here comes the problem: The method of my disciplinesBean needs to be passed a center (entity) as a parameter and this center is in editalBean. My solution was to put the list of selected disciplines in the disciplinesBean and the complete list of disciplines in editalBean (which is where I can pass the parameter).
The method that handles these two lists is this (when they are in the same bean):
public void onDisciplinaDrop(DragDropEvent ddEvent) {
Disciplina disciplina = ((Disciplina) ddEvent.getData());
listaSelecionadoss.add(disciplina);
listaCompleta.remove(disciplina);
}
Then the discipline is added to one table and removed from another. But as I put the complete list of disciplines in another bean, I don’t know how to remove it.
My onDisciplinaDrop method is in the disciplineBean and my listComplete is in editalBean. How can I make the correct removal?
My codes:
Editalbean.java
@ManagedBean(name="editalBean")
@SessionScoped
public class EditalBean {
private Edital edital;
private EditalDAO editalDAO = new EditalDAO();
private Centro centro;
private CentroDAO centroDAO = new CentroDAO();
private DisciplinaDAO disciplinaDAO = new DisciplinaDAO();
private List<Disciplina> listaPorCentro;
public List<Disciplina> getListaPorCentro() {
listaPorCentro = disciplinaDAO.getListaDisciplinaPorCentro(edital.getAno(), edital.getPeriodo(), centro);
return listaPorCentro;
}
public void setListaPorCentro(List<Disciplina> listaPorCentro) {
this.listaPorCentro = listaPorCentro;
}
Disciplinabean.java
@ManagedBean(name="disciplinaBean")
@SessionScoped
public class DisciplinaBean {
private Disciplina disciplina;
private Disciplina disciplinaSelecionada;
private List<Disciplina> droppedDisciplinas = new ArrayList<Disciplina>();
private DisciplinaDAO disciplinaDAO = new DisciplinaDAO();
public void onDisciplinaDrop(DragDropEvent ddEvent) {
if(droppedDisciplinas != null){
droppedDisciplinas.add(d);
}else {
System.out.println("droppedDisciplinas é nulo.");
}
}
If you need more details I try to explain better. Thank you.
The general need I understood but the specific problem was not clear to me. I imagine that your difficulty lies in using in a Bean the objects that were instantiated in another Bean. Is that it? Two suggestions: consider using a single bean for resources on the same page that interact so much with each other; and consider using Viewscoped because Sessionscoped can greatly harm the user experience.
– Caffé
Good morning @Caffé, my problem is exactly this, through Disciplinabean managing to manipulate an object that is in Editalbean, so the best thing would be to create a Bean type: formCadastroBean (since it is a registration form) and within it I work with both Beans? Is that about right? And what’s the difference between Session Scoped and View Scoped, they interfere with that?
– João Neto