Why tree ajax events in primefaces don't work when bean scope is request?

99封情书 提交于 2019-12-11 09:42:05

问题


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>

And my bean code is:

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

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

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?


回答1:


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.

See also:

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


来源:https://stackoverflow.com/questions/25422401/why-tree-ajax-events-in-primefaces-dont-work-when-bean-scope-is-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!