Java 无法将项添加到托管Bean中的集合

Java 无法将项添加到托管Bean中的集合,java,jsf,jsf-2,primefaces,Java,Jsf,Jsf 2,Primefaces,我有一个托管bean,其中我有一个地址集合(每个客户机可能有N个地址),我有一个使用JSF(Primefaces)的表单,从中我发送一些数据填充一个对象(Endereco.java),并将这个对象添加到集合中 在发送数据后,我检查添加的对象,它具有它应该具有的所有属性,问题是在这之后,当我检查集合列表中的第一个对象时,它不在那里 有什么不对劲吗 MB中的操作: /** * Action to add the object endereco to the collection in this M

我有一个托管bean,其中我有一个地址集合(每个客户机可能有N个地址),我有一个使用JSF(Primefaces)的表单,从中我发送一些数据填充一个对象(Endereco.java),并将这个对象添加到集合中

在发送数据后,我检查添加的对象,它具有它应该具有的所有属性,问题是在这之后,当我检查集合列表中的第一个对象时,它不在那里

有什么不对劲吗

MB中的操作:

/**
 * Action to add the object endereco to the collection in this MB
 */
public void adicionarEndereco() {
    getRemetente().getEnderecos().add(endereco);

    limparEndereco();

    // At this point the collection is still the same it was before
    Collection<Endereco> addressList = getRemetente().getEnderecos();
    String logradouro = addressList.iterator().next().getLogradouro();
    System.out.println("String from the the property in the first item: " + logradouro); //

    // close dialog box
    if (true) {
        RequestContext.getCurrentInstance().execute("dlgEndereco.hide()");
    }
}
/**
*将对象endereco添加到此MB中的集合的操作
*/
公开无效adicionarEndereco(){
getremeentent().getEnderecos().add(endereco);
林帕伦德里科();
//在这一点上,收集仍然是一样的,它是以前
集合地址列表=GetRemente().getEnderecos();
字符串logradouro=addressList.iterator().next().getLogradouro();
System.out.println(“第一项中属性的字符串:“+logradouro”)//
//关闭对话框
如果(真){
RequestContext.getCurrentInstance().execute(“dlgEndereco.hide()”);
}
}
将数据发送到MB的xhtml代码:



有什么帮助吗?

bean的作用域是什么?@RequestScoped公共类remeentemb…addressList是remeentemb的字段吗?另外,也许可以尝试一个会话。是的,解决了我的问题。谢谢。除非是明确的会话内容,否则不要使用
SessionScope
。如果它是用于视图,那么在使用jsf-2时使用
@ViewScoped