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

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).

Thanks,

Rafael Afonso

Portlet configuration:


   <portlet>
        <portlet-name>CargaUsuarios</portlet-name>
        <display-name>CargaUsuarios</display-name>
        <portlet-class>com.ibm.faces20.portlet.FacesPortlet</portlet-class>
        <init-param>
            <name>com.ibm.faces.portlet.page.view</name>
            <value>/pages/carga/cargaUsuarios.jsp</value>
        </init-param>
        <init-param>
            <name>wps.markup</name>
            <value>html</value>
        </init-param>
        <expiration-cache>0</expiration-cache>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>view</portlet-mode>
        </supports>
        <portlet-info>
            <title>Carga de Usuarios</title>
            <short-title>Carga deUsuarios</short-title>
            <keywords>Carga Usuario</keywords>
        </portlet-info>
    </portlet>

Manged Bean:


   @ManagedBean(name = "cargaUsuariosMB")
    @RequestScoped
    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="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
    <%@taglib
        uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model"
        prefix="portlet-client-model"%>
    <%@page language="java" contentType="text/html"
        pageEncoding="ISO-8859-1" session="false"%>

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

    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
      Rafonso
      2 Posts
      ACCEPTED ANSWER

      Re: Request scope issue in IBM portal 8.0

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

      Mark:

       

      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>          
          ...
      </f:view>

      Manged Bean:

      @ManagedBean(name = "cargaUsuariosMB")
      @SessionScopedpublic
      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)) {
                  clean();       
              }
          }
             // 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