Jump to content

Can't seem to figure out RequestScoped...

DtrollMC

I've been reading a few books lately, one of them being Java EE 7 Development with NetBeans 8 (Heffelfinger), and I keep having problems with making the named beans. They seem to work sporadically, sometimes the bean works, other times (most times) I am greeted with this lovely error:

/index.xhtml @8,56 contracts="#{themeSelector.themeName}" WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped

When I restart Glassfish, and re-run the application, it will work again. Why is this? Is there any simple way to prevent this? This is generally the bean I am trying to implement:

package com.carvethsolutions.beans;

import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

/**
 * A simple Named Bean to select a theme on the webpage
 * @author John L. Carveth
 */
@Named
@RequestScoped
public class ThemeSelector implements Serializable {
    private String themeName = "dark";

    public String getThemeName() {
        return themeName;
    }

    public void setThemeName(String themeName) {
        this.themeName = themeName;
    }
}

and I access the named bean in the xhtml pages using:

#{themeSelector.themeName}

 

Anyone familiar with Java EE, JSF, to help with this?

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×