0

I have created a bean class version of an enum because jsp beans don't allow enums, but when I tried to use it, it gave me an error of "The value for the useBean class attribute ... is invalid."

Here is the code:

public class SomeClass
{
  public enum Variables
  {
    ERROR("error"),
    KEY("key");

    private final String name;

    private Variables(String name)
    {
      this.name = name;
    }

    public String getName()
    {
      return this.name;
    }
  }

  public static class VariablesBean
  {
    private Variables variable;

    public VariablesBean() { }

    public String getName()
    {
      return variable.getName();
    }

    public void setName(String name)
    {
      switch(name)
      {
        case "ERROR":
          variable = Variables.ERROR;
          break;
        case "KEY":
          variable = Variables.KEY;
          break;
      }
    }
  }
}

Then, within my jsp file, I have this tag which raises that error:

<jsp:useBean id="errorVariable" class="SomeClass.VariablesBean"> 
  <jsp:setProperty name="errorVariable" property="name" value="ERROR" />
</jsp:useBean>

What am I doing wrong?

kerafill
  • 274
  • 1
  • 4
  • 14

1 Answers1

1

The name of the class would be [<package identifier>.]SomeClass$VariablesBean since it's a nested class.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724