Background Task with a Bean with Session scope

I’m trying to do this

I want the progress bar when ever a user is authenticating to a third party but i store these credentials in a session scoped bean.

I get a
Scope ‘session’ is not active for the current thread; IllegalStateException: No thread-bound request found.

Any idea how this can be done?

How did you define the bean and how do you access it?

The following works for me:

@Scope(value = WebApplicationContext.SCOPE_SESSION)
public class SampleSessionBean {

    private String value;

    public String getValue() {
        return value;

    public void setValue(String value) {
        this.value = value;
public class TaskScreen extends Screen {

    private Dialogs dialogs;

    private SampleSessionBean sampleSessionBean;

    private Label label;

    private static final Logger log = LoggerFactory.getLogger(SampleTask.class);

    private class SampleTask extends BackgroundTask<Integer, Void> {

        public SampleTask() {
            super(10, TimeUnit.MINUTES, TaskScreen.this);

        public Void run(TaskLifeCycle<Integer> taskLifeCycle) throws Exception {
            for (int i = 0; i < 20; i++) {
                if (taskLifeCycle.isCancelled()) {

            return null;

        public void done(Void result) {
            String value = sampleSessionBean.getValue();
  "done >>> " + value);

I have the bean as

changing to
@Scope(value = WebApplicationContext.SCOPE_SESSION)
breaks my application :frowning:

Perhaps it’s not a good idea to access session beans from a background thread.
Better store the data required for a background process in the background task instance itself: pass input to the constructor and return results from done() method if needed.

1 Like

great idea… this made that error go away… it super makes my code horrible now because i need to be sending these parameters all over the place… but now… the operation starts… stays there a couple of seconds and at the last second it shows the progressbar and hides it. i dont have a list of elements its only a slow web service call i need to do. Just need to notify the end user about it. so its still not really working for me.