我目前的環境是JRE 1.7,JSF 2.2,Eclipse Luna。在某一頁(entity_index.xhtml
)我的申請,我有以下(PrimeFaces)按鈕:導航到其他視圖傳遞參數
<p:commandButton value="Details" action="entity_details"
ajax="false" onclick="this.form.target='_blank'">
<f:param name="id" value="#{entity.id}" />
</p:commandButton>
的想法是提供一個按鈕,以便用戶可以單擊它,在當前實體的一些細節將在顯示另一個瀏覽器選項卡(頁面entity_details.xhtml
)。這是很多的一個按鈕,因此entity_index.xhtml
頁面顯示了許多實體實例,每個實例都有一個詳細信息按鈕。
該按鈕的工作原理是打開一個新選項卡並顯示正確的頁面(entity_details.xhtml
),但實體標識永遠不會到達處理詳細信息頁面(EntityDetailsMB
)的bean。詳細信息頁面如下:
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:dsi="http://www.cce.ufpr.br"
template="/private/template/sbadmin.xhtml">
<f:metadata>
<f:viewParam name="id" value="#{entityDetailsMB.id}"/>
</f:metadata>
<ui:define name="content">
<h2 class="page-header">#{entityDetailsMB.entity.name}</h2>
<h:form id="form">
...
</ui:composition>
注意,有專用捕獲從索引頁發送的參數,並將其轉發給id
財產EntityDetailsMB
,一個<f:metadata/>
元素,其中有以下幾點:
public Entity getEntity() {
return entityById(id);
}
public Long getId() {
return id;
}
public void setId(Long value) {
id = value;
}
因爲setId()
方法永遠不會被調用,所以getEntity()
總是返回null
。
什麼是缺少使它的工作?
你嘗試做的結果,並添加一個參數去從獲取數據的第一個JSF頁面 –