2

I have a page containing a PrimeFaces (2.2.1) Editor component, a Refresh button and a selectOneMenu, whose selection affects the contents of the Editor, as follows:

<p:editor id="uploadedText" value="#{facilityDataUploadBean.uploadedText}"
          width="600" height="180" disabled="true" controls="" />
<h:commandButton value="Refresh" immediate="true" />
<h:selectOneMenu id="skipLines" styleClass="dropdown"
                 value="#{facilityDataUploadBean.skipLines}">
    <f:selectItems value="#{facilityDataUploadBean.skipLinesList}" />
    <f:ajax listener="#{facilityDataUploadBean.importParameterChanged}" />
</h:selectOneMenu>

facilityDataUploadBean.importParameterChanged updates facilityDataUploadBean.uploadedText. After changing the selectOneMenu value, the operator presses the Refresh button to refresh the page, including the contents of the p:editor. (I cannot simply refresh the p:editor using AJAX, because it doesn't re-render correctly, at least in PF 2.2.1.)

It seems like I ought to be able to accomplish the page refresh automatically when the selectOneMenu value is changed, but I've been unable to come up with a combination of attributes and events that will do that. I've tried various combinations of onchange="submit();", immediate="true" and valueChangeListener on the selectOneMenu, as well as execute="@all/@form", render="@all/@form" on the f:ajax event, all to no avail. My current workaround is to display a message asking the user to press the Refresh button whenever they change the selectOneMenu selection - pretty hokey.

Kevin Rahe
  • 1,609
  • 3
  • 19
  • 27

2 Answers2

5

Invoke window.location.replace(window.location.href) rather than submit() in the onchange event, as in:

<h:selectOneMenu id="skipLines" ... onchange="window.location.replace(window.location.href);">
    <f:selectItems ... />
    <f:ajax ... />
</h:selectOneMenu>
Kevin Rahe
  • 1,609
  • 3
  • 19
  • 27
  • 1
    Once in a while a change to the selectOneMenu doesn't "take" - perhaps the page refresh occurs before the AJAX that sets the value in the backing bean executes. But I haven't seen it leave the UI in an inconsistent state or showing a different value than is currently held by the backing bean (which is SessionScoped). – Kevin Rahe Jun 22 '12 at 20:49
  • Note that this solution also avoids certificate selection (which could be wanted or unwanted). – Andrew Dec 21 '18 at 16:36
2

please try the onchange="window.location.reload();" approach like:

<h:selectOneMenu id="skipLines" ... onchange="window.location.reload();">
    <f:selectItems ... />
    <f:ajax ... />
</h:selectOneMenu>

This works just fine in my environment (GF 3.1.1, PF 3.2) but please be aware that there is the possibility of interrupting some ajax functinality.

Hope this helpes, have Fun!

SimonSez
  • 7,399
  • 1
  • 30
  • 35
  • 1
    When I do that, I get the same dialog that [this question](http://stackoverflow.com/questions/4869721/reload-browser-window-after-post-without-prompting-user-to-resend-post-data) complains about. The solution, however, is to use `window.location.replace(window.location.href)` rather than `window.location.reload()`, which the answer to [this question](http://stackoverflow.com/questions/296685/page-auto-reload-with-parameters) tipped me off to. – Kevin Rahe Jun 22 '12 at 03:58
  • Great to hear you found a solution which worked out for you! Cheers! – SimonSez Jun 22 '12 at 07:27