postconstruct

@PostConstruct method is called even if the ManagedBean has already been instantiated (e.g. on AJAX-calls) [duplicate]

跟風遠走 提交于 2019-11-27 15:14:09
问题 This question already has an answer here: @ViewScoped calls @PostConstruct on every postback request 1 answer I have a @ViewScope ManagedBean and a @PostConstruct initialisation method. This method is called when a new instance is created, but also on every ajax call. Why is this so? On an AJAX-call the init-Method is called and executed, but no changes are visible. For example if I change a property in the init-Method, this is only visible on instatiation and not for AJAX-calls. For AJAX

Why does @PostConstruct callback fire every time even though bean is @ViewScoped? JSF

℡╲_俬逩灬. 提交于 2019-11-27 03:34:44
I am using datatable on page and using binding attribute to bind it to my backing bean. This is my code :- <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.prime.com.tr/ui"> <h:head> <title>Facelet Title</title> </h:head> <h:body> <h:form prependId="false"> <h:dataTable var="item" value="#{testBean.stringCollection}" binding="#{testBean.dataTable}"> <h:column> <h:outputText

Guice call init method after instantinating an object

一个人想着一个人 提交于 2019-11-27 03:27:22
Is it possible to tell Guice to call some method (i.e. init()) after instantinating an object of given type? I look for functionality similar to @PostConstruct annotation in EJB 3. gpampara Actually, it is possible. You need to define a TypeListener to get the functionality going. Something along the lines of the following in your module definition: bindListener(Matchers.subclassesOf(MyInitClass.class), new TypeListener() { @Override public <I> void hear(final TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) { typeEncounter.register(new InjectionListener<I>() { @Override public void

@SessionScoped bean looses scope and gets recreated all the time, fields become null

南楼画角 提交于 2019-11-26 14:46:08
I have a very strange problem with a SessionScoped bean in a JSF 2.0 project. Using Netbeans 6.9.1, Glassfish 3 server and PrimeFaces 3 as the JSF component library. Here is some code: package com.hia.jsf; import com.hia.netlabel.jpa.Genre; import com.hia.netlabel.jpa.Label; import java.io.Serializable; import java.util.List; import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedProperty; @ManagedBean @SessionScoped public class LabelDetailJSF implements Serializable{ @ManagedProperty("#

How can I add FacesMessage during page load? Using @PostConstruct does not seem to work

Deadly 提交于 2019-11-26 04:27:05
问题 In a backing bean\'s @PostConstruct method, I make a call to an EJB which might return some messages that I want to display on the page via p:messages. However, even if I add the FacesMessages e.g. FacesContext.getCurrentInstance().addMessage(...), p:messages is not being updated with the FacesMessages. If I instead invoke the call to the EJB on an action from the page (say a user clicks a button on the page which invokes a method that calls the EJB and then adds the FacesMessage(s)), then

@SessionScoped bean looses scope and gets recreated all the time, fields become null

泪湿孤枕 提交于 2019-11-26 03:45:04
问题 I have a very strange problem with a SessionScoped bean in a JSF 2.0 project. Using Netbeans 6.9.1, Glassfish 3 server and PrimeFaces 3 as the JSF component library. Here is some code: package com.hia.jsf; import com.hia.netlabel.jpa.Genre; import com.hia.netlabel.jpa.Label; import java.io.Serializable; import java.util.List; import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedProperty;

When to use f:viewAction / preRenderView versus PostConstruct?

谁说胖子不能爱 提交于 2019-11-26 01:29:15
问题 When should one use the f:viewAction or preRenderView event to initialize data for a page versus using the @PostConstruct annotation? Is the rationale to use one or the other based on the type of scope of the backing bean e.g. If the backing bean is @RequestScoped , then would the choice of using f:viewAction or preRenderView over @PostConstruct to initialize your backing bean prior to rendering the view be irrelevant as the two would result in the same effect? f:viewAction or preRenderView

@ViewScoped calls @PostConstruct on every postback request

风格不统一 提交于 2019-11-25 22:38:44
问题 This doesn\'t seem right. I was doing some cleanup of my code and I just noticed this. Every ajax request is firing the constructor and @PostConstruct of my @ViewScoped bean. Even a simple database pagination is firing it. I understood that @ViewScoped is longer than @RequestScoped and that it shouldn\'t be reconstructed on every request. Only after a complete page reload by GET. 回答1: In other words, your @ViewScoped bean behaves like a @RequestScoped bean. It's been recreated from scratch on