微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将其他参数发送到Ajax事件侦听器

我有一个应该重定向到项目视图页面的ajax监听器.
但是,由于我使用泛型类型作为模型,我想在我的公共数据表控制器中另外指定具有第二个参数的视图.

不幸的是,人们可以在两个监听器方法之间进行选择,一个使用事件参数来帮助识别对象,第二个让你有机会发送免费的参数但缺少事件.

模板:

<p:dataTable value="#{aObj.objList}" var="item" .... selectionMode="single">

  <p:ajax event="rowSelect" listener="#{aObj.viewItem}" />
  <p:ajax event="rowSelect" listener="#{aObj.viewItem('myItemView?_id=')}" />

  ...
</p:dataTable>

控制器:

public void viewItem(SelectEvent event) {
  // ...
}

public void viewItem(String viewUrl) {
  // ...
}

我可以为bean添加其他属性,但由于它是通用的,并且提供模型项不适合污染它.

有没有解决方法

您可以在数据表中设置属性并在选择侦听器中读取它.为此,请使用< f:attribute name =“...”value =“...”/>.从 documentation

Constraints

Must be nested inside a UIComponent custom action.

Description

Locate the closest parent UIComponent custom action instance (…). If the associated component already has a component
attribute with that name,take no action. Otherwise,call the isLiteralText() method on the argument value. If it
returns true,store the value in the component’s attribute Map under the name derived above. If it returns false,store
the ValueExpression in the component’s ValueExpression Map under the name derived above.

因此,根据您尝试在评论中设置的属性,您应该使用它:

XHTML:

<p:dataTable value="#{aObj.objList}" var="item" .... selectionMode="single">

  <f:attribute name="test" value="abc" />
  <p:ajax event="rowSelect" listener="#{aObj.viewItem}" />

  ...
</p:dataTable>

监听器:

public void viewItem(SelectEvent event) {
  String test = (String) event.getComponent().getAttributes().get("test");
  // ...
}

原文地址:https://www.jb51.cc/ajax/159908.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐