2

I have a question. I have been using JSF2.0 these days and I found to use annotation rather than faces-config.xml to configure managed bean is more useful. But I am facing a problem to get the managed bean instance in my *.xhtml pages.

While I am using faces-config.xml to declare my managed bean I do it like:

<managed-bean>
    <managed-bean-name>exampleBean</managed-bean-name>
    <managed-bean-class>com.example.ExampleBean</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>
</managed-bean>

But with annotation we do it like: @ManagedBean(name = "exampleBean"). But while accessing the managed bean in EL expression and its property using annotation, I can't get the instance of the managed bean. I keep trying the #{} and ctrl+space in Eclipse but does not come in suggestion.

But its easier to get the instance while using faces-config.xml to declare the managed bean. How can I do this using annotation as well?

Please suggest!! Thanks in advance.. :)

SilverNak
  • 3,283
  • 4
  • 28
  • 44
NDeveloper
  • 3,115
  • 7
  • 23
  • 34
  • What do you mean by "Eclipse does not come in suggestion"? Do you know Eclipse's autocomplete tools don't cover every single JSF (or other framework) aspect? Eclipse not telling you that doesn't mean it won't work... – Aritz Mar 16 '14 at 10:12
  • I know it still works. But if we define the Managed Bean instance in `faces-config.xml` then eclipse gives a suggestion for the bean instance. But it does not come in case of annotation. – NDeveloper Mar 19 '14 at 13:00
  • Have you tried to write your EL expressions manually despite of that ? it should not underline it if the managed-bean is well annotated and accepted. – Omar Mar 19 '14 at 14:28
  • You seem to be blaming Eclipse for annotations not working. That's however another different matter. Annotations not working is normally related with not providing at least an empty faces-config file while using them. The JSF framework does not perform a scanning for them in this case. If otherwise your problem is about eclipse, then mention it in your title and add the proper tag to the question – Aritz Mar 19 '14 at 17:47

1 Answers1

2

just close and re open the project and everything will work :). your problem you have created a new project and after that you have to add jsf to project facets. in this case you get this problem.

Evgenij Reznik
  • 17,916
  • 39
  • 104
  • 181
sghaier ali
  • 433
  • 2
  • 15