为什么在请求bean作用域时素数树的ajax事件不起作用? [英] Why tree ajax events in primefaces don't work when bean scope is request?

查看:101
本文介绍了为什么在请求bean作用域时素数树的ajax事件不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的xhtml代码是:

My xhtml code is:

<p:tree id="attachTree" style="width: 100%;" value="#{detailsTaskBacking.attachRootNode}" selectionMode="single" selection="#{detailsTaskBacking.selectedNode}" var="node">
<p:ajax event="select" async="false" update=":roteiroAttachTab:formAttachForm:mediaPdf" listener="#{detailsTaskBacking.onNodeSelect}"/>
<p:treeNode expandedIcon="ui-icon-folder-open" collapsedIcon="ui-icon-folder-collapsed">
<h:outputText value="#{text['tasksbacking.tabAttach']}"/>
 </p:treeNode>
<p:treeNode type="file" expandedIcon="ui-icon-document" collapsedIcon="ui-icon-document">
 <h:outputText value="#{node.name}"/>
</p:treeNode>
</p:tree>

我的bean代码是:

@request
...
public void onNodeSelect(NodeSelectEvent event) {...}

在调试模式下运行项目时,由于参数事件为null,为什么?

When run the project in debug mode selectedNode for argument event is null, why?

为什么在请求bean作用域时素数树ajax事件不起作用?我在视图范围内使用一个bean进行了测试,并且selectedNode不为null,为什么?

Why in primefaces tree ajax events not work when bean scope is request? I tested this with one bean in view scope and the selectedNode is not null, why?

推荐答案

如果回发期间#{detailsTaskBacking.attachRootNode}后面的模型不兼容地发生更改,则会发生这种情况.例如.重新初始化为null时.您需要确保同一视图上的回发模型完全相同.如果是请求范围的bean,则需要确保在@PostConstruct中准备与显示表单时完全相同的模型.另一种方法是仅使bean @ViewScoped,以便只要在同一视图上回发就可以存在相同的bean实例.

That will happen if the model behind #{detailsTaskBacking.attachRootNode} incompatibly changes during postback. E.g. when it's reinitialized to null. You need to make sure that the model is exactly the same across postbacks on the same view. In case of a request scoped bean, you'd need to make sure that you prepare exactly the same model in @PostConstruct as it was when the form is being displayed. Another way is to just make the bean @ViewScoped so that the same bean instance lives as long as you postback on the same view.

  • How to choose the right bean scope?
  • commandButton/commandLink/ajax action/listener method not invoked or input value not updated - point 4

这篇关于为什么在请求bean作用域时素数树的ajax事件不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆