其他页面上的数据表选定行

时间:2014-07-01 13:31:52

标签: jsf primefaces

我实现了数据表lazy(http://www.primefaces.org/showcase/ui/data/datatable/lazy.xhtml),它运行正常。

现在我想在选择行时打开新页面。例如,我必须这样做:http://primefaces-rocks.appspot.com/ui/datatableRowSelectionInstant.jsf(第二个表)。

在我的LazyView类中,我尝试过:

try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("carDetails.xhtml?id=" + ((Car) event.getObject()).getId().toString());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

显示carDetail页面,但值为空。我不知道如何在carDetail.xhtml页面中获取汽车的价值...

我也试试这段代码:

public String onRowSelectNavigate(SelectEvent event) {  
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedCar", event.getObject());  

        return "carDetail?faces-redirect=true";  
    }

但它不起作用。

有人可以帮助我吗?

感谢的

2 个答案:

答案 0 :(得分:0)

在你的bean上,你需要创建一个参数,因为你可以为这种情况设置id。因此,当您在数据表中选择一行时,例如,您可以添加该属性的setter。

<h:commandButton action="#{bean.showNewPage}" value="Submit">
    <f:setPropertyActionListener target="#{bean.carId}" value="result.carId" />
</h:commandButton>

答案 1 :(得分:0)

原因是:我的视图类中的SessionScoped:)

谢谢