File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Value doesnt return when I use @Named annotation in JSF2 but @ManagedBean working fine.

 
Baris Vlgl
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I did a simple button action. It returns value whatever the user type in a texbox. But when I use @Named annotation, it returns nothing and also no error occurs. After I change "Named" to "ManagedBean" , everything working fine. I have configured everything that the http://www.theserverside.com/tutorial/Working-with-CDI-and-JSF-20-on-Tomcat-7-Configuring-Weld says but I couldnt understand the error because there is no error anywhere.

I am using JSF2 - Tomcat7

Thanks in advance.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17627
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Baris!

JSF ignores a lot of "errors" and one of them is when you don't have your resources named and defined properly.

The @Named annotation doesn't register the named object as a JSF managed bean (as far as I know, anyway). And if it doesn't, then JSF can't use it.
 
Baris Vlgl
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if so how do I know what causes this strange behavior without seeing any error ? Any resource that you can advice me to make a start. I am new to jsf.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17627
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, there's no diagnostic information available. Sometimes you'll get a "property x not defined on bean y" type of message, but that's usually in cases where lack of a value is fatal. Otherwise, when data just simply fails to show, do the following checklist:

1. Make sure that the bean itself is defined and cataloged as a managed bean and that you have capitalized everything properly. The class name for the bean should begin with an uppercase letter and the actual bean reference (instance name) should begin with a lower-case letter. The @ManagedBean annotation will automatically take care of that, if that's what you are using.

2. Make sure that there's a public "getXxxx" method defined for the referenced property name "xxxx" and that it doesn't return void. Depending on the usage, it may be necessary to also define a public void "setXxxx" method as well.

3. Make sure that "getXxxx" actually is returning a non-blank value if you want a value to display!
 
Baris Vlgl
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for taking the time. Just one more question, could you explain what do you mean by "The @Named annotation doesn't register the named object as a JSF managed bean". I got confused about that.

 
Emmanuel Borges
Greenhorn
Posts: 12
Java MySQL Database Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your bean session scoped?

If so, you must import the 'javax.enterprise.context' package for the @SessionScope annotation and not the 'javax.faces.bean' package as you would do if you were using a Managed Bean.

Well, i'm a rookie myself, so i'm not sure if this is the answer to your problem.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic