1

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


}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Praneeth
  • 1,457
  • 5
  • 23
  • 36
  • What JSF impl/version? Looks like a bug to me. Try upgrading to latest or replacing the impl. By the way, you're a bit insinuating that it fails in `rich:dataTable` only, can you confirm this? I.e. does it work perfectly fine when the command link is placed outside `rich:dataTable`? – BalusC Sep 09 '11 at 16:04
  • @BalusC I'm using JSF 2.0, JSTL 1.1 (framework that comes with NetBeans 6.9.1). When I placed the command link outside `rich:dataTable`, it doesn't show the warning message. I have added it like this `` and in `MyBean.java`, I added a method `linkTest()` that has same body as method `cLink(Inventory inv)` – Praneeth Sep 09 '11 at 16:29
  • "JSF 2.0" is just a spec version. What impl/version are you using? Mojarra 2.0.6, for example? It should be visible in server startup log or otherwise by extracting the JAR and reading the manifest file. As to the problem, that's interesting. Can you try using `h:dataTable`/`h:column` instead of `rich:xxx` ones? This way we can exclude standard JSF or RichFaces from being suspect. – BalusC Sep 09 '11 at 16:32
  • I am using Mojarra 2.1.3 (FCS b02). I tried with `h:dataTable`, it doesn't show the warning message. – Praneeth Sep 09 '11 at 17:01
  • And the flash scope worked fine? (i.e. the message in flash is been shown after redirect). Well, now that look like a RichFaces specific bug. – BalusC Sep 09 '11 at 17:01
  • Yes, flash scope worked fine. Earlier, the messages were not getting cleared (i.e. if I click command link 3 times then it was showing all the 3 messages with 3 warnings) – Praneeth Sep 09 '11 at 17:09
  • Sorry, I can't reproduce your problem. It works fine for me with `` of RF 4.0.0 Final, Mojarra 2.1.3 on Tomcat 7.0.19. Do you have any additional filters in `web.xml`? – BalusC Sep 09 '11 at 17:26
  • I don't have any additional filters. I'm using GF 3.1.1, I don't think that will be an issue. Btw.. my `web.xml` has `javax.faces.PROJECT_STAGE` as `Production` and `org.ajax4jsf.VIEW_HANDLERS` as `com.sun.facelets.FaceletViewHandler`, apart from these I have `FacesServlet` and session timeout. – Praneeth Sep 09 '11 at 17:54
  • `org.ajax4jsf.*` stuff in `web.xml` is RichFaces 3.x specific, but you're using RichFaces 4.x. Plus, `com.sun.facelets.FaceletViewHandler` is Facelets 1.x specific, but you're using JSF/Facelets 2.x. Remove them. It won't solve the problem as those context params are ignored in RichFaces 4.x anyway. I retried on Glassfish 3.1, I cannot reproduce your problem, so I don't know. At least, Flash is cookie based. Try clearing browser's cookies on the domain. Try different browsers. I tested on FF6, GC13 and IE9. – BalusC Sep 09 '11 at 18:14
  • I tried on different browsers, but the result stays same. FYI I'm using following jars `richfaces-components-api-4.0.0.Final.jar`, `richfaces-components-ui-4.0.0.Final.jar`, `richfaces-core-api-4.0.0.Final.jar`, `richfaces-core-impl-4.0.0.Final.jar`, `sac-1.3.jar`, `cssparser-0.9.5.jar`, `guava-r09.jar`. Are you using the same code that I posted? – Praneeth Sep 09 '11 at 18:33
  • Oh sorry, I overlooked the `` in the bottom. When I added it, I was able to reproduce the problem. – BalusC Sep 09 '11 at 18:50
  • @Java Thanks for your advice. I overlooked the option "Was this post useful to you?". I thought of voting the answer, but as I don't have enough points to vote, it denied me. Let me know if I am missing anything else. – Praneeth Sep 12 '11 at 15:13
  • 1
    @Java Thanks, I accepted the answer – Praneeth Sep 13 '11 at 16:33

2 Answers2

1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

after long time debugging, I've found a 100% working solution for my case. Glassfish chunks the output stream and each chunk is commited separately. But after the first chunk is commited, the ELFlash implementation thinks, the whole response is commited and decides to fail...

After disabling chunking in glassfish, all problems are gone. http://www.dirkreske.de/jsf1095-with-glassfish-3-1/

Greets Dirk

Dirk
  • 203
  • 1
  • 2
  • 10