加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 01:35:58 所属栏目:百科 来源:网络整理
导读:我有一个应该重定向到项目视图页面的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");
  // ...
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读