【问题标题】:Warning JSF1095 while using a h:commandLink inside a rich:dataTable在 Rich:dataTable 中使用 h:commandLink 时发出警告 JSF1095
【发布时间】:2011-11-13 22:17:09
【问题描述】:

我在rich:dataTable 中有一个h:commandLink。当我单击命令链接时,我将 FacesMessage 添加到上下文并重定向到相同的消息。我在页面上有一个h:messages 标签来显示任何面孔消息。我能够显示消息,但我收到以下警告并且消息没有被清除。

警告:JSF1095:在我们尝试为 flash 设置传出 cookie 时,响应已经提交。存储到闪存中的任何值在下一次请求时都将不可用。

我正在使用 JSF2.0、RF4.0.0.Final。以下是代码

index.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:rich="http://richfaces.org/rich">
<h:head>
    <title>DataTable Test</title>
</h:head>
<h:body>
    <h:form prependId="false">
        <rich:panel header="Data table test">
            <br/><br/>
            <rich:dataTable id="dTable" value="#{myBean.allInventory}" var="inv" style="margin: auto; width: 100%; min-width: 750px;"
                            rows="10" onrowmouseover="this.style.backgroundColor='#A0A0A0'"
                            onrowmouseout="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Sl No" />
                    </f:facet>
                    <h:outputText value="#{inv.slno}" />
                </rich:column>
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Item 1" />
                    </f:facet>

                    <h:commandLink id="docMessage" title="Click for details" action="#{myBean.cLink(inv)}" value="#{inv.item1}"/>
                </rich:column>
                <rich:column>
                    <f:facet name="header">
                        <h:outputText value="Item 2" />
                    </f:facet>
                    <h:outputText value="#{inv.item2}" />
                </rich:column>
                <f:facet name="footer">
                    <rich:dataScroller id="dataScroll" for="dTable"/>
                </f:facet>
            </rich:dataTable>

            <h:messages id="messages" globalOnly="true" layout="table" ></h:messages>
        </rich:panel>
    </h:form>
</h:body>

MyBean.java

package com.mypkg;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Named;

@Named
@SessionScoped
public class MyBean implements Serializable {

private List<Inventory> allInventory = null;

/**
 * @return the allInventory
 */
public List<Inventory> getAllInventory() {
    if (allInventory == null) {
        allInventory = new ArrayList<Inventory>();
        for (int i = 0; i < 100; i++) {
            Inventory e = new Inventory();
            e.setSlno(i + 1);
            e.setItem1("Item1" + Math.random());
            e.setItem2("Item2" + Math.random());
            allInventory.add(e);
        }
    }
    return allInventory;
}

public String cLink(Inventory inv) {
    FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Sample Error Message", "Sample Error Message"));
    return "index?faces-redirect=true";
}

/**
 * @param allInventory the allInventory to set
 */
public void setAllInventory(List<Inventory> allInventory) {
    this.allInventory = allInventory;
}

}

Inventory.java

/* * 要更改此模板,请选择工具 |模板 * 并在编辑器中打开模板。 */

package com.mypkg;

public class Inventory {

    private int slno;
    private String item1;
    private String item2;

    /**
     * @return the slno
     */
    public int getSlno() {
        return slno;
    }

    /**
     * @param slno the slno to set
     */
    public void setSlno(int slno) {
        this.slno = slno;
    }

    /**
     * @return the item1
     */
    public String getItem1() {
        return item1;
    }

    /**
     * @param item1 the item1 to set
     */
    public void setItem1(String item1) {
        this.item1 = item1;
    }

    /**
     * @return the item2
     */
    public String getItem2() {
        return item2;
    }

    /**
     * @param item2 the item2 to set
     */
    public void setItem2(String item2) {
        this.item2 = item2;
    }


}

【问题讨论】:

  • 什么 JSF impl/version?对我来说似乎是一个错误。尝试升级到最新版本或更换 impl。顺便说一句,您有点暗示它仅在rich:dataTable 中失败,您能确认一下吗? IE。当命令链接放在rich:dataTable 之外时,它工作得很好吗?
  • @BalusC 我正在使用 JSF 2.0、JSTL 1.1(NetBeans 6.9.1 附带的框架)。当我将命令链接放在rich:dataTable 之外时,它不会显示警告消息。我已经像&lt;h:commandLink value="Check" action="#{myBean.linkTest}" /&gt; 这样添加了它,在MyBean.java 中,我添加了一个与方法cLink(Inventory inv) 具有相同主体的方法linkTest()
  • "JSF 2.0" 只是一个规范版本。您使用的是什么 impl/version?例如,Mojarra 2.0.6?它应该在服务器启动日志中可见,或者通过提取 JAR 并读取清单文件。至于问题,这很有趣。您可以尝试使用h:dataTable/h:column 而不是rich:xxx 吗?这样我们就可以排除标准 JSF 或 RichFaces 的嫌疑。
  • 我正在使用 Mojarra 2.1.3 (FCS b02)。我试过h:dataTable,它没有显示警告信息。
  • @Java 谢谢,我接受了答案

标签: jsf-2 richfaces flash-scope


【解决方案1】:

经过长时间的调试,我找到了适合我的情况的 100% 工作解决方案。 Glassfish 对输出流进行分块,每个块分别提交。但是在第一个块被提交后,ELFlash 实现认为,整个响应被提交并决定失败......

在 glassfish 中禁用分块后,所有问题都消失了。 http://www.dirkreske.de/jsf1095-with-glassfish-3-1/

问候 德克

【讨论】:

    【解决方案2】:

    此问题与您在表格页脚中的&lt;rich:dataScroller&gt; 有关。当我删除它时,一切都按预期工作。

    我检查了RichFaces issue tracker 是否知道此错误,但显然不是。您可能需要考虑在新的问题报告中重新发布您在问题中的代码的最小示例(几个列、标题和属性是不必要的,并且使代码不必要地大,因此将它们修剪掉)在那里的新问题报告中。

    【讨论】:

    • 非常感谢。我会重新发布它并进行必要的更改。
    • 嗨,我不是要在这里转贴,而是在 RichFaces 问题跟踪器上转贴:) 点击我答案中的链接。
    • 糟糕,抱歉。我会将其发布在 RichFaces 问题跟踪器中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 2019-11-23
    相关资源
    最近更新 更多