How can I access the SessionBean1 property from within my Java class?

Suppose you create a new Java class in your web application package, and you need to access your SessionBean1 property from the new class. Here's an example of code that gives the access you need.

import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
ValueBinding vb = 
SessionBean1 bean1 = 
    (SessionBean1) vb.getValue(FacesContext.getCurrentInstance());

ValueBinding is already deprecated. Here's the alternative

import webprojectname.SessionBean1;
import javax.el.ValueExpression;
import javax.faces.context.FacesContext;

FacesContext facesContext = FacesContext.getCurrentInstance();
ValueExpression ve = facesContext.getApplication().getExpressionFactory().
                     createValueExpression(facesContext.getELContext(), "#{SessionBean1}", SessionBean1.class);
SessionBean1 bean1 = (SessionBean1) ve.getValue(facesContext.getELContext());        

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo