Unicode input retrieved via PrimeFaces input components become corrupted

Introduction Normally, JSF/Facelets will set the request parameter character encoding to UTF-8 by default already when the view is created/restored. But if any request parameter is been requested before the view is been created/restored, then it’s too late to set the proper character encoding. The request parameters will namely be parsed only once. PrimeFaces encoding … Read more

Session timeout and ViewExpiredException handling on JSF/PrimeFaces ajax request

Exceptions which are thrown during ajax requests have by default totally no feedback in the client side. Only when you run Mojarra with project stage set to Development and use <f:ajax>, then you will get a bare JavaScript alert with the exception type and message. But other than that, and in PrimeFaces, there’s by default … Read more

Pass parameter to p:remoteCommand from JavaScript

Yes, it is possible. How to do that depends on the PrimeFaces version. You can see it in PrimeFaces users guide. PrimeFaces 3.3 or newer Since PrimeFaces version 3.3 the syntax is as follows (copypasted from 3.3 users guide). 3.81 RemoteCommand … Passing Parameters Remote command can send dynamic parameters in the following way; increment([{name:’x’, … Read more

Component to inject and interpret String with HTML code into JSF page

JSF by default escapes HTML from backing bean properties in order to prevent XSS attack holes. To disable this, just set the escape attribute of the <h:outputText> to false. <h:outputText … escape=”false” /> This way the HTML won’t be escaped and will thus be interpreted by the webbrowser. Unrelated to the concrete problem, beware of … Read more

Keep p:dialog open when a validation error occurs after submit

The onsuccess runs if ajax request itself was successful (i.e. there’s no network error, uncaught exception, etc), not if action method was successfully invoked. Given a <p:dialog widgetVar=”yourWidgetVarName”>, you could remove the onsuccess and replace it by PrimeFaces RequestContext#execute() inside saveMethod(): if (success) { RequestContext.getCurrentInstance().execute(“PF(‘yourWidgetVarName’).hide()”); } Note: PF() was introduced in PrimeFaces 4.0. In older … Read more

How can I populate a text field using PrimeFaces AJAX after validation errors occur?

The cause of the problem can be understood by considering the following facts: When JSF validation succeeds for a particular input component during the validations phase, then the submitted value is set to null and the validated value is set as local value of the input component. When JSF validation fails for a particular input … Read more

Manually adding / loading jQuery with PrimeFaces results in Uncaught TypeErrors

PrimeFaces is a jQuery based JSF component library. It already ships with jQuery and jQuery UI out the box. It is not right to manually load another copy of jQuery/jQuery UI for some reason. Multiple different versioned jQuery files would only conflict with each other this way, because they do not necessarily use/share exactly the … Read more

How to invoke a JSF managed bean on a HTML DOM event using native JavaScript?

Several ways. Use <h:commandScript>. Note that this is only available since JSF 2.3. <h:form> <h:commandScript name=”commandName” action=”#{bean.action}” render=”:results” /> </h:form> <h:panelGroup id=”results”> … </h:panelGroup> You can invoke it in JS as below: commandName(); The parameters can be passed as below: commandName({ name1: “value1”, name2: “value2” }); And obtained as below: String name1 = externalContext.getRequestParameterMap().get(“name1”); // … Read more