Hi
I am having login page where i enter username and password and click on login button.
i am having weld bean for user credential as follows,
@Named
@SessionScoped
public class Credentials implements Serializable {
/**
*
*/
private static final long serialVersionUID = 8154140549591434736L;
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
i had added eclipse debuger on setter methods ,then i found that it set the value to bean but the class where i inject this bean is second bean and not one which is populated from JSF Form.
@Inject private Credentials credentials;
Above code i used to inject credentials in Authenticator class,
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Named
@RequestScoped
public class Authenticator implements Serializable{
//@Inject private Logger log;
private static final Logger log=LoggerFactory.getLogger(Authenticator.class);
@Inject private Credentials credentials;
public String authenticate()
{
System.out.println(credentials.getUsername());
}
public void logout()
{
}
}
Please tell me that why second instance of bean is being instantiated by container?
Thanks in adavnce.