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

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

Conditionally provide either file download or show export validation error message

Is there any generally acceptable way of solving issues like this one? You basically want to fire an ajax request first and in its oncomplete check if it’s successful, and then trigger a synchronous request to download the file (note that you can’t download files with ajax). You could make use of FacesContext#validationFailed() (or OmniFaces … Read more

Primefaces dialog + commandButton

You can try either of the following , I vote number one, it’s a cleaner design IMO Bring the <p:dialog/> outside of the general <h:form/> and put an <h:form/> inside it instead <p:dialog id=”dlg” header=”#{messages.chooseSkillLevel}” widgetVar=”dlg” modal=”true” dynamic=”true”> <h:form> <h:dataTable value=”#{editSkills.skillsAndLevels}” var=”skillslevel”> <h:column> #{skillslevel.skill.umiejetnosc} </h:column> <h:column> <p:selectOneMenu value=”#{skillslevel.level}” > <f:selectItems value=”#{editSkills.levels}” var=”level” itemLabel=”#{level.stopien}” itemValue=”#{level.id}” /> … Read more

LazyInitializationException in selectManyCheckbox on @ManyToMany(fetch=LAZY)

You need to fetch it while inside a transaction (thus, inside the service method), and not while outside a transaction (thus, inside e.g. JSF managed bean init/action method), that would thus throw a LazyInitializationException. So, your attempt hardware.getConnectivities().size(); has to take place inside a transaction. Create if necessary a new service method for the purpose … Read more

Keep open when validation has failed

The PrimeFaces ajax response puts an args object in the scope which has a validationFailed property. You could just make use of it. oncomplete=”if (args &amp;&amp; !args.validationFailed) PF(‘editDialog’).hide()” (the args precheck is necessary to not cause a JS error when an exception is thrown during request) You could refactor it to a reusable JS function … Read more