Jsf 2 嵌套在ui中的操作:repeat重新创建viewscoped bean,而不是导航离开

Jsf 2 嵌套在ui中的操作:repeat重新创建viewscoped bean,而不是导航离开,jsf-2,Jsf 2,我有一个带有两个p:CommandButton的h:form。一个按钮嵌套在ui内:在组件内重复。ui:include外部的按钮似乎可以正确导航到操作方法返回的目标目标。但是,嵌套在ui:include和ui:repeat中的相同按钮似乎会重新初始化视图范围的bean,而不是导航到操作目标。有人有解释、解决方案或变通方法吗 代码大致如下。mybean是视图范围的 <h:form id="myform"> <p:commandButton value="DoIt" action=

我有一个带有两个p:CommandButton的h:form。一个按钮嵌套在ui内:在组件内重复。ui:include外部的按钮似乎可以正确导航到操作方法返回的目标目标。但是,嵌套在ui:include和ui:repeat中的相同按钮似乎会重新初始化视图范围的bean,而不是导航到操作目标。有人有解释、解决方案或变通方法吗

代码大致如下。mybean是视图范围的

<h:form id="myform">
<p:commandButton value="DoIt" action="#{mybean.doit()}" ajax="true"/> <!-- this works! -->
<ui:include src="/sections/util/mycomp.xhtml">
 <ui:param name="backingbean" value="#{mybean}"/>
</ui:include>
</h:form>

这是组件

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                ...
                xmlns:p="http://primefaces.org/ui">
  <ui:repeat value="#{backingbean.mylit}" var="item" varStatus="status">
    <p:commandButton value="DoIt" action="#{backinbean.doit()}" ajax="true"/> <!-- this doesn't -->
  </ui:repeat>
</ui:composition>

奇怪的是,如果我将嵌套的p:commandButton重新定位在ui:component内部,但在ui:repeat外部,那么它就工作了


有什么想法吗?

嗨,我复制了你的代码,并试图重现问题,但我的似乎工作正常。顺便说一下,如果您想使用该按钮进行导航,可能应该将ajax设置为false。以下是我的代码:

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

    <h:head></h:head>
    <h:body>
        <h:form id="myform">
            <p:commandButton value="DoIt" action="#{backingBean.goToAnotherPage()}" ajax="true"/> <!-- this works! -->
            <ui:include src="firstpage.xhtml">
                <ui:param name="bb" value="#{backingBean}"/>
            </ui:include>
        </h:form>
    </h:body>
</html>

这里是第二页firstpage.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

            <ui:repeat value="#{bb.myList}" var="item" varStatus="status">
                <p:commandButton value="DoItInRepeat" action="#{bb.goToAnotherPage()}" ajax="true"/> <!-- this doesn't -->
            </ui:repeat>
            <ui:debug hotkey="x" />

</ui:composition>

最后是支持bean:

@ManagedBean
@ViewScoped
public class BackingBean {

    private List<String> myList = new ArrayList<String>();

    @PostConstruct
    public void init(){
        myList.add("1");
        myList.add("2");
        myList.add("3");
    }

    public String goToAnotherPage(){
        return "destpage.xhtml";
    }
    //Getters and Setters     
}
@ManagedBean
@视域
公共类BackingBean{
private List myList=new ArrayList();
@施工后
公共void init(){
myList.添加(“1”);
myList.添加(“2”);
myList.添加(“3”);
}
公共字符串goToAnotherPage(){
返回“destpage.xhtml”;
}
//接球手和接球手
}

无法用任何Mojarra版本重现您的问题。您使用的是哪个JSF impl/版本?是我的脸吗?