hamid147
hamid147

Reputation: 59

Primefaces selectOneMenu changes value after page refresh in firefox

I am using PrimeFaces SelectOneMenu with change event call. When I change it's value, the change method calls and sets some parameters. when I refresh the page, in the bean side, selected value changes to default but in the UI, changed value showed. So, when user clicks on the submit, the setter method changes the value but change method don't calls. Here is UI code:

<p:selectOneMenu value="#{bean.selectedType}">
    <f:selectItems value="#{bean.types}"/>
    <p:ajax event="change" listener="#{bean.changeType}" update=":form"/>
</p:selectOneMenu>
<p:commandButton actionListener="#{bean.changeType}" update=":form"/>

Upvotes: 0

Views: 2315

Answers (5)

Dilapidus
Dilapidus

Reputation: 425

For me, this was solved via the example in https://www.logicbig.com/tutorials/misc/primefaces/select-one-menu-with-ajax.html

The key is that the ajax change event isn't well supported (it does not appear to fire the update). Using itemSelect instead completely fixed this problem for me.

<p:ajax event="itemSelect" update="@all"/>

Upvotes: 0

Dominik
Dominik

Reputation: 11

I recently had the same problem and was able to solve it by adding explicit no-cache instructions to the HTTP-Header.

e.g. implement the javax.servlet.Filter class and do something like

    HttpServletResponse httpServletResponse = (HttpServletResponse) response;

    httpServletResponse.setHeader("Cache-Control", "no-cache, no-store, 
    must-revalidate"); // HTTP 1.1.
    httpServletResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    httpServletResponse.setDateHeader("Expires", 0); // Proxies.

in the doFilter() method.

Then just apply your filter-class to the pages you want to filter in your web.xml

Upvotes: 1

JokerTheFourth
JokerTheFourth

Reputation: 425

I Solve this problem with remoteCommand component, to update selectOneMenu after page is refreshed. Don't forget to set selected variable to null in @PostConstruct method.

The problem occurs only on Firefox browser.

code:

<p:remoteCommand name="rcName"
                 update="@form"
                 autoRun="true"
                 ignoreAutoUpdate="true" />code

Upvotes: 3

domincb
domincb

Reputation: 1

Are you tried to put process="@this" in the ajax component?

Upvotes: 0

500 Server error
500 Server error

Reputation: 644

Check if your bean is @RequestScoped. If so change it to @ViewScoped.

Upvotes: 0

Related Questions