0

i am using JSF 2 and Primefaces 5 and i am trying to show p:dialog when the object "client" is null (not instantiated) like below :

<p:commandLink update=":form:connecterPanel" 
   oncomplete="#{empty loginBean.client ? PF('connectDialog').show():''}" title="add to panel">
   <h:outputText styleClass="ui-icon ui-icon-cart" style="margin:0 auto;" />
</p:commandLink>

But i am getting the error Function 'PF' not found

Hen
  • 253
  • 1
  • 2
  • 16
  • Just a quick thought: `empty` is a bitch in EL-Expressions. I faced similiar issues quite often, the cause are missing brackets. Try `(empty loginBean.c)?`. – dognose May 23 '17 at 22:33
  • i am still getting the same error ! – Hen May 23 '17 at 22:41

1 Answers1

1

I solved it using this :

oncomplete="if(#{empty loginBean.client }){PF('connectDialog').show()}"
Hen
  • 253
  • 1
  • 2
  • 16
  • 1
    That is weird. Are you 100% sure it is the only thing you changed? – Kukeltje May 24 '17 at 06:39
  • @Kukeltje yes it was the only thing i have changed, i got the answer from here https://stackoverflow.com/a/25359606/4663461 – Hen May 24 '17 at 10:47
  • Omfg, didn't see the obvious :-) Yes, ofc. `PF()` is a javascript-method, while el-expressions itself are not aware of javascript-methods. So, in your first code, java searched for a method "PF()", which is wrong. So, what should also work: Inside the EL-Expression, print the function call as "String", which then will be valid Java-Script after html-generation: `oncomplete="#{empty loginBean.client ? \"PF('connectDialog').show()\":''}` (not sure about the escaping) evaluates to `"oncomplete="PF('connectDialog').show()"` or `oncomplete=""` depending on the condition. – dognose May 24 '17 at 15:07
  • 1
    A, i remember: in EL, concatenating strings is a terrible thing with concat, see here: https://stackoverflow.com/questions/17008504/how-do-i-append-a-quote-to-a-string-in-jsf-el - so your approach is clearly a "good" one, even if the generated html `oncomplete="if(true){PF('connectDialog').show()"` looks strange, if someone checks the source code :-) – dognose May 24 '17 at 15:12
  • Another approach would be to generate the javascript-string inside a bean-method, and use it like `oncomplete="#{loginBean.onCompleteJavascript}"` with `public string getOnCompleteJavascript(){ if (!this.client.isEmpty()))return "PF('connectDialog').show()"; return "";}` – dognose May 24 '17 at 15:14
  • @dognose thanks for the link :) i am getting an issue here https://stackoverflow.com/q/44159640/4663461 can you check it please !! – Hen May 24 '17 at 15:20