如何将参数值传递给 a4j:jsFunction
在我的页面上有一个按钮,可以在弹出窗口中打开项目列表。当我在列表中选择一个项目时,我想将该项目的 id 传递给我的第一页的 backingbean。是否可以?它尝试使用 a4j:jsFunction
和 a4j:param
来完成此操作,但它不起作用。
这是我的代码:
page 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;
}
在弹出窗口中选择时,将调用我的支持 bean 中的方法,但是 < code>newGuarantorId 为 null,并且 setNewGuarantorId
从未被调用。
我的问题有解决办法吗?
On my page I have a button that opens a list of items in a popup. When I select 1 item in the list, I want to pass the id of the item to the backingbean of my first page. Is it possible? It tried to do it with a4j:jsFunction
and a4j:param
but it does'nt work.
This is my code:
page 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>
And this is the backing bean code for the first page
private Integer newGuarantorId;
public void setNewGuarantor() {
guarantor = newGuarantorId;
}
public Integer getNewGuarantorId() {
return newGuarantorId;
}
public void setNewGuarantorId(Integer newGuarantorId) {
this.newGuarantorId = newGuarantorId;
}
When selecting in the popup the method in my backingbean is called, but newGuarantorId
is null and setNewGuarantorId
is never called.
Is there a solution to my problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯..这很奇怪,看起来没有任何问题..不是您问题的答案,但请尝试此解决方法 - 不要将值分配给 guarantorId,而是将参数保留为
并在actionListener
方法中从请求中检索此 param1 作为String param1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(). get(“param1”);
。然后将此参数转换为 int 并进一步使用它。那应该有效
Hmm.. thats strange, nothing looks wrong..Not an answer to your question but try this workaround - instead of assigning the value to guarantorId, keep the param as
<a4j:param name="param1"/>
and in theactionListener
method retrieve this param1 from the request asString param1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("param1");
.And then convert this param to int and utilize it further. That should work
尝试从
actionListener
切换到action
:建议阅读有关该主题的内容:a4j:jsFunction
Try switching from
actionListener
toaction
:Here is recommended reading on the topic: a4j:jsFunction
我想你可以尝试这个:
在你的托管bean中,定义setNewGuarantor方法如下:
I think you can try this:
And in your Managed bean, define the
setNewGuarantor
method as following: