JSF CDI ViewExpiredException

时间:2016-08-23 15:02:29

标签: jsf cdi viewexpiredexception

我尝试使用jsf2和cdi设置一个简单的测试应用程序,它只显示一个由sessionScoped bean支持的数字,并且可以通过按钮增加。我的问题是如果单击按钮,我总是立即得到一个ViewExpiredException。 我在WEB-INF下有一个web.xml + faces-config.xml + beans.xml。还有什么可能是问题?

的index.xhtml

<!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">

<h:head></h:head>
<body>
    <h1>test</h1>
    <div id="content">#{bean.value}</div>

    <h:form>
        <h:commandButton value="++" action="#{bean.increase()}">
            <f:ajax render=":content" />
        </h:commandButton>
    </h:form>
</body>
</html>

TestBean.java

package at.risc.wbs;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import java.io.Serializable;

@SessionScoped
@Named("bean")
public class TestBean implements Serializable {
    private static final long serialVersionUID = 1L;

    private int value;

    @PostConstruct
    public void init() {
        this.value = 1;
    }

    public void increase() {
        this.value++;
    }

    public int getValue() {
        return this.value;
    }

    public void setValue(int value) {
        this.value = value;
    }
}

0 个答案:

没有答案