Access UserBean from Java

May 8, 2012 – 4:25 pm

I use the userBean that comes with the extension Library in SSJS very often. It is a convenient way to access various properties of the current user.

Today I wanted to use the UserBean in Java. But I could not figure out, how to do. After some help from Stephan Wissel and a few minutes of try and error, I ended up with the following:

package de.eknori.jsf.core;
public class User {
public static Object getUser() {
return UserBean.get().getField( "effectiveUserName" );

A UserBean.get(9 will return all fields as shown in the picture below

The getField(String) method lets you access a single value from the bean.


  1. One Response to “Access UserBean from Java”

  2. Did you also check the source code for the UserBean? It is in the ExtLib download. The get() function is actually pretty handy and you might want to add that to every bean you create to be able to access it in Java:

    public static final String BEAN_NAME = “userBean”; //name of the bean

    public static UserBean get(FacesContext context) {
    UserBean bean = (UserBean)context.getApplication().getVariableResolver().resolveVariable(context, BEAN_NAME);
    return bean;

    By Mark Leusink on May 8, 2012

Sorry, comments for this entry are closed at this time.