managed-bean

JSF 2 managed bean does not get instantiated

删除回忆录丶 提交于 2019-12-19 10:46:05
问题 I am having this problem in this sample jsf project I created. Managed beans do not get instantiated. Bean class: @ManagedBean(name="loginMB") @RequestScoped public class LoginMB extends AbstractMB { private static final long serialVersionUID = -8523135776442886000L; @ManagedProperty("#{userMB}") private UserMB userMB; //getters and setters public String login() { UserSupport userSupport = new UserSupportImpl(); User user = userSupport.isValidLogin(email, password); if (user != null) {

When should you explicity name a Managed Bean?

为君一笑 提交于 2019-12-19 03:41:38
问题 With all the research I've done on creating managed beans, what I've not noticed (or what I may have overlooked) is when to use explicit naming of the bean e.g. @Named(name = "someBean") . I guess what it hard for me to understand is why you would want to name the bean anything other than your class name: @Named(name = "someBean") public class SomeBean implements Serializebale { } With all the examples I've seen, some use the the explicit name and some just use @Named to leave the default

What is the equivalent of @ManagedBean(eager=true) in CDI

怎甘沉沦 提交于 2019-12-19 00:45:51
问题 As we all know that it is recommended to use annotations from javax.enterprise.context instead of javax.faces.bean as they are getting deprecated. And we all found ManagedBeans with eager="true" annotated with @ApplicationScoped from javax.faces.bean and having a @PostConstruct method are very useful to do web application initialization e.g: read properties from file system, initialize database connections, etc... Example : import javax.faces.bean.ApplicationScoped; import javax.faces.bean

Can CDI managed beans and JSF managed beans talk to each other?

烂漫一生 提交于 2019-12-18 16:57:41
问题 I have a Tomcat 6 JSF web application that I'd like to set up with CDI beans. I will have to convert the project to CDI gradually though. My question is: can CDI beans and traditional JSF managed beans be injected into each other? Thanks. 回答1: All JSF managed beans (JMB) either are CDI managed beans (CMB) automatically, or can be recognized as such using the beans.xml marker file. (The requirements of a CMB are set very low and basically just dictate the existence of a non-parameter

How to register a JSF managed bean programmatically?

血红的双手。 提交于 2019-12-18 11:59:32
问题 I'd like to register/add a Managed Bean class programmatically (from within a Servlet init()) into application scope. How can I do that with JSF 1.2? 回答1: from within a Servlet init() So, it concerns a non-JSF request. The FacesContext#getCurrentInstance() would return null here, so it's of no use for you here. It's good to know that JSF application scoped managed beans are basically stored as an attribute of the ServletContext . In the init() method you've the ServletContext at your hands by

How to redirect from a ManagedBean for when the request sent is an Ajax request?

和自甴很熟 提交于 2019-12-18 11:07:51
问题 I am using PrimeFaces with JSF2. I am trying to authenticate user by sending login and password as an Ajax request. And in the action method of the backing bean, I am trying to validate user and redirect to a new view if the validation succeeds. Is this possible while using primefaces? Because I think with primefaces' p:commandButton , I can only either have ajax behavior or the navigation. 回答1: Yes, just send a redirect instead of a (default) forward as outcome. The <navigation-case> -less

Are there going to be two instances for a bean if I write @managed bean annotation and define same in faces-config.xml

依然范特西╮ 提交于 2019-12-18 09:06:53
问题 In my application in some places we are using @ManagedBean annoation for Person bean and for the same Person bean we defining in the faces-confing.xml like below at the same time. @ManagedBean("name=person") @SessionScoped Public class Person{ } faces-config.xml <managed-bean> <managed-bean-name>person</managed-bean-name> <managed-bean-class>com.test.sample.Person</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> my question is does this approach create two

How to pass backing bean value to JavaScript?

做~自己de王妃 提交于 2019-12-18 07:14:41
问题 I would like to read the backing bean value in JSF and then pass over to JavaScript, may I know how this can be done? Backing bean sample code: @ManagedBean(name="enquiry") @SessionScoped public class Enquiry { public boolean noQuery; /** getter and setter **/ } In XHTML sample code, I would like pass the backing bean value and then pass into showNoQueryPrompt() like this: <h:commandLink onClick="showNoQueryPrompt(#{enquiry.noQuery})"> </h:commandLink> And then in JavaScript code, I can read

How to get properties file from /WEB-INF folder in JSF?

时间秒杀一切 提交于 2019-12-18 05:11:24
问题 I have some properties file in /WEB-INF . And I want to load it in a JSF managed bean. Is there any way to do that? 回答1: Use either ExternalContext#getResource() or ExternalContext#getResourceAsStream() wherein you pass the webcontent-relative path. E.g.: ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); Properties properties = new Properties(); // ... properties.load(externalContext.getResourceAsStream("/WEB-INF/file.properties")); This delegates under

How to get properties file from /WEB-INF folder in JSF?

自闭症网瘾萝莉.ら 提交于 2019-12-18 05:11:12
问题 I have some properties file in /WEB-INF . And I want to load it in a JSF managed bean. Is there any way to do that? 回答1: Use either ExternalContext#getResource() or ExternalContext#getResourceAsStream() wherein you pass the webcontent-relative path. E.g.: ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); Properties properties = new Properties(); // ... properties.load(externalContext.getResourceAsStream("/WEB-INF/file.properties")); This delegates under