How do I display a message if a jsf datatable is empty?

Make use of the rendered attribute. It accepts a boolean expression. You can evaluate the datatable’s value inside the expression with help of the EL’s empty keyword. If it returns false, the whole component (and its children) won’t be rendered. <h:outputText value=”Table is empty!” rendered=”#{empty bean.list}” /> <h:dataTable value=”#{bean.list}” rendered=”#{not empty bean.list}”> … </h:dataTable> For … Read more

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

Should I use Facelets “jsfc” attribute?

As you said, the jsfc attribute is essentially usefull when you have to “convert” an HTML prototype to a JSF page. For example, when you have an HTML input text: <input type=”text” …/> you can add the jsfc attribute in order to convert this HTML component into a JSF component: <input type=”text” jsfc=”h:inputText” …/> This … Read more

Modular web apps

You are very right in thinking there are synergies here, we have a modular web app where the app itself is assembled automatically from independent components (OSGi bundles) where each bundle contributes its own pages, resources, css and optionally javascript. We don’t use JSF (Spring MVC here) so I can’t comment on the added complexity … 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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)