I'm trying to write a simple login form with jsf and CDI. the problem is when I inject my SessionScoped bean it doesn't work as I expect. This is my bean
@Named
@SessionScoped
public class LoginInfo implements Serializable {
private String uname;
private String pass;
private String pagename;
private int count;
public LoginInfo() {
}
public void increment() {
count++;
}
}
And this is my controller :
@Named
@RequestScoped
public class LoginPageMg {
@Inject
LoginInfo lo;
public LoginPageMg() {
}
public void login() {
lo.increment();
lo.setPagename("aaa");
int x = 8;
}
}
And a simple Jsf form which calls login function and shows counter field of LoginInfo class.
<h:form prependId="false" id="mainform" styleClass="login-box">
<p:inputText value="#{loginPageMg.uname}"/>
<p:password value="#{loginPageMg.pass}"/>
<h:outputLabel id="counter" value="#{loginInfo.count}"></h:outputLabel>
<p:commandButton update="counter"
action="#{loginPageMg.login}"
value="login"></p:commandButton>
</h:form>
By clicking login button and debugging variables I can see "lo" is something like this :
lo = {LoginInfo$Proxy$_$$_WeldClientProxy@16688}"com.mg.LoginInfo@703ec5d5"
On line int x=8 I can see "lo" variables didn't changed at all but in my jsf page I can see the counter increases every time I press login button and bean holds the value after refreshing the page.
- What is WeldClientProxy?
- Why there are two different instance of a SessionScoped bean? Is that normal or I'm doing something wrong?
- How can I inject the same instance that jsf does?
I'm using Wildfly 15 Jsf 2.3.4 CDI 1.1
@SessionScoped
and@RequestScoped
you are using? – Nikos Paraskevopoulos