在rich:dataTable中使用h:commandLink时警告JSF1095 [英] Warning JSF1095 while using a h:commandLink inside a rich:dataTable

查看:178
本文介绍了在rich:dataTable中使用h:commandLink时警告JSF1095的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

警告:JSF1095:在我们尝试为闪存设置传出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;
    }


}

解决方案

此问题与表脚注中的<rich:dataScroller>有关.当我删除它时,一切正常.

我已在 RichFaces问题跟踪程序中进行了检查, t.您可能需要考虑在问题中重新编写代码的最小示例(几个列,标头和属性是不必要的,并且使代码不必要地变大,因此将其删除)在新问题报告中.

I have a h:commandLink inside rich:dataTable. When I click on the command link, I'm adding a FacesMessage to the context and redirecting to the same message. I have a h:messages tag on the page to display any faces messages. I am able to display the message, but I'm getting following warning and the messages are not getting cleared.

WARNING: JSF1095: The response was already committed by the time we tried to set the outgoing cookie for the flash. Any values stored to the flash will not be available on the next request.

I am using JSF2.0, RF4.0.0.Final. Following is the code

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

/* * To change this template, choose Tools | Templates * and open the template in the editor. */

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;
    }


}

解决方案

This problem is related to the <rich:dataScroller> which you've there in your table footer. When I removed it, everything works as expected.

I checked around in RichFaces issue tracker if this bug is known, but it apparently isn't. You may want to consider to repost a minimal example of your code as you've in the question (several columns, headers and attributes are unnecessary and makes code unnecessarily large, so trim them away) in a new issue report over there.

这篇关于在rich:dataTable中使用h:commandLink时警告JSF1095的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆