rubaka
rubaka

Reputation: 47

Injected CDI Bean return null values

My JSF Page:

<h:form>
    <p>
        <h:outputLabel for="phone">Phone: <h:message class="alert" for="phone"/> 
            <h:message class="alert" for="phoneLogin"/>
        </h:outputLabel>
        <p:inputText id="phone" value="#{userBean.mobile_phone}">
            <f:validator validatorId="phoneValidation"/>
        </p:inputText>
        <p:watermark for="phone" value="+79123456789"/>
    </p>
    <p>
        <h:outputLabel for="password">
            Password: <h:message class="alert" for="password"/>
        </h:outputLabel>
        <p:password id="password" value="#{userBean.password}">
            <f:validator validatorId="passValidation"/>
        </p:password>
    </p>
    <p style="text-align: center">
        <p:commandButton id="phoneLogin" update="@form" binding="#{dataBean.phoneLogin}" 
                         value="Login" action="#{dataBean.loginProfile}"/>
    </p>
</h:form>

My UserBean code:

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import java.io.Serializable;

@Named
@SessionScoped
    //user data. getters and setters

My DataBean code:

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.inject.Named;

@Named
@Stateless
public class DataBean{

@Inject
private UserBean userBean;
//class logic

When I press the button I should be logged in by loginProfile method in DataBean class. But the @Inject annotation returns null values and I get a NullPointerException. All imports are ok. I'm using CDI beans only and I'm really not understanding why I can't get the values from UserBean class. I hope that someone can help me.

Upvotes: 0

Views: 5077

Answers (1)

rubaka
rubaka

Reputation: 47

If program not working, but you sure that everything is ok. Try to clean target directory and try one more. It's working for me.

Upvotes: 1

Related Questions