managed-bean

Eager ApplicationScoped managed beans constructed multiple times

别说谁变了你拦得住时间么 提交于 2019-11-29 15:03:09
问题 I have a bunch of eager ApplicationScoped managed beans. Some of them are injected into others by the ManagedProperty annotation, forming a tree of dependencies. Each depending bean manipulates its parent after construction. However, it seems like a new instance is created for each injection, thus making previous manipulations undone. To my understanding, an ApplicationScoped bean should only be created once. Have I misunderstood or why is this happening? Is it because they are eager? Here is

JSF messages persistance

僤鯓⒐⒋嵵緔 提交于 2019-11-29 12:10:54
I have a viewScoped bean which has some business logic validation. I display the resultant errors from this validation to the page using FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(severity, result, null)); The problem is: user submits invalid form form redisplayed, messages not displayed to user due to using PRG I solved this using the following line of code: FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true); Now the problem is that the business logic validation messages persist too long: user submits invalid form form redisplayed

How to create and use a generic bean for enums in f:selectItems?

人走茶凉 提交于 2019-11-29 11:50:01
I have generic class with this signature: public abstract class EnumListBean<E extends Enum<E>> { public List<E> getEnumList() { //implementation details } } Currently I have to define a empty subclass in order to access the enumList property for a concrete generic parameter: @ManagedBean @ApplicationScoped public class ItemRarityBean extends EnumListBean<Item.Rarity>{ } This makes its possible to access the property e.g: <f:selectItems value="#{itemRarityBean.enumList}" var="rarity" itemLabel="#{rarity.readableName}" itemValue="#{rarity}" /> Im wondering whether one really have to declare a

Data from @RequestScoped bean is shared in different browsers

筅森魡賤 提交于 2019-11-29 11:44:09
I have a @RequestScoped bean with a List property. import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import org.springframework.stereotype.Controller; @Controller @ManagedBean @RequestScoped public class MyBean implements Serializable { private List list; // getters and setters } This property is linked to a datatable: <ice:dataTable value="#{myBean.list}" ..other stuff.. /> The List is dynamically filled with no problem, and the datatable is displayed with no problems. But if, I navigate to another page, and then go back to the initial page the datatable is still

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

浪子不回头ぞ 提交于 2019-11-29 08:00:47
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? BalusC 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 the covers to ServletContext#getResource() / getResourceAsStream() . See also: Where to place and

Using JSF EL in a plain HTML attribute

妖精的绣舞 提交于 2019-11-29 07:30:10
Can we use JSF EL inside a HTML tag? For example, inside a plain HTML <td> element, can we use EL #{bean.color} for the bgcolor attribute? <td bgcolor="#{bean.color}"> BalusC The answer depends on the JSF version and the view technology used. The technical term you're looking for is "using EL in template text" (i.e. not inside any tag/component). As per your question history you're using JSF 1.2 on Websphere. I assume that you're still using old JSP, the predecesor of Facelets. Whether JSF EL #{} works in template text depends on the JSP version used. JSP version goes hand in hand with Servlet

Is there a way to call a method upon leaving a page with JSF or PrimeFaces?

爱⌒轻易说出口 提交于 2019-11-29 06:42:31
Is there a way to call a method upon leaving a page with JSF? Not when using native JSF or PrimeFaces. Your best bet would be to hook on session expiration instead. import javax.inject.Named; import javax.enterprise.context.SessionScoped; @Named @SessionScoped public class Bean implements Serializable { @PreDestroy public void destroy() { // Your code here. } } If you happen to use the JSF utility library OmniFaces , then you can use its @ViewScoped . This will call the @PreDestroy when leaving the page referencing the view scoped bean. import javax.inject.Named; import org.omnifaces.cdi

@PostConstruct didn't get called by JSF if ManagedBean is inside jar library

假装没事ソ 提交于 2019-11-29 04:42:00
I'm running with the following problem. I have a few Managed Beans that are shared between, at this moment, two JSF applications. As I don't want to copy and paste the code in the two (more in the coming future) I've put this shared managed beans inside a JAR library. I've followed this blog: http://jsflive.wordpress.com/2011/03/24/custom-component-library/ Well, even if I put the faces-config.xml inside JAR/META-INF/ the @ManagedBean and @ViewScoped didn't work. I couldn't realise why, but if I register the beans in faces-config.xml (JAR ones, not WAR ones) this problem goes away. I could

Inject EJB bean from JSF managed bean programmatically

∥☆過路亽.° 提交于 2019-11-29 04:36:24
I have EJB stateless bean. How can I inject it to JSF managed bean by programmatic instead of @EJB annotation? You can't inject it programmatically. You can however obtain it programmatically. EJBs are also available via JNDI . Usually, you find those JNDI names/aliases printed in server startup log. At least JBoss / WildFly does that. There are different JNDI name aliases: java:global/APP_NAME[/MODULE_NAME]/EJB_NAME java:app/MODULE_NAME/EJB_NAME java:module/EJB_NAME Where /APP_NAME is the name of the WAR or EAR application, and /MODULE_NAME is the name of the EJB module in case of an EAR

JSF bean: call @PostConstruct function after ViewParam is set

匆匆过客 提交于 2019-11-29 01:56:41
I have a product.xhtml and a ProductBean. I use /product/{id} to access the products so I have a viewParam in product.xhtml with value=ProductBean.id. The problem is that inside the bean I use an init function with a PostConstruct annotation in order to fill the details of the product. To do this I need the id to call an external function. I guess though that init is called before viewParam sets the id of the bean and therefore inside init I cannot call the external function because id is not set yet. What am I doing wrong and how do I fix this? UPDATE I found what was wrong. I think the