Zim
Zim

Reputation: 1483

MyFaces doesn't append javax.faces.ViewState back on ajax update of stateless view

I'm experiencing some trouble running multiple times the same ajax request that updates its enclosing form with stateless JSF (MyFaces 2.2.8 + CDI OpenWebBeans 1.2.7 running on Tomcat 7).

Here is an SSCCE that will depict the issue better than words. Let's consider a simple form with both an inputText and an outputText bound to a bean parameter. Submitting the form just displays the value next to the inputText field.

test.xhtml

<!DOCTYPE html>
<html lang="fr" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">
<f:view transient="true">
    <h:head>
        <title>Test</title>
    </h:head>
    <h:body>
        <h:form>
            <h:inputText value="#{testBean.txt}" />
            <h:outputText value="#{testBean.txt}" />
            <h:commandButton value="Submit">
                <f:ajax execute="@form" render="@form" />
            </h:commandButton>
        </h:form>
    </h:body>
</f:view>
</html>

TestBean.java

@Named
@RequestScoped
public class TestBean {
    private String txt;

    public String getTxt() {
        return txt;
    }

    public void setTxt(String txt) {
        this.txt = txt;
    }
}

Could hardly be simpler! When submitting a value the first time, it is working as expected and the output is displayed. But when it is submitted another time (no matter what the value is), the inputText and outputText fields are emptied (and the setter is not called).

In fact, what's happening is that the <input type="hidden" autocomplete="off" value="stateless" id="j_id__v_0:javax.faces.ViewState:1" name="javax.faces.ViewState"> that's initially added to the form is not put back in the partial rendering. And when it's added manually to the DOM, the ajax request is working again.

Is this behaviour expected or is it a bug? Is there any workaround?

Thanks!

-- Zim

Upvotes: 4

Views: 1135

Answers (1)

BalusC
BalusC

Reputation: 1109372

Reproduced. This is indeed a MyFaces bug. It works on Mojarra (tested with 2.2.11).

You can't do much else than reporting the bug to MyFaces guys. So I did: issue 3992.

Upvotes: 4

Related Questions