【发布时间】:2012-01-31 21:19:21
【问题描述】:
在我的页面上,我有一个按钮,可以在弹出窗口中打开项目列表。当我在列表中选择一个项目时,我想将项目的 id 传递给我的第一页的 backingbean。可能吗?它试图用a4j:jsFunction 和a4j:param 来做到这一点,但它不起作用。
这是我的代码:
第 1 页:
<a4j:jsFunction name="renderGuarantor" render="guarantor" actionListener="#{prospectDetail.setNewGuarantor}">
<a4j:param name="param1" assignTo="#{prospectDetail.newGuarantorId}" />
</a4j:jsFunction>
弹出页面:
<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 为 null 并且永远不会调用 setNewGuarantorId。
我的问题有解决方案吗?
【问题讨论】:
-
您确定
#{applicant.deposit_id}在新窗口中不为空吗? -
是的,它填写了正确的 id。
-
嗯..这很奇怪,看起来没什么问题..不是您的问题的答案,但请尝试此解决方法 - 不要将值分配给
guarantorId,而是将参数保留为<a4j:param name="param1"/>并在actionListener方法将此param1从请求中检索为String param1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("param1");。然后将此参数转换为int并进一步利用它。那应该可以。 -
太棒了! :) 把它作为答案放在下面。如果它是您问题的答案,请标记它
标签: ajax jsf jsf-2 richfaces ajax4jsf