Search code examples
javaxpagesjavabeans

accessing a Java Bean from a different Java class


I have a Java Bean called appProps defined as an ApplicationScope that is a Hashmap and of the type <string, object>. I can access it via SSJS using the format

var appDesc:String = appProps["some application name"].getAppDesc();

and this returns the application description which is stored in one of the fields in the Hashmap Object.

Now I need to call the same process in another JAVA Class.

The definition in the faces-config is:

<managed-bean>
    <managed-bean-name>appProps</managed-bean-name>
    <managed-bean-class>ca.wfsystems.core.ApplicationMap</managed-bean-class>
    <managed-bean-scope>application</managed-bean-scope>
  </managed-bean>

Solution

  • The best Java equivalent of the implicit lookup that SSJS and EL do for appProps there is:

    ApplicationMap appProps = (ApplicationMap)ExtLibUtil.resolveVariable(FacesContext.getCurrentInstance(), "appProps")