Deb
Deb

Reputation: 431

I can not change my selectOneMenu

I'm trying to load the selectOneMenu and gives the following exception: java.lang.IllegalStateException: Cannot create a session after the response has been committed. I have the xhtml:

<h:outputText value="Nome:" />
 <p:selectOneMenu value="" id="nome"  >
   <f:selectItem itemValue="#{solicitarPortabilidadeBean.listaDoadora}" var="doadora" itemLabel="#{doadora.nomeOperadora}"/>                
 </p:selectOneMenu>

the bean:

@ViewScoped
@ManagedBean
public class SolicitarPortabilidadeBean implements Serializable {

  private static final long serialVersionUID = 1L;  
  private List<Operadora> listaDoadora = null;
  private Operadora operadora;
//getters and setters

  @EJB
  private ConsultasSpnService consultaOp;   

  public List<Operadora> getListaDoadora() {

if (listaDoadora == null) {

 listaDoadora = new ArrayList<Operadora>();
 listaDoadora = consultaOp.listarOp();          

}   

return listaDoadora;
    }

public void setListaDoadora(List<Operadora> listaDoadora) {
    this.listaDoadora = listaDoadora;
}

public Operadora getOperadora() {
    return operadora;
}

public void setOperadora(Operadora operadora) {
    this.operadora = operadora;
}

public List<Eot> getListaEot() {
    return listaEot;
}

public void setListaEot(List<Eot> listaEot) {
    this.listaEot = listaEot;
}

public Eot getEot() {
    return eot;
}

public void setEot(Eot eot) {
    this.eot = eot;
}

public ConsultasSpnService getConsultaOp() {
    return consultaOp;
}

public void setConsultaOp(ConsultasSpnService consultaOp) {
    this.consultaOp = consultaOp;
}   

}

the Operadora class:

public class Operadora {
 private String srvprovid = null;   
 private String nomeOperadora = null;   
 private String indicadorFuncoes = null;
 private String funcaoSuporte = null;
 private String tipoTempReceptora = null;
 private String tipoTempDoadora = null;
 private String horaTrabSuportado = null;
 private Long qtdMaximaTn = null;
 private String tipoServico = null;
 //getters and setters
public String getSrvprovid() {
        return srvprovid;
    }
    public void setSrvprovid(String srvprovid) {
        this.srvprovid = srvprovid;
    }
    public String getNomeOperadora() {
        return nomeOperadora;
    }
    public void setNomeOperadora(String nomeOperadora) {
        this.nomeOperadora = nomeOperadora;
    }
    public String getIndicadorFuncoes() {
        return indicadorFuncoes;
    }
    public void setIndicadorFuncoes(String indicadorFuncoes) {
        this.indicadorFuncoes = indicadorFuncoes;
    }
    public String getFuncaoSuporte() {
        return funcaoSuporte;
    }
    public void setFuncaoSuporte(String funcaoSuporte) {
        this.funcaoSuporte = funcaoSuporte;
    }
    public String getTipoTempReceptora() {
        return tipoTempReceptora;
    }
    public void setTipoTempReceptora(String tipoTempReceptora) {
        this.tipoTempReceptora = tipoTempReceptora;
    }
    public String getTipoTempDoadora() {
        return tipoTempDoadora;
    }
    public void setTipoTempDoadora(String tipoTempDoadora) {
        this.tipoTempDoadora = tipoTempDoadora;
    }
    public String getHoraTrabSuportado() {
        return horaTrabSuportado;
    }
    public void setHoraTrabSuportado(String horaTrabSuportado) {
        this.horaTrabSuportado = horaTrabSuportado;
    }
    public Long getQtdMaximaTn() {
        return qtdMaximaTn;
    }
    public void setQtdMaximaTn(Long qtdMaximaTn) {
        this.qtdMaximaTn = qtdMaximaTn;
    }
    public String getTipoServico() {
        return tipoServico;
    }
    public void setTipoServico(String tipoServico) {
        this.tipoServico = tipoServico;
    }

I know the error is in calling the bean inside the xhtml, but I tried everything I knew. Can anyone help me?

Thank you!!!

Upvotes: 0

Views: 158

Answers (2)

BalusC
BalusC

Reputation: 1109635

Apart from severe logic errors in the code, which should in turn however not have thrown any exception during rendering at all, for sure not particularly the mentioned exception,

IllegalStateException: Cannot create a session after the response has been committed

your concrete problem is most likely caused by a bug in Mojarra which is fixed in Mojarra 2.1.8. This bug can manifest when a view scoped or session scoped bean is referenced for the first time "late" in a relatively large JSF page, long after the response has been committed.

View and session scoped beans needs to be stored in the HTTP session. For that, the HTTP session needs to be created first, if not done yet (e.g. first-time request). For that, a cookie needs to be put on the HTTP response headers first. For that, the response should not have been sent to the client at all. The default response buffer size is usually 2KB, so if a page is larger than 2KB and the view or session scoped bean is referenced for the first time after the first piece of 2KB, then you will get exactly this exception.

Upgrade to at least Mojarra 2.1.8 (it's currently already at 2.1.13) and this problem should disappear.

See also:

Upvotes: 2

benz
benz

Reputation: 4629

Firs of all, here is one syntax problem with your code

<h:outputText value="Nome:" />
 <p:selectOneMenu value="" id="nome"  >
   <f:selectItem itemValue="#{solicitarPortabilidadeBean.listaDoadora}" var="doadora" itemLabel="#{doadora.nomeOperadora}"/>                
 </p:selectOneMenu>

You are not binding the value attribute to the backing bean. Additionally IllegalStateException comes when you have already committed the response, means written something, committed it and then passed the control to another servlet or something. Before seeing at the proper ManagedBean code, it is hard to tell where you are mistaking. How is your list getting populated. Please post the ManagedBean code and try to map the value attribute to some ManagedBean property. HTH, Ben

Upvotes: 0

Related Questions