Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Primefaces:ajax导航和dataTable复选框选择_Java_Ajax_Jsf_Primefaces - Fatal编程技术网

Java Primefaces:ajax导航和dataTable复选框选择

Java Primefaces:ajax导航和dataTable复选框选择,java,ajax,jsf,primefaces,Java,Ajax,Jsf,Primefaces,我在应用程序中遇到复选框选择问题。我在一个页面上有一个数据表(index.xhtml)。在同一个页面上有一个ajax按钮,当用户单击它时,应用程序应该导航到另一个页面(detail.xhtml)。详细信息页面包含用于导航回index.xhtml的返回按钮。导航工作,但当用户从详细信息页面返回时,当用户单击dataTable时,dataTable中的行复选框不会被选中(选中所有行的标题复选框工作)。当我重复这个场景(又名访问详细信息页面并返回)时,复选框再次工作。第三次重复后,它们不再工作(因此每

我在应用程序中遇到复选框选择问题。我在一个页面上有一个数据表(index.xhtml)。在同一个页面上有一个ajax按钮,当用户单击它时,应用程序应该导航到另一个页面(detail.xhtml)。详细信息页面包含用于导航回index.xhtml的返回按钮。导航工作,但当用户从详细信息页面返回时,当用户单击dataTable时,dataTable中的行复选框不会被选中(选中所有行的标题复选框工作)。当我重复这个场景(又名访问详细信息页面并返回)时,复选框再次工作。第三次重复后,它们不再工作(因此每秒钟它们都不工作)。当我在按钮上使用ajax=“false”或faces redirect=true时,一切正常

使用Mojarra 2.10.19、PF 3.5和Glassfish 3.2.1

为了简单起见,我通过简单的示例重新创建了问题:

index.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"      
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui" >

<h:head></h:head>   
<h:body>
    <h:form>
        <p:commandButton value="Add" action="add" />
        <p:dataTable id="cars" var="car" value="#{tableBean.mediumCarsModel}" 
                     selection="#{tableBean.selectedItems}" >

            <p:column selectionMode="multiple" style="width: 2%" />

            <p:column headerText="Model">
                #{car.model}
            </p:column>

        </p:dataTable> 
    </h:form>    
</h:body>
faces-config.xml

<navigation-rule>
    <from-view-id>/index.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>add</from-outcome>
        <to-view-id>/detail.xhtml</to-view-id>
    </navigation-case>       
</navigation-rule>   

<navigation-rule>
    <from-view-id>/detail.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>return</from-outcome>
        <to-view-id>/index.xhtml</to-view-id>
    </navigation-case>       
</navigation-rule> 

/index.xhtml
添加
/detail.xhtml
/detail.xhtml
返回
/index.xhtml

您需要从faces-config.xml中删除导航规则来尝试以下操作

index.xhtml

<p:commandButton value="Add" action="#{tableBean.redirectToDetail}" />
<p:commandButton value="Return" action="#{tableBean.redirectToIndex}" />

正如我在帖子中所说,faces重定向是可行的,但我不想使用它
public class Car implements Serializable {

    private String model;

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public Car(String model) {
        this.model = model;
    }
}
<navigation-rule>
    <from-view-id>/index.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>add</from-outcome>
        <to-view-id>/detail.xhtml</to-view-id>
    </navigation-case>       
</navigation-rule>   

<navigation-rule>
    <from-view-id>/detail.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>return</from-outcome>
        <to-view-id>/index.xhtml</to-view-id>
    </navigation-case>       
</navigation-rule> 
<p:commandButton value="Add" action="#{tableBean.redirectToDetail}" />
<p:commandButton value="Return" action="#{tableBean.redirectToIndex}" />
@ManagedBean(name = "tableBean")
...
...
...
public String redirectToDetail() {
    return "detail?faces-redirect=true";
}
public String redirectToIndex() {
    return "index?faces-redirect=true";
}