如何将参数值传递给 a4j:jsFunction

发布于 2024-12-24 02:34:23 字数 1286 浏览 0 评论 0原文

在我的页面上有一个按钮,可以在弹出窗口中打开项目列表。当我在列表中选择一个项目时,我想将该项目的 id 传递给我的第一页的 backingbean。是否可以?它尝试使用 a4j:jsFunctiona4j: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

背叛残局 2024-12-31 02:34:23

嗯..这很奇怪,看起来没有任何问题..不是您问题的答案,但请尝试此解决方法 - 不要将值分配给 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 the actionListener method retrieve this param1 from the request as String param1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().‌​get("param1");.
And then convert this param to int and utilize it further. That should work

痴情 2024-12-31 02:34:23

尝试从 actionListener 切换到 action

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

建议阅读有关该主题的内容:a4j:jsFunction

Try switching from actionListener to action:

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

Here is recommended reading on the topic: a4j:jsFunction

爱的那么颓废 2024-12-31 02:34:23

我想你可以尝试这个:

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

在你的托管bean中,定义setNewGuarantor方法如下:

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

I think you can try this:

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

And in your Managed bean, define the setNewGuarantor method as following:

public void setNewGuarantor(int newGuarantorId)  {
   guarantor = newGuarantorId;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文