I’m using boolean switchers to resolve a choosed behaviour of application, for example SAVEACCEPTED enables SAVE button of form.
<h:commandButton action="#{bean.save}" disabled="#{!bean.saveaccepted}">
JSF need private boolean and its getters and setters, but if I want to resolve some internal logic in application server, it must be defined static. For example
IF (USERFOUND) SAVEACCEPTED = true;
So, I’m using settings class and there are public static booleans defined. And in the beans there are getters and setters pointing to the Settings.VARIABLE
Settings.java
public static boolean SAVEACCEPTED = false;
Bean.java
public static boolean isSaveAccepted() {
return Settings.SAVEACCEPTED;
}
Problem is, that the public boolean is only one and if more then one users using an application, when the first switch the variable, it affects second user form.
How can I solve this issue, is there some standard solution?
Don’t use a
staticvariable. Use a@SessionScopedor@ViewScopedbean to store the settings separately for each user.and
Do not use a static variable.
If you need to set the value in another bean, you can
@Injectan instance:and CDI will give you the right instance of
Settings.BalusC comments:
Since it looks like you’re not using a full Java EE 6 container, you can use
@ManagedBeaninstead of@Namedand@ManagedPropertyinstead of@Inject.My apologies for sending you down a more complicated path!