1

folks. I'm stuck on the following problem. I have a modal dialog with two selectOneMenu components in it. When I close the dialog and open it again the values in selectoneMenu's are still selected. This is my menus:

 <p:selectOneMenu id="fromCurrency"
value="#{dialog.exchangeRateManageContainer.currencyIdFrom}"                                                   
    styleClass="ui-input-required"                                      
    required="true"
requiredMessage="#{msgs['validation.maintenance.exchangeRate.fromCurrency']}">                                         
    <f:selectItem
    itemLabel="#{msgs['label.maintenance.selectCurrency']}"/>                                       
    <f:selectItems value="#{dialog.currencies}" var="currency"
    itemLabel="#{currency.code}"
    itemValue="#{currency.currencyId}"/>
    </p:selectOneMenu>

<p:outputLabel for="toCurrency" value="#{msgs['label.maintenance.toCurrency']}" />
<p:selectOneMenu id="toCurrency"
    value="#{dialog.exchangeRateManageContainer.currencyIdTo}"
    styleClass="ui-input-required"
        required="true"
    requiredMessage="#{msgs['validation.maintenance.exchangeRate.toCurrency']}">
<f:selectItem itemLabel="#{msgs['label.maintenance.selectCurrency']}"/>
<f:selectItems value="#{dialog.currencies}" var="currency"
    itemLabel="#{currency.code}"
    itemValue="#{currency.currencyId}"/>

This is the cancel button:

    <p:commandButton id="cancelButton"
    value="#{msgs['label.button.cancel']}"
    icon="ui-icon-cancel"
    action="#{dialog.cancel()}"
    immediate="true"
    process="@this"
    oncomplete="addExchangeRateDialog.hide();"/>

And this is the cancel method:

   public void cancel() {
    manageCurrenciesDialog = null;
   }

Any help will be appreciated.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
vladislavn
  • 388
  • 1
  • 8
  • 20
  • 1
    Did you read this link : http://stackoverflow.com/questions/20169208/how-to-reset-input-components-on-change-of-pselectonemenu-after-certain-valid ? – JGeo Apr 01 '14 at 14:04
  • Also, this link may help http://stackoverflow.com/questions/16251156/how-to-reset-dropdown-on-primefaces-commandbutton-reset-type – Stathis Andronikos Apr 01 '14 at 14:12
  • 1
    There may be many reasons for this behaviour. Maybe you don't clear the values in the bean or you do not refresh/update the dialog before opening it or maybe you close the dialog after validation failed and the dialog state is not cleared. The code you've posted is not enough to tell. – Aneta Stępień Apr 01 '14 at 19:41

3 Answers3

1

The solution for me was to add update atribut on the command buton which opens the dialog with the dialog id. And it works.

vladislavn
  • 388
  • 1
  • 8
  • 20
0

In order to reset selections, you need to set the values of your components to null.

Change your cancel method to:

public void cancel() {
    manageCurrenciesDialog = null;
    exchangeRateManageContainer.currencyIdFrom = null;
    exchangeRateManageContainer.currencyIdTo = null;
}
Yamada
  • 723
  • 6
  • 23
-1

Reset values of all components

I reseted values of all components by calling action to my backing bean method. Inside of this method I assigned all values of components such as p:selectOneMenu and p:selectBooleanCheckbox to null. It works perfectly.

Skyware
  • 352
  • 1
  • 7
  • 16