2 replies Latest Post - ‏2013-07-05T11:00:33Z by Rafonso
2 Posts

Pinned topic Request scope issue in IBM portal 8.0

‏2013-07-04T16:34:16Z |

I have a JSR 286 portlet running in a Websphere Portal Server 8.0. There, I do a file upload and after show the results of processing. Initially my managed bean responsible to process this file has a Request Scope (@RequestScoped). When I Click in command button to upload file, the method in MB process correctly and fills a collection of results (dadosCarga attribute in MB below) that must be showed in JSP page. However, when I the page is rederized I got a stacktrace explaining that my Managed Bean class was not found (ClassNotFoundException) and results are not shown. I got the same results using ViewScoped. Just when I changed scope from Request to Session (@SessionScoped), the results are shown.

After I googled for some answer, I found this page explaining about difference between action and render request in Portlets. It was suggested to use JSF Portlet bridge. However, this page is not active anymore. There is a Portlet bridge for Apache Myfaces (IBM portal runs over MyFaces). However, I could not see how use it. Is it just put both jars (api and implementation) in WEB-INF/lib? I tried, but I got a exception when I tried load the pages in application. So I remove them.

Below, I show My Portlet configuration, Managed Bean and JSP page. Is there any alternative, a better Idea about how to deal with this? Or may be a explanation about how to use correclty MyFaces Bridge (I could not found none in its home page).


Rafael Afonso

Portlet configuration:

            <title>Carga de Usuarios</title>
            <short-title>Carga deUsuarios</short-title>
            <keywords>Carga Usuario</keywords>

Manged Bean:

   @ManagedBean(name = "cargaUsuariosMB")
    public class CargaUsuariosMB extends AbstractMB {

        private String nomeArquivo;    // FIle name

        private Collection<CargaUsuarioInfoBean> dadosCarga; // processing result.

        public String doUploadArquivo() {
            this.dadosCarga = ... // process file and receives a collection

            this.nomeArquivo = ... // get uploaded file name

            return null; // Return to same origin page
        // Getters...


JSP page (cargaUsuarios.jsp):

   <%@taglib uri="" prefix="c"%>
    <%@taglib uri="" prefix="f"%>
    <%@taglib uri="" prefix="h"%>
    <%@taglib uri="" prefix="portlet"%>
    <%@page language="java" contentType="text/html"
        pageEncoding="ISO-8859-1" session="false"%>

    <portlet:defineObjects />
        <portlet-client-model:require module="ibm.portal.xml.*" />
        <portlet-client-model:require module="ibm.portal.portlet.*" />
        <h2>Carga de Usuários</h2>
        <h:form enctype="multipart/form-data">
                <label for="arquivoCarga"> <span>File:</span> </label> <input
                    type="file" name="arquivoCarga" id="FileCarga" />
            <br />
            <br />
            <h:commandButton value="Salvar File"
        <h:panelGroup id="pnlProcessamento"
            rendered="#{not empty cargaUsuariosMB.dadosCarga }">
                value="Dados do File #{cargaUsuariosMB.nomeArquivo} processados com sucesso."></h:outputText>
            <br />
            <h:dataTable id="tblDadosProcessamento"
                value="#{cargaUsuariosMB.dadosCarga}" var="dadosCarga"
                styleClass="dadosProcessamento" width="100%" border="1">
                <%-- Show processing results. --%>
        <h:messages styleClass="messages" id="msgsPesquisaCadastro"
            errorClass="mensagensErro" errorStyle="color: red;"></h:messages>
  • Mark_Winton
    110 Posts

    Re: Request scope issue in IBM portal 8.0

    ‏2013-07-05T09:06:00Z  in response to Rafonso

    You managed bean class should implement the Serializable interface, and you'll need to ensure that your CargaUsuarioInfoBean class and any other referenced classes also implement Serializable. This may explain why switching to @SessionScoped fixes the issue, as Portal may be holding onto the bean in memory rather than trying to serialize it.

    If that doesn't fix anything it may help if you post the source of the AbstractMB class - in particular does it have a default constructor? If my memory serves correctly an exception being thrown during a managed bean's constructor can cause a ClassNotFoundException to be thrown.

    Final note, you shouldn't need to include the portlet bridge jar in your project, as Portal provides this for you - the only thing to be aware of is how the portal request lifecycle and JSF request lifecycle sync up, but even that shouldn't cause you problems 99% of the time.

    • Rafonso
      2 Posts

      Re: Request scope issue in IBM portal 8.0

      ‏2013-07-05T11:00:33Z  in response to Mark_Winton



      Firstly, thanks for your reply. Both CargaUsuarioInfoBean and AbstractMB implment Serializable. Also, AbstractMB has a a default constructor.

      I did a workaround to clean my Managed Bean attributes and consequently remove them from session. In <h:view> tag a added a afterPhase attibute calling a method from Managed bean. In this method, after RENDER_RESPONSE, I clean attributes.

      JSP page (cargaUsuarios.jsp):

      <f:view afterPhase="#{cargaUsuariosMB.processarEvento }">
          <h2>Carga de Usuários</h2>          

      Manged Bean:

      @ManagedBean(name = "cargaUsuariosMB")
      class CargaUsuariosMB extends AbstractMB {
          private void clean() {
              this.dadosCarga = null;
              this.nomeArquivo = null;   
          public void processarEvento(PhaseEvent evento) {
              if (evento.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
             // Rest of code ...

      After Render response phase the page is already ready (with nomeArquivo and dadosCargaalready already used). Consequently, it is safe clean them.

      Updated on 2013-07-05T11:15:22Z at 2013-07-05T11:15:22Z by Rafonso