Jsf richfaces 4.2再次调用了构造后方法,可以很好地处理myfaces

Jsf richfaces 4.2再次调用了构造后方法,可以很好地处理myfaces,jsf,Jsf,在包含多个表单的页面中,我看到了和的不同行为 这是我的后盾: import javax.annotation.PostConstruct; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; @ManagedBean @ViewScoped public class MultiFormBean { String inputText1 = ""; String inputText2 =

在包含多个表单的页面中,我看到了和的不同行为

这是我的后盾:

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class MultiFormBean
{
    String inputText1 = "";
    String inputText2 = "";

    @PostConstruct
    public void initializeBean(){
        System.out.println("PostConstruct Called ------------------");
    }

    public String getInputText1()
    {
        return inputText1;
    }

    public void setInputText1(String inputText1)
    {
        this.inputText1 = inputText1;
    }

    public String getInputText2()
    {
        return inputText2;
    }

    public void setInputText2(String inputText2)
    {
        this.inputText2 = inputText2;
    }

    public void doSubmit1() {
        inputText2 = inputText1;
    }

    public void doSubmit2() {
        inputText1 = inputText2;
    }

}
当我使用以下xhtml时,多次单击Submit1和Submit2都不会多次调用@PostConstruct:

    <h:body>
        <h:form id="firstForm" prependId="false">
            <h:panelGroup layout="block" id="renderTarget1"/>
            <h:inputText id="first_input" value="#{multiFormBean.inputText1}"/>
            <h:commandButton id="click1" action="#{multiFormBean.doSubmit1}" value="submit1" type="submit"
                             onclick="javascript:jsf.ajax.request(this, event, {execute:'firstForm', render:'renderTarget1 secondForm'}); return false;">
            </h:commandButton>
        </h:form>
        <h:form id="secondForm" prependId="false">
            <h:panelGroup layout="block" id="renderTarget2"/>
            <h:inputText id="second_input" value="#{multiFormBean.inputText2}"/>
            <h:commandButton id="click2" action="#{multiFormBean.doSubmit2}" value="submit2" type="submit"
                             onclick="javascript:jsf.ajax.request(this, event, {execute:'secondForm', render:'renderTarget2 firstForm'}); return false;">

            </h:commandButton>

        </h:form>       
</h:body>
    <h:body>
        <h:form id="firstForm" prependId="false">
            <h:panelGroup layout="block" id="renderTarget1"/>
            <h:inputText id="first_input" value="#{multiFormBean.inputText1}"/>
<a4j:commandButton id="click1" action="#{multiFormBean.doSubmit1}" value="submit1" type="submit" execute="@form" render="renderTarget1,secondForm"/>
        </h:form>
        <h:form id="secondForm" prependId="false">
            <h:panelGroup layout="block" id="renderTarget2"/>
            <h:inputText id="second_input" value="#{multiFormBean.inputText2}"/>

            <a4j:commandButton id="click2" action="#{multiFormBean.doSubmit2}" value="submit2" type="submit" execute="@form" render="renderTarget2,firstForm"/> 


        </h:form>       
    </h:body>
但以下xhtml会多次调用@PostConstruct:

    <h:body>
        <h:form id="firstForm" prependId="false">
            <h:panelGroup layout="block" id="renderTarget1"/>
            <h:inputText id="first_input" value="#{multiFormBean.inputText1}"/>
            <h:commandButton id="click1" action="#{multiFormBean.doSubmit1}" value="submit1" type="submit"
                             onclick="javascript:jsf.ajax.request(this, event, {execute:'firstForm', render:'renderTarget1 secondForm'}); return false;">
            </h:commandButton>
        </h:form>
        <h:form id="secondForm" prependId="false">
            <h:panelGroup layout="block" id="renderTarget2"/>
            <h:inputText id="second_input" value="#{multiFormBean.inputText2}"/>
            <h:commandButton id="click2" action="#{multiFormBean.doSubmit2}" value="submit2" type="submit"
                             onclick="javascript:jsf.ajax.request(this, event, {execute:'secondForm', render:'renderTarget2 firstForm'}); return false;">

            </h:commandButton>

        </h:form>       
</h:body>
    <h:body>
        <h:form id="firstForm" prependId="false">
            <h:panelGroup layout="block" id="renderTarget1"/>
            <h:inputText id="first_input" value="#{multiFormBean.inputText1}"/>
<a4j:commandButton id="click1" action="#{multiFormBean.doSubmit1}" value="submit1" type="submit" execute="@form" render="renderTarget1,secondForm"/>
        </h:form>
        <h:form id="secondForm" prependId="false">
            <h:panelGroup layout="block" id="renderTarget2"/>
            <h:inputText id="second_input" value="#{multiFormBean.inputText2}"/>

            <a4j:commandButton id="click2" action="#{multiFormBean.doSubmit2}" value="submit2" type="submit" execute="@form" render="renderTarget2,firstForm"/> 


        </h:form>       
    </h:body>
有人能帮我用这个代替吗


我还发现我不能用4j commandButton调用doSubmit2方法,我认为这里的问题在于JSF2和Richfaces4中的bug。从4个版本开始,Richfaces开始使用JSF嵌入式ajax功能。在页面上使用多个表单和ajax请求时存在一个错误。问题在于richfaces使用当前渲染视图状态的id渲染特殊隐藏输入。渲染新视图时,此id将更改。它也会随每个请求一起提交,以表明它属于某个特定视图。因此,当您在第一次ajax请求后在同一页面上有多个表单时,视图状态将得到错误的位置,并且不能再次提交。有时行为看起来非常古怪,没有逻辑描述

PostConstruct被调用了两次,因为服务器认为两个请求属于不同的视图视图状态不是sumbit,并且就bean的视图范围而言,它被创建了两次。单击周围的图标后,ajax完全可以停止使用它,因为服务器无法识别视图,当您无法单击第二个提交按钮时,可能会看到什么


首先,我建议您使用最新版本的JSF和Richfaces。这个bug和更多的bug可能已经修复。

而且我发现我不能用4J commandButton调用doSubmit2方法