IBM Portal 8.0中的请求范围问题

时间:2013-07-04 14:20:21

标签: jsf-2 portlet websphere-portal jsr286

我在Websphere Portal Server 8.0中运行了一个JSR 286 portlet。在那里,我做了一个文件上传,并在显示处理结果后。最初,负责处理此文件的托管bean具有请求范围(@RequestScoped)。当我单击命令按钮上传文件时,MB中的方法正确处理并填充必须在JSP页面中显示的结果集合(下面的MB中的dadosCarga属性)。但是,当我重新构建页面时,我得到了一个堆栈跟踪,解释我找不到我的Managed Bean类(ClassNotFoundException)并且没有显示结果。我使用ViewScoped得到了相同的结果。就在我将范围从Request更改为Session(@SessionScoped)时,显示结果。

在我googled得到答案后,我发现this page解释了Portlet中动作和渲染请求之间的区别。有人建议使用JSF Portlet bridge。但是,此页面不再有效。有Portlet bridge for Apache Myfaces(IBM门户网站在MyFaces上运行)。但是,我看不出怎么用它。它只是将两个罐子(api和实现)放在WEB-INF / lib中吗?我试过,但是当我尝试在应用程序中加载页面时,我遇到了异常。所以我删除它们。

下面,我将展示My Portlet配置,Managed Bean和JSP页面。有没有其他选择,更好的想法如何处理这个?或者可能是关于如何使用correclty MyFaces Bridge的解释(我在其主页中找不到任何内容)。

谢谢,

Rafael Afonso

Portlet配置

<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页面(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>

4 个答案:

答案 0 :(得分:1)

请尝试在portlet.xml中添加以下内容,看看它是否有效:

<container-runtime-option>
    <name>javax.portlet.actionScopedRequestAttributes</name>
    <value>true</value>
</container-runtime-option>

有关详细信息,请下载并查看Portlet V2.0规范中的以下部分: PLT.10.4.4运行时选项 javax.portlet.actionScopedRequestAttributes

答案 1 :(得分:0)

您对渲染和操作请求是正确的,JSF(或CDI)请求和ViewScoped无法正常工作。但解决方案可能是使用包含全新范围的JBoss Portlet Bridge - PortletLifecycleScoped和PortletRedisplayScoped。第一个行为与RequestScope完全相同,您可以在docs中找到更多信息。但是,我不确定是否能够在除GateIn之外的其他门户中使用这些范围。

答案 2 :(得分:0)

使用请求范围时,需要将数据从portlet操作传送到portlet呈现阶段。数据通常通过portlet为请求范围bean携带,呈现参数是一个String。为了保存您的数据,您的对象需要是Serializable。

除此之外,您可能希望将WebSphere Portal下的WebSphere Application Server升级到V8.0.0.6以避免PM79460和Portal本身也使用最新的FixPack。

希望这有帮助。

BTW:JSR286和JEE6没有规定CDI如何与Portlet编程模型交互。您可能希望查看JSR362

答案 3 :(得分:0)

IBM使用自己的portlet桥。除此之外,不建议使用任何桥梁。