我有一个应该重定向到项目视图页面的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
UIComponentcustom action.Description
Locate the closest parent
UIComponentcustom action instance (…). If the associated component already has a component
attribute with that name,take no action. Otherwise,call theisLiteralText()method on the argumentvalue. If it
returnstrue,store the value in the component’s attribute Map under the name derived above. If it returnsfalse,store
theValueExpressionin the component’sValueExpressionMap 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");
// ...
}

