1

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?

nuno
  • 1,771
  • 1
  • 19
  • 48
Marin
  • 1,010
  • 1
  • 10
  • 37

1 Answers1

2

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Does that mean that, if a request parameter is accessed in the backing bean, it should always be accessed in `@PostConstruct` (when in request-scope)? – nuno Aug 21 '14 at 09:52
  • That's correct. You can use `@ManagedProperty` to set a request parameter as a bean property before `@PostConstruct` runs. However, if parameters depend on postback actions taken place beforehand on the same view, you'd better just put the bean in the view scope. There it is for. – BalusC Aug 21 '14 at 09:55
  • Initially this id is populated but when I click on the node it is null. In scope view work but i need use request scope. the problem is that initially the id is in the url but when click on node not. I saw it doing print context.getRequestURL(). why? – Marin Aug 21 '14 at 11:18
  • Because you didn't pass it when submitting the form. That's answered in among others http://stackoverflow.com/questions/17734230/retaining-get-request-query-string-parameters-on-jsf-form-submit/ – BalusC Aug 21 '14 at 11:19
  • thanks BalusC! use this code in form . – Marin Aug 21 '14 at 13:10