Khuzi
Khuzi

Reputation: 2912

Problem with submitting form in JSF+PrimeFaces after using widgetvar

I am using widgetVar to enable a command button through javascript on some event. However after enabling command button, when I click the button, the form is not submitted and action is not called on server side.

The same setup works fine if I don's use widgetVar and keep button enabled by default. It submits the funciton, calls the actions and displays the result.

FYI, I am using ajax call.

<p:commandButton id="btnSearch" value="Search" disabled="true"
    widgetVar="searchButton"
    ajax="true"
    action="#{someBean.someFunction(someBean.firstName, someBean.lastName)}">
    <p:ajax
        execute="firstName lastName"
        render="tabViewId:resultsDataTableId"
        onsuccess="showSearchResults()"/>
</p:commandButton>

Javascript -

function onSomeEvent(){
    PF('searchButton').enable();
}

Please advice.

Upvotes: 0

Views: 151

Answers (1)

Kukeltje
Kukeltje

Reputation: 12337

If you'd debug the network tab in the browser there is a chance you'd see network traffic when the button is enabled like this (on the other hand you might not but you should have inspected this). So that would mean the submission to the server is actually taking place, it is just not processed. Why that is?

It is by design and is a feature that is native to JSF to prevent client-side tampering with forms/data/... Other modern (read hyped) client-side javascript frameworks would need additional OWASP protection to achieve the same level of security that JSF has. So if you want to enable a button from the client side, you should do an ajax call to update the state of the button (and check if the client is allowed to do that). Or you could enable it by default and with some javascript initially disable it. I'd personally would go for the former.

Upvotes: 3

Related Questions