Calling Primefaces dialog box from Managed Bean function

You can, by using the RequestContext (or PrimeFaces if you are using the version 6.2 or higher) class. Suppose you have the following: <p:dialog id=”myDialogID” widgetVar=”myDialogVar”> …. </p:dialog> So the way you do in the facelet itself, i.e. onclick=myDialogVar.show();, the same can be done in your managed bean like so: For PrimeFaces <= 3.x RequestContext … Read more

How to reference a CSS / JS / image resource in JSF?

Introduction The proper way is using <h:outputStylesheet>, <h:outputScript> and <h:graphicImage> with a name referring the path relative to webapp’s /resources folder. This way you don’t need to worry about the context path. Folder structure Drop the CSS/JS/image files in /resources folder of the public webcontent as below (just create one if not already exist at … Read more

What is the difference between FacesContext and ExternalContext

Carefully look in their javadocs to see what methods they offer and what exactly those methods all do. FacesContext javadoc ExternalContext javadoc If you look closer at those methods listed in the javadoc, you’ll notice that the FacesContext generally offers access to JSF-specific artifacts which are further in no way related to the “underlying” Servlet … Read more

Default selection for within

<h:selectOneMenu id=”items” value=”#{bean.selectedItem}”> <f:selectItem itemLabel=”10″ itemValue=”10″/> <f:selectItem itemLabel=”20″ itemValue=”20″/> <f:selectItem itemLabel=”30″ itemValue=”30″/> </h:selectOneMenu> The default selection would be the one which has value same as selectedItem which you set in bean. selectedItem = 20;

Creating master-detail pages for entities, how to link them and which bean scope to choose

What is the correct usage of session scope Use it for session scoped data only, nothing else. For example, the logged-in user, its settings, the chosen language, etcetera. See also: How to choose the right bean scope? And every time I visit the page, the product list will be created from the latest entries in … Read more

@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

JSF — over a java.util.Set?

The easiest way to finish the deal at page without modifying the class is converting the set to an array like this. <ui:repeat value=”#{myBean.mySet.toArray()}” var=”_myvar”>

tech