0

I'm trying to add dynamically an item in a SelectOneMenu('Raison') within an editable dataTable using primeFaces.

My code for XHTML :

<p:column>
    <!-- ... -->

    <!-- inside p:cellEditor -->

    <p:selectOneMenu id="selectmenu" value="#{o.rais.raison}"effect="fold"  filter="true" filterMatchMode="startsWith" style="width:100%">
        <f:selectItems value="#{vueRecupSurveil.raisonsBlocakge}"  />
                                                   
        <f:selectItem ItemValue="#{vueRecupSurveil.newRaisonBlocakge}" itemLabel="Ajouter une raison"/>

        <p:ajax listener="#{vueRecupSurveil.ajoutNewRaison}"/>
    </p:selectOneMenu>

    <!-- ... -->
</p:column>

My code for bean:

@ManagedBean(name="vueRecupSurveil")
@ViewScoped
public class VueRecupSurveil implements Serializable {

    private String newRaisonBlocakge="";

    private List<String> raisonsBlocakge = new ArrayList<String>();

    @PostConstruct
    public void init() {
        // initialize list   
    }


    public void ajoutNewRaison(AjaxBehaviorEvent event) {
        if (newRaisonBlocakge.equals(((UIInput) event.getComponent()).getValue())) {               
            RequestContext ajax = RequestContext.getCurrentInstance();

            ajax.update("addNewRaisonDialog");
            ajax.execute("PF('widget_addNewRaisonDialog').show()");
        }
    }
}

My problem is when i click in the icon edit, in options in datatable, and change the raison, then click back in cancel icon, i can't get the initial value displayed; when i remove the ajax code for my xhtml it works.

The dialog should display the new data via ajax.

fuggerjaki61
  • 822
  • 1
  • 11
  • 24
  • just add `update="selectId"` to the ajax that calls the method that adds the item. – fuggerjaki61 Jun 25 '20 at 12:50
  • @fuggerjaki61 when i click on cancel in roweditor it stills gives me in the selectonemenu the value i changed to it not the value displayed first.. – Salma Iabdounane Jun 25 '20 at 13:47
  • are you removing the current selection in the bean? see [this](https://stackoverflow.com/questions/6248933/call-a-custom-listener-for-cancel-in-proweditor) – fuggerjaki61 Jun 25 '20 at 13:55
  • No i’ m not removing it, i thought cancel in roweditor did that. Please how can i remove the current selection? – Salma Iabdounane Jun 25 '20 at 14:13
  • See [how to add `no selection` property](https://stackoverflow.com/questions/11360030/best-way-to-add-a-nothing-selected-option-to-a-selectonemenu-in-jsf) and then just set the value to null. – fuggerjaki61 Jun 25 '20 at 14:30
  • I think i didn’t understand ur idea. I change the the item value in select item to #{null} but i’m still having the problem. – Salma Iabdounane Jun 25 '20 at 15:06
  • You could save your original list and replace the other one with it, on edit cancel – WoAiNii Jun 26 '20 at 10:51

0 Answers0