1
I have an array that whenever I refresh my page, it duplicates. I did some tests to see if it was duplicated in Javascript, but found nothing.
This is the Javascript:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
listaProjetoArr = "";
listaProjeto = "";
listaProjeto = "${usuarioBean.listaNomeProjeto}";
listaProjeto = listaProjeto.replace("[", "");
listaProjeto = listaProjeto.replace("]", "");
var listaProjetoArr = listaProjeto.split(",");
console.log(listaProjetoArr)
$.each(listaProjetoArr, function(index, value) {
$("#projeto").append("<option value='"+value+"'>"+value+"</option>");
});
</script>
And that’s the controller’s method:
@RequestMapping(value = REDIRECT_PAGE_CADASTRO, method = RequestMethod.GET)
public ModelAndView viewCadastro(Model model) {
List<Projeto> listaCompletaProjeto = projetoService.findAll();
for (Projeto listaProjetos : listaCompletaProjeto) {
listaNomeProjeto.add(listaProjetos.getProjeto());
}
List<Perfil> listaCompletaPerfil = perfilService.findAll();
for (Perfil listaPerfis : listaCompletaPerfil) {
listaNomePerfil.add(listaPerfis.getPerfil().toString());
}
List<Jornada> listaCompletaJornada = jornadaService.findAll();
for (Jornada listaJornadas : listaCompletaJornada) {
listaNomeJornada.add(listaJornadas.getDsJornada().toString());
}
usuarioBean = new UsuarioBean(listaNomeProjeto, listaNomePerfil, listaNomeJornada);
model.addAttribute("usuarioBean", usuarioBean);
return new ModelAndView(REQUEST_MAPPING_PAGE_CADASTRO);
}
Your controller is marked with
@SessionScope
? What are his notes? Where and how is thelistaNomeProjeto
, thelistaNomePerfil
and thelistaNomeJornada
?– Victor Stafusa
is not annotated with @Sessionscope and the cosings are declared as private List<String> listNomeProject = new Arraylist<String>(); Private List<String> listNomePerfil = new Arraylist<String>(); private List<String> listNomeJornada = new Arraylist<String>();
– Wesley Santos
Probably the
listaNomePerfil
is global, you have to put its instance within the method– Sorack
then more I’m instantiating everything by Bean
– Wesley Santos
I recommend you post then your full controller class.
– Victor Stafusa