ConversationScoped bean操作未使用呈现的commandlink触发

时间:2014-04-16 08:29:03

标签: java jsf scope rendered-attribute

我无法理解为什么我的ConversationScope&bean上的动作方法不会触发。豆是:

package org.work;

import java.io.Serializable;
import javax.enterprise.context.ConversationScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Named;

@Named
@ConversationScoped
public class NewClass implements Serializable {

    private static final long serialVersionUID = 6470665657635110586L;
    private boolean b1;

    public boolean isB1() {
        return b1;
    }

    public void setB1(boolean b1) {
        this.b1 = b1;
    }

    public void preRenderView(ComponentSystemEvent evt) {
    }

    public String peformAction() {
        return null;
    }
}

我的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">
    <f:view>
        <h:head>

        </h:head>
        <f:metadata>
            <f:viewParam name="b1"
                         value="#{newClass.b1}" />
            <f:event type="preRenderView"
                     listener="#{newClass.preRenderView}"/>
        </f:metadata>
        <h:body>
            <h:form>
                <h:commandLink action="#{newClass.setB1(!newClass.b1)}"
                               style="background-color:  #{newClass.b1 ? 'darkorchid' : 'aquamarine'};"
                               value="btn3"/>
                <h:panelGrid rendered="#{newClass.b1}"
                             columns="1">
                    <h:commandLink value="edit"
                                   action="#{newClass.peformAction()}" />
                </h:panelGrid>
            </h:form>
        </h:body>
    </f:view>
</html>

在按下应该反转布尔值的commandLink后,不会触发performAction()方法,使得另一个commandLink被渲染。调试时我可以看到布尔值设置为true,但在我看来,&#34;渲染&#34;在设置viewparams之前评估属性。这是真的? 该示例适用于@ManagedBean和@ javax.faces.bean.ViewScoped。

1 个答案:

答案 0 :(得分:0)

我认为你没有长时间的对话。您可以在此网站上阅读更多信息:http://docs.oracle.com/javaee/6/api/javax/enterprise/context/ConversationScoped.html

如果您有临时对话,则在每次请求后重新创建此bean