2011-09-09 39 views
1

我有一个h:commandLinkrich:dataTable。当我点击命令链接时,我添加了一个FacesMessage到上下文并重定向到相同的消息。我在页面上有一个h:messages标签来显示任何脸部信息。我能够显示该消息,但我收到以下警告,并且消息未被清除。同时使用1 H警告JSF1095:commandLink内丰富:dataTable的

警告:JSF1095:响应已通过我们试图为闪存传出饼干时提交。存储到闪存中的任何值都将在下一个请求中不可用。

我使用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; 
    } 


} 
+0

什么JSF IMPL /版本?对我来说看起来像一个bug。尝试升级到最新版本或替换impl。顺便说一句,你有点暗示它只在'rich:dataTable'中失败,你能证实吗?即当命令链接放在'rich:dataTable'之外时它是否工作得很好? – BalusC

+0

@BalusC我正在使用JSF 2.0,JSTL 1.1(NetBeans 6.9.1附带的框架)。当我将命令链接放在'rich:dataTable'之外时,它不显示警告消息。我已经添加了这个'',并且在MyBean.java中添加了一个方法'linkTest()',它具有相同的主体作为'cLink(Inventory inv)'方法' – Praneeth

+0

“JSF 2.0”只是一个spec版本。你使用的是什么impl/version?例如Mojarra 2.0.6?它应该在服务器启动日志中可见或以其他方式通过提取JAR并读取清单文件。至于这个问题,这很有趣。你可以尝试使用'h:dataTable' /'h:column'而不是'rich:xxx'吗?这样我们可以排除标准的JSF或RichFaces被怀疑。 – BalusC

回答

1

这个问题是关系到你在你的表格页脚过那里的<rich:dataScroller>。当我删除它时,一切都按预期工作。

RichFaces issue tracker检查周围是否这个错误是已知的,但它显然不是。你可能要考虑你的问题已经重新发布代码的一个小例子,(几个栏目,标头和属性是不必要的,使代码不必要的大,所以修剪他们离开)在一个新的问题报告在那边。

+0

非常感谢。我将通过必要的更改重新发布。 – Praneeth

+0

嗨,我不是故意重新发布它在这里,但在那里的RichFaces问题跟踪:)点击我的答案中的链接。 – BalusC

+0

哎呀,对不起。我会将它发布在RichFaces问题跟踪器中。 – Praneeth

1

很长一段时间调试完毕后,我发现我的情况下,100%有效的解决方案。 Glassfish将输出流分块,并且每个块都单独提交。但在第一个块被提交之后,ELFlash实现认为整个响应被提交并决定失败...

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

电贺 德克