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
Post a Comment