Tuesday, November 14, 2017

Public fields in CDI

in CDI one can't have a PUBLIC attribute in a RequestScoped variable:

@Named
@RequestScoped
public class EventViewBean implements Serializable {

    @Produces
    public List<Meal> meals;

    public void setMeals(List<Meal> meals) {
 this.meals = meals;
    }

    public List<Meal> getMeals() {
  return meals;
    }

}

otherwise you get this error:

WELD-000075 Normal scoped managed bean implementation class has a public field

To fix the issue, just remove the "public" in "public List<Meal> meals;" and don't ask questions... it's all too sad... just smile and say yes.

No comments: