Вопрос

Is a managed bean property accessible from an ejb? I would like to get few values from a managed bean into my ejb. The managed bean properties are created by jsf, which works fine, but in my ejb I always get null for the managed bean properties.

Here are some parts of me code:

Managed Bean: BeanCredentials

@ManagedBean
@RequestScoped
public class BeanCredentials implements Serializable {
    private String eMail;

    public String geteMail() {
        return eMail;
    }

    public void seteMail(String eMail) {
        this.eMail = eMail;
    }    
}

EJB: ServiceUser

@Stateful
public class ServiceUser {
    @PersistenceContext(unitName = "...")
    private EntityManager em;

    @Inject
    private BeanCredentials credentials;

    ...

    @Transactional
    public void login() {       
        if(this.credentials.geteMail() == null) { /* Always true */
            System.out.println(true);
        }
    }
}

public void login(); is called from an additional managed bean which provides user services to the front end (i.e. login, logout, create new users, display user information). This managed bean delegte the ejb (ServiceUser) to process all necessary user takss

Managed Bean: BeanUser

@ManagedBean
@SessionScoped 
public class BeanUser implements Serializable {
    @EJB
    private ServiceUser serviceUser;

    ...

    public void login() {       
        this.serviceUser.login();
    }
}

In the jsf from the value eMail from BeanCredentials is filled, but I am not able to acces the value inside the ejb ServiceUser. Does I misunderstood some annotations or the concept?

How could I access the managed bean properties inside an ejb? What is the common solution?

Это было полезно?

Решение

You could pass the values as a parameter to any EJB method.

For example in a typical create form you capture all the input from the user using the ManagedBean fields and then invoke your EJB through a service with these values. You could use java transfer object if the number of properties are large.

Другие советы

Can you ensure that the javax.inject jar is present in your classpath. If you are using this maven try including

<dependency>
  <groupId>javax.inject</groupId>
  <artifactId>javax.inject</artifactId>
  <version>1</version>
</dependency>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top