Skip required validation and invoke the application

Just put that condition straight in the required attribute. <h:inputText … required=”#{someCondition}” /> It namely just accepts any EL expression like as many other attributes. Many starters think that you can only hardcode a “true” or “false” string in it. This is untrue. For example, when you want to let it evaluate true only when … Read more

JSF resource versioning

If I do like this resources/js/1_0_0/mainscript.js It does not work. It says RESOURCE_NOT_FOUND This will work if you specify js as library name. <h:outputScript library=”js” name=”mainscript.js” /> However, this is not the proper usage of a resource library. Rather introduce one. resources/default/1_0_0/js/mainscript.js Then you can specify it as follows: <h:outputScript library=”default” name=”js/mainscript.js” /> They did … Read more

FacesContext.getCurrentInstance() returns null in Runnable class

The FacesContext is stored as a ThreadLocal variable in the thread responsible for the HTTP request which invoked the FacesServlet, the one responsible for creating the FacesContext. This thread usually goes through the JSF managed bean methods only. The FacesContext is not available in other threads spawned by that thread. You should actually also not … Read more

Ajax update and submission using h:commandButton

This is to be done by nesting a <f:ajax> in it. In effects, <p:commandButton … process=”@form” update=”:statusBlock” /> does exactly the same as <h:commandButton …> <f:ajax execute=”@form” render=”:statusBlock” /> </h:commandButton> Note that the subtle difference with the PrimeFaces equivalent is that PrimeFaces defaults to @form in the process/execute, while the <f:ajax> one defaults to @this, … Read more

Automatically open the printer dialog after providing PDF download

With JasperReports When using JasperReports, simply add this parameter to JasperReports exporter: exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, “this.print();”); This basically instructs Adobe Acrobat to execute the script this.print() when opening the PDF. See also page 79-80 of Adobe Acrobat Scripting Guide. Below is an extract of relevance: Printing PDF Documents It is possible to use Acrobat JavaScript to specify … Read more