Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

primefaces and JSF 2.3 javascript error Cannot read property 'error' of null

I am using primefaces with JSF2.3

here is the way my dependencies are

    dependencies {

    providedCompile 'javax.servlet:javax.servlet-api:4.0.0'
    compile group: 'javax.faces', name: 'javax.faces-api', version: '2.3'
    compile group: 'org.glassfish', name: 'javax.faces', version: '2.3.3'
    compile 'javax.servlet:jstl:1.2'
    compile 'org.jboss.weld.servlet:weld-servlet:2.4.5.Final'
    compile group: 'org.primefaces', name: 'primefaces', version: '6.2'
}

my jsf file is very basic

   <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
<f:view>
    <h:outputLabel value="Hello, world"/>
    <h:form>
        <p:selectOneMenu value="#{testView.chosen}"
                         style="width:200px">
            <f:selectItem itemLabel="Select listing template"/>
            <f:selectItems value="#{testView.list}"/>
            <p:ajax event="change" process="@this" update="@all"/>
        </p:selectOneMenu>
    </h:form>
</f:view>
</html>

and my viewScoped bean also

    @Named
@ViewScoped
public class TestView implements Serializable {
String chosen;
List<String> list;

@PostConstruct
public void setup(){
    list = new ArrayList<>();
    list.add("alpha");
    list.add("gamma");
    list.add("bravo");
}

getter and setter are ommited for simplicity.

the thing is that I used to work with (jsf 2.2, primefaces 6.1) and everything is working fine.

after the upgrade (jsf 2.3, primefaces6.2), I have a problem whenever the event change (when i change selection is triggered)

the error is

Uncaught TypeError: Cannot read property 'error' of null
    at Object.<anonymous> (core.js.xhtml?ln=primefaces&v=6.2:3)
    at i (jquery.js.xhtml?ln=primefaces&v=6.2:2)
    at Object.fireWith [as resolveWith] (jquery.js.xhtml?ln=primefaces&v=6.2:2)
    at A (jquery.js.xhtml?ln=primefaces&v=6.2:4)
    at XMLHttpRequest.<anonymous> (jquery.js.xhtml?ln=primefaces&v=6.2:4)

Is there any conflict javascript between jsf2.3 and primefaces ?

like image 877
Toumi Avatar asked Mar 02 '18 14:03

Toumi


2 Answers

AFAICS this is a bug in Mojarra, i would create a issue there. Seems like the component resources are available (see PrimeFaces HeadRenderer) in the postback but somehow they are not rendered in the response inside the head tag.

NOTE: this will only happen with update=@all as otherwise the head-tag won't be replaced. Actually update=@all shoudln't be used, only if really really really necessary.

like image 99
tandraschko Avatar answered Sep 28 '22 08:09

tandraschko


There's a problem with mojarra, because it should send all the files when you want to render "all".

Meanwhile, there is an alternative solution mentioned here: https://github.com/javaserverfaces/mojarra/issues/4354

You can execute the following script after primeface has loaded, so it can change the way PF renders the HEAD:

https://github.com/javaserverfaces/mojarra/files/2626517/primefaces_replacehead_hack.js.txt

With it, PF wont replace the head and the code will probably continue to work.

It worked for me.

like image 45
0xfthul Avatar answered Sep 28 '22 06:09

0xfthul