annotations - How to annotate helper class to be visible inside JSF? -


i have helper class, neither stateful managed bean, nor stateless ejb, nor entity mapped table via jpa or hibernate. collection of static methods simple things return date formats , similar.

given that, in order java class visible inside jsf, class must annotated in way container assigns visible jsfs, there way annotate helper class not match of standard jsf visible categories becomes visible? alternative, of course, have conduit method in managed bean passes call jsf helper class prefer not clutter managed bean if can call directly jsf. understand doing stateless ejb jsf considered anti-pattern methods in class wish use simple , non-transactional.

mark class @applicationscoped. make sure has public no-arg constructor , class doesn't have state , methods thread safe.

e.g.

managed bean (pure jsf)

//this important import javax.faces.bean.applicationscoped;  @managedbean @applicationscoped public class utility {     public static string foo(string another) {         return "hello " + another;     } } 

cdi version

//this important import javax.enterprise.context.applicationscoped;  @named @applicationscoped public class utility {     public static string foo(string another) {         return "hello " + another;     } } 

view

<h:outputtext value="#{utility.foo('amphibient')}" /> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Restarting Supervisor and effect on FlaskSocketIO -