85831

ManagedBean Params not accepted and Bean seemingly not in scope

This uses the same code that comes from primefaces tree control

@ManagedBean( name = "theName", eager = true)

The first question is why "name" and "eager" are not recognised. Eclipse suggests I change either parameter to "value" - so not sure whats going on there.

Then, where I have been careful to capitalise where necessary and create my bean

public class TreeBean implements Serializable {

and reference it in my xhtml

<h:form id="mainForm">

<p:tree id="treeSingle" value="#{treeBean.root}" var="node" selectionMode="single" selection="#{treeBean.selectedNode}">

(paying attention to the capitalisation of the classname).

The output shows only a narrow bar. System.out.println("Constructor called") suggests the bean is not known. To support this, if I press the button as coded in the example (link provided at the top) I get the error

Jan 13, 2014 12:19:26 AM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError SEVERE: javax.el.PropertyNotFoundException: /HelloWorld.xhtml @23,50 selection="#{treeBean.selectedNode}": Target Unreachable, identifier 'treeBean' resolved to null at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:133)

I've run out of ideas now as to what could be the problem. Is there any way of further debugging this or anyone got any ideas about the eager/name thing and what is causing the Bean class to be (I assume) not to be seen.

Thanks in advance. Kevin

Answer1:

beans should be defined this way:

@ManagedBean(name="treeBean") @SessionScoped // or whatever scope you would like to use public class TreeBean implements Serializable { ....

Usage in XHTML: ...="#{treeBean.root}"

<strong>Or</strong>

@ManagedBean(name="xyz") @SessionScoped // or whatever scope you would like to use public class TreeBean implements Serializable { ....

Usage in XHTML: ...="#{xyz.root}"

bean name is just a key for the map, you can name it whatever you want

the scope of the bean should be from the package javax.faces.bean

i.e. for <strong>sessionscoped</strong> beans you have to import

import javax.faces.bean.SessionScoped;

and for the managedBean Annotation

import javax.faces.bean.ManagedBean;

Answer2:

Here you can find different ways to define a JSF managed bean and also here you can find a really good discuss about managed beans.

Recommend

  • Index was outside the bounds of the array vb.net n mapwingis
  • Why the controls not update, when call method from other form
  • MultiPartParserError :- Invalid boundary
  • How to highlight the first inserted node in a tree view?
  • Affordable options for multi touch desktop device (To test apps on Windows phone 7 emulator)?
  • WPF ListBox scrollbar is not working
  • Print dynamic Excel page with changing content
  • call monodroid method from javascript example
  • Rails - Redundant RESTFUL Actions for map.resources? (new, create)
  • Amazon S3 - How do I download objects owned by anonymous user?
  • java.lang.IllegalArgumentException: Setter not found for property class
  • Primeng - Cant display array items in a column
  • How to select all in PrimeFaces TreeTable?
  • FIR filter in CUDA (as a 1D convolution)
  • how to replace TreeView's selected node with newly created node
  • typescript: any difference between number[] and [number,number]?
  • Flash radiobutton: how do I get the selected radiobutton?
  • How can I restyle a word when rendering a pdf with pdf.js?
  • Simple linked list-C
  • Find group of records that match multiple values
  • CakePHP ACL tutorial initDB function warnings
  • Conversion from string “a” to type 'Boolean' is not valid
  • Sails.js/waterline: Executing waterline queries in toJSON function of a model?
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Redux, normalised entities and lodash merge
  • Do create extension work in single-user mode in postgres?
  • Data Validation Drop Down Box Arrow Disappearing
  • Getting Messege Twice Using IMvxMessenger
  • Change div Background jquery
  • How to get Windows thread pool to call class member function?
  • Bitwise OR returns boolean when one of operands is nil
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How can i traverse a binary tree from right to left in java?
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?