My current platform is NB 7 rc 1 and I have a JSF 2 app with just one “managed bean”. In time, I’m using Tomcat 7.0.34.
Here is the code where the error occurs:
@ManagedBean
@SessionScoped
public class CopyController implements Serializable {
private static final long serialVersionUID = 1L;
private String pathBancoSentencas;
private List<Arquivo> arquivosUpload;
private HttpSession session;
private List<String> listaPdfs;
public List<Arquivo> getArquivosUpload() {
return arquivosUpload;
}
public void setArquivosUpload(List<Arquivo> arquivosUpload) {
this.arquivosUpload = arquivosUpload;
}
public CopyController() {
arquivosUpload = new ArrayList<Arquivo>();
}
@PostConstruct
public void doInit() {
session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
pathBancoSentencas = (String)session.getAttribute("DIRETORIO_TRABALHO");
}
And after processing the request, the routine calls a view like this:
<p:dataTable value="#{copyController.arquivosUpload}" var="arquivo" paginator="true" paginatorPosition="bottom"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}">
<f:facet name="header">
Item processado
</f:facet>
<h:column>
<h:outputText value="#{arquivo.nome}" />
</h:column>
</p:dataTable>
However, the view is not displayed and this error occurs:
Caused by: java.lang.NullPointerException
at br.jus.tjmg.dspace.copy.CopyController.doInit(CopyController.java:54)
... 70 more
Can someone help me?
Thanks!
From your
doInit()method,This returns
nullif the session is currently not been created yet. But yet you’re explicitly expecting a non-nullsession in the next line.You need to pass
trueto trigger autocreate.See also the javadoc (emphasis mine):
Unrelated to the concrete problem, that whole
doInit()method is unnecessary and can be replaced by a@ManagedProperty:Or, if you’re absolutely positive that you need do to it in the
doInit(), a nicer way is to get it fromExternalContext#getSessionMap()instead.You should try to avoid
javax.servlet.*imports in your JSF backing bean.