javascriptprimefaces

No behavior available in Primefaces widget


I want to fill an Primefaces inputText field by Javascript and trigger then the change event. In my understanding of the documentation of the inputText widget the callBehavior function would be the right way.

So my field looks like this:

<p:inputText id="myInput" value="#{myBean.value}">
   <p:ajax event="change" update="@this" onstart="console.log('Change triggered')" />
</p:inputText>

My JS function looks like this

function myFun() {
   const theId = // Have to get the id dynamically
   const inputWdgt = PrimeFaces.getWidgetById(theId);
   inputWdgt.jq.val('My new value');
   inputWdgt.callBehavior('change');
}

But in result neither the log in the onstart is printed nor the update is executed.

In my further investigation I saw, that the cfg object in the browser doesn't contain any behaviors. Hence it is obvious, that the callBehavior has no effect (since the function relates to these). So the question would be, why are there no behaviors defined for the widget?


Solution

  • Its a bug. Can't believe no one ever reported this.

    Bug: https://github.com/primefaces/primefaces/issues/12887

    PR: https://github.com/primefaces/primefaces/pull/12888

    It will be fixed in PF 14.0.8+