This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes Value doesnt return when I use @Named annotation in JSF2 but @ManagedBean working fine. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Value doesnt return when I use @Named annotation in JSF2 but @ManagedBean working fine." Watch "Value doesnt return when I use @Named annotation in JSF2 but @ManagedBean working fine." New topic
Author

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

Baris Vlgl
Greenhorn

Joined: Apr 15, 2011
Posts: 3
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

Joined: Jun 25, 2001
Posts: 15951
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Baris Vlgl
Greenhorn

Joined: Apr 15, 2011
Posts: 3
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

Joined: Jun 25, 2001
Posts: 15951
    
  19

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

Joined: Apr 15, 2011
Posts: 3
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 F. Borges
Greenhorn

Joined: Mar 25, 2011
Posts: 12

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
 
subject: Value doesnt return when I use @Named annotation in JSF2 but @ManagedBean working fine.
 
Similar Threads
Using inheritance for managed beans
ejb injection in weblogic 11g fails
Still struggling to get started with JSF.
Why @ManagedBean works while @Named doesn't?
request.getParameter returns null