2012-01-02 130 views
6

在我的頁面上,我有一個按鈕,用於打開彈出窗口中的項目列表。當我在列表中選擇1個項目時,我想將項目的ID傳遞給我的第一頁的backingbean。可能嗎?它試圖用a4j:jsFunctiona4j:param這樣做,但它不起作用。如何將參數值傳遞給a4j:jsFunction

這是我的代碼:

第1頁:

<a4j:jsFunction name="renderGuarantor" render="guarantor" actionListener="#{prospectDetail.setNewGuarantor}"> 
    <a4j:param name="param1" assignTo="#{prospectDetail.newGuarantorId}" /> 
</a4j:jsFunction> 

popuppage:

<h:outputLink value="" onclick="window.opener.renderGuarantor(#{applicant.deposit_id});window.close();"> 
    <h:graphicImage style="padding:0 1px; border:0" value="${path.staticRootUrl}images/confirm.gif" alt="${msg.applicantslist_select}" title="${msg.applicantslist_select}"/> 
</h:outputLink> 

這是第一頁

支持bean代碼
private Integer newGuarantorId; 
public void setNewGuarantor() { 
    guarantor = newGuarantorId; 
} 

public Integer getNewGuarantorId() { 
    return newGuarantorId; 
} 

public void setNewGuarantorId(Integer newGuarantorId) { 
    this.newGuarantorId = newGuarantorId; 
} 

在彈出窗口中選擇時,我的backingbean中的方法被調用,但newGuarantorId爲空,並且從不調用setNewGuarantorId

有沒有解決我的問題?

+0

你確定'#{applicant.deposit_id}'在新窗口中不爲空嗎? – Nikhil 2012-01-02 17:44:50

+0

是的,它填寫了正確的ID。 – roel 2012-01-03 08:41:21

+0

嗯..多數民衆贊成在奇怪的,沒有看起來錯了..不是你的問題的答案,但嘗試這種解決方法 - 而不是將值分配給'guarantorId',保持參數爲''並在'actionListener'方法中從請求中獲取這個'param1'作爲'String param1 = FacesContext.getCurrentInstance()。getExternalContext()。getRequestParameterMap()。get(「param1」);'。然後將此參數轉換爲「int」並進一步利用它。這應該工作。 – Nikhil 2012-01-03 11:38:42

回答

5

嗯..那怪,看起來沒有任何的wrong..Not回答你的問題,但嘗試這種解決方法 - 而不是分配價值guarantorId,保持帕拉姆爲<a4j:param name="param1"/>,並在actionListener方法來檢索從這個參數1請求爲String param1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().‌​get("param1");。 然後將此參數轉換爲int並進一步使用它。這應該工作

1

我想你可以試試這個:

<a4j:jsFunction name="renderGuarantor" render="guarantor" 
       actionListener="#{prospectDetail.setNewGuarantor(prospectDetail.newGuarantorId)}" /> 

而在你的託管bean,定義setNewGuarantor方法如下:

public void setNewGuarantor(int newGuarantorId) { 
    guarantor = newGuarantorId; 
} 
3

嘗試切換從actionListeneraction

<a4j:jsFunction name="renderGuarantor" render="guarantor" action="#{prospectDetail.setNewGuarantor}"> 
    <a4j:param name="param1" assignTo="#{prospectDetail.newGuarantorId}"/> 
</a4j:jsFunction> 

以下是關於主題的推薦閱讀: a4j:jsFunction