2012-01-02 91 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