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

Why Facelets is preferred over JSP as the view definition language from JSF 2.0 onwards?

True, JSP has some templating capabilities, but the biggest disadvantage of using JSP in JSF is that JSP writes to the response as soon as it encounters template text content, while JSF would like to do some pre/post processing with it. In JSF 1.0/1.1 the following JSF code <h:outputText value=”first”/> second <h:outputText value=”third”/> fourth would … Read more

How to ajax-refresh dynamic include content by navigation menu? (JSF SPA)

A straightforward approach would be the following view: <h:panelGroup id=”header” layout=”block”> <h1>Header</h1> </h:panelGroup> <h:panelGroup id=”menu” layout=”block”> <h:form> <f:ajax render=”:content”> <ul> <li><h:commandLink value=”include1″ action=”#{bean.setPage(‘include1’)}” /></li> <li><h:commandLink value=”include2″ action=”#{bean.setPage(‘include2’)}” /></li> <li><h:commandLink value=”include3″ action=”#{bean.setPage(‘include3’)}” /></li> </ul> </f:ajax> </h:form> </h:panelGroup> <h:panelGroup id=”content” layout=”block”> <ui:include src=”/WEB-INF/includes/#{bean.page}.xhtml” /> </h:panelGroup> With this bean: @ManagedBean @ViewScoped public class Bean implements Serializable { private … Read more

Why do I need to nest a component with rendered=”#{some}” in another component when I want to ajax-update it?

Ajax updating is performed by JavaScript language in the client side. All which JavaScript has access to is the HTML DOM tree. If JSF does not render any component to the HTML output, then there’s nothing in the HTML DOM tree which can be obtained by JavaScript upon Ajax update. JavaScript cannot get the desired … Read more

DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled.

just add this attribute rowKey to the datatable tag : <p:dataTable border=”1″ value=”#{projectAdminisrationMB.projectNoUsersList}” var=”userObj” rowKey=”#{userObj.name}”selection=”#{projectAdminisrationMB.selectedUsers}” selectionMode=”multiple” rowIndexVar=”rowIndex” binding=”#{table2}”>

Opening JSF Facelets page shows “This XML file does not appear to have any style information associated with it.”

This XML file does not appear to have any style information associated with it. The document tree is shown below. You will get this message in the client side when the client (the web browser) for some reason interprets the HTTP response content representing a HTML document as text/xml instead of text/html and the parsed … Read more

How to show user-friendly error page in browser when runtime exception is thrown by servlet?

Just declare an <error-page> in web.xml wherein you can specify the page which should be displayed on a certain Throwable (or any of its subclasses) or a HTTP status code. E.g. <error-page> <exception-type>java.lang.Exception</exception-type> <location>/error.jsp</location> </error-page> which will display the error page on any subclass of the java.lang.Exception, but thus not java.lang.Throwable or java.lang.Error. This way … Read more