Skip to main content

GF3.1 @Named annotation not working but @ManagedBean does

4 replies [Last post]
lchong2
Offline
Joined: 2009-02-01
Points: 0

When I run the code like the following that is part of an entire program, consist of a Bean (the following code), a XHTML login page and another XHTML welcome page after login submission, I received an error after login page submisstion:

HTTP Status 500 with exception: javax.servlet.ServletException: /login.xhtml @16,46 value="#{user.name}": Target Unreachable, identifier 'user' resolved to null.

However after I changed @Name("user") to @ManagedBean(name="user"), the program runs without error. Is this due to a bug in GF3.1?

Cheers, lchong2

// UserBean
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named("user") //or @ManagedBean(name="user")
@SessionScoped
public class UserBean implements Serializable {
private String name;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}

}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mug897
Offline
Joined: 2011-05-27
Points: 0

you should CDI enabled when using CDI.

check whether beans.xml file exist

jdlee
Offline
Joined: 2006-01-25
Points: 0

Do you have a WEB-INF/beans.xml file?

On 3/11/11 5:12 PM, forums@java.net wrote:
> When I run the code like the following that is part of an entire program,
> consist of a Bean (the following code), a XHTML login page and another
> XHTML
> welcome page after login submission, I received an error after login page
> submisstion:
>
>
>
> HTTP Status 500 with exception: javax.servlet.ServletException:
> /login.xhtml
> @16,46 value="#{user.name}": Target Unreachable, identifier 'user'
> resolved
> to null.
>
>
>
> However after I changed @Name("user") to @ManagedBean(name="user"), the
> program runs without error. Is this due to a bug in GF3.1?
>
> Cheers, lchong2
>
>
>
> // UserBean
> import javax.enterprise.context.SessionScoped;
> import javax.inject.Named;
> @Named("user") //or @ManagedBean(name="user")
> @SessionScoped
> public class UserBean implements Serializable {
> private String name;
> private String password;
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public String getPassword() {
> return password;
> }
> public void setPassword(String password) {
> this.password = password;
> }
>
> }
>
>

lchong2
Offline
Joined: 2009-02-01
Points: 0

No.

Stoney
Offline
Joined: 2006-02-17
Points: 0

Thanks for asking that question. I stumbled over the same problem today (as a beginner into CDI beans ;) An empty beans.xml in WEB-INF solved the problem.