How to override stylesheets of PrimeFaces? [duplicate]

If using primefaces 2.2.1, Use the h:outputStylesheet tag and include it in h:body not in h:head to override primefaces stylesheets, same with h:outputScript. Example: <h:body> <h:outputStylesheet library=”css” name=”YOURSTYLES.css” /> <h:outputScript library=”javascript” name=”YOURSCRIPT.js” target=”head” /> </h:body> If using primefaces 3, follow this blog entry https://www.primefaces.org/resource-rendering/

Populate p:selectOneMenu based on another p:selectOneMenu in each row of a p:dataTable

Whilst your initial solution works, it’s in fact inefficient. This approach basically requires the entire object graph of the Country and State tables (even with circular references) to be fully loaded in Java’s memory per JSF view or session even though when you simultaneously use only e.g. 5 of 150 countries (and thus theoretically 5 … Read more

Disable row selection for a few rows only in a p:dataTable

Since 4.0 version, Primefaces datatable comes with a disabledSelection property. <p:dataTable var=”foo” value=”#{bean.foos}” selection=”#{bean.selectedFoo}” disabledSelection=”#{foo.bar == 1}”> <p:column selectionMode=”single” /> <p:column> <h:outputText value=”#{foo.bar}” /> </p:column> <p:dataTable> Then, when foo.bar == 1 is true, checkbox will be disabled.

Remove all styling from Primefaces components?

Set primefaces.THEME context parameter to none and you’ll get a functional ui with no styles. <context-param> <param-name>primefaces.THEME</param-name> <param-value>none</param-value> </context-param> You don’t need to spend hours editing styles. Styling of PrimeFaces is done via shared styles like ui-widget-header, ui-widget-content which you can customize via the themeroller web form. I don’t think JSF and theming can get … 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

selectOneMenu ajax events

The PrimeFaces ajax events sometimes are very poorly documented, so in most cases you must go to the source code and check yourself. p:selectOneMenu supports change event: <p:selectOneMenu ..> <p:ajax event=”change” update=”msgtext” listener=”#{post.subjectSelectionChanged}” /> <!–…–> </p:selectOneMenu> which triggers listener with AjaxBehaviorEvent as argument in signature: public void subjectSelectionChanged(final AjaxBehaviorEvent event) {…}

Defer loading and parsing of PrimeFaces JavaScript files

Use <o:deferredScript> Yes, it is possible with the <o:deferredScript> component which is new since OmniFaces 1.8.1. For the technically interested, here’s the involved source code: The UI component: DeferredScript The HTML renderer: DeferredScriptRenderer The JS helper: deferred.unminified.js Basically, the component will during the postAddToView event (thus, during the view build time) via UIViewRoot#addComponentResource() add itself … Read more

Store PDF for a limited time on app server and make it available for download

Make use of File#createTempFile() facility. The servletcontainer-managed temporary folder is available as application scoped attribute with ServletContext.TEMPDIR as key. String tempDir = (String) externalContext.getApplicationMap().get(ServletContext.TEMPDIR); File tempPdfFile = File.createTempFile(“generated-“, “.pdf”, tempDir); // Write to it. Then just pass the autogenerated file name around to the one responsible for serving it. E.g. String tempPdfFileName = tempPdfFile.getName(); // … Read more