@ViewScoped calls @PostConstruct on every postback request

In other words, your @ViewScoped bean behaves like a @RequestScoped bean. It’s been recreated from scratch on every postback request. There are many possible causes for this, most of which boils down that the associated JSF view is not available anymore in the JSF state which in turn is by default associated with the HTTP … Read more

Spawning threads in a JSF managed bean for scheduled tasks using a timer

Introduction As to spawning a thread from inside a JSF managed bean, it would only make sense if you want to be able to reference it in your views by #{managedBeanName} or in other managed beans by @ManagedProperty(“#{managedBeanName}”). You should only make sure that you implement @PreDestroy to ensure that all those threads are shut … Read more

Java EE vs JSP vs JSF [closed]

Is JSP “dead” in favor of JSF? JSF has countless benefits over JSP. For instance: It defines a MVC approach It set up componentization standards It has apply values feature Built-in AJAX A defined view context control Allows for rich interfaces extensions like Primefaces And we can go on and on. You can still use … Read more

JSF request scoped bean keeps recreating new Stateful session beans on every request?

Stateful session beans (SFSB) are not exactly what you think they are. You seem to think that they behave somehow like session scoped JSF managed beans. This is untrue. The term “session” in EJBs has an entirely different meaning than the HTTP session which you’ve had in mind. The “session” in EJBs must be interpreted … Read more

How to trigger component refresh from javascript in primefaces?

You can use PrimeFaces’ <p:remoteCommand> for this. <p:remoteCommand name=”updateGrowl” update=”showmessage” /> which is to be invoked as <p:commandButton … oncomplete=”addMemberDlg.hide(); updateGrowl();” /> In this particular case there’s however a simpler way. Set the autoUpdate attribute of <p:growl> to true. <p:growl autoUpdate=”true” life=”1500″ id=”showmessage”/> It’ll auto-update itself on every ajax request. If your component actually didn’t … Read more

Understand Flash Scope in JSF2

In short, variables stored in the flash scope will survive a redirection and they will be discarded afterwards. This is really useful when implementing a Post-Redirect-Get pattern. If you try to navigate to another page by redirect and access the attributes on load, they will be there. After that request is done the values in … Read more

CDI Injection into a FacesConverter

Replace @FacesConverter(value = “categoryConverter”) by @Named and use <h:inputSomething converter=”#{categoryConverter}” /> or <f:converter binding=”#{categoryConverter}” /> instead of <h:inputSomething converter=”categoryConverter” /> or <f:converter converterId=”categoryConverter” /> By the way, similar problem exist for @EJB inside a @FacesConverter. It however offers a way to be grabbed by JNDI manually. See also Communication in JSF 2.0 – Getting an … Read more

How can I get a message bundle string from inside a managed bean?

You can get the full qualified bundle name of <message-bundle> by Application#getMessageBundle(). You can get the current locale by UIViewRoot#getLocale(). You can get a ResourceBundle out of a full qualified bundle name and the locale by ResourceBundle#getBundle(). So, summarized: FacesContext facesContext = FacesContext.getCurrentInstance(); String messageBundleName = facesContext.getApplication().getMessageBundle(); Locale locale = facesContext.getViewRoot().getLocale(); ResourceBundle bundle = ResourceBundle.getBundle(messageBundleName, … Read more

tech