1
votes

I have a problem concerning the reset of a f:selectOneMenu with a p:ajax element inside a p:dataTable with row edit mode. When I cancel the row editing, all changes in every field (also other f:selectOneMenu elements without a p:ajax) are correctly reset except for a f:selectOneMenu which contains a p:ajax element.

If I remove the concerning p:ajax element the f:selectOneMenu is as well reset correctly.

Any advice where my problem may arise from?

Here is the concerning xhtml snippet:

<h:form id="tradingPartnersForm">   
  <p:dataTable id="tradingPartnerRow" styleClass="partnersTable" var="partnerText"
      value="#{tradingPartners.tradingPartnerList}" editable="true" >

    <p:ajax event="cellEdit" listener="#{tradingPartners.onRowEdit}" update=":messages" />
    <p:ajax event="rowEditCancel" listener="#{tradingPartners.onRowCancel}" update=":messages" />

    ... // other fields 

    <p:column headerText="#{someLabel}">
      <p:cellEditor>
        <f:facet name="output">
          <h:outputText value="#{partnerText.rolle}" />
        </f:facet>
        <f:facet name="input">
          <p:selectOneMenu value="#{partnerText.rolle}">
            <f:selectItems value="#{tradingPartners.partnerKindsMap.entrySet()}" var="partnerKindsEntry" itemValue="#{partnerKindsEntry.key}" itemLabel="#{partnerKindsEntry.value}" />
              <p:ajax event="change" execute="@this" update="l1group l2group" />
          </p:selectOneMenu>
        </f:facet>
      </p:cellEditor>
    </p:column>

    ... // other fields 

    <p:column style="width:32px">
      <p:rowEditor />
    </p:column>
  </p:dataTable>
</h:form>
1
1. Your question says f:selectOneMenu, but your code says p:selectOneMenu. 2. It seems similar to problem I have encountered before, may be it's a primefaces bug. Checkout the answers to this question. stackoverflow.com/questions/10780093/…Lokesh
Hi @Lokesh, thank you for the correction of the title. I'll also have a look at the other answer.hans

1 Answers

0
votes

Okay, it seams that primefaces row edit cancel event works correct. The problem is homemade, and arises from the ajax call:

<p:ajax event="change" execute="@this" update="l1group l2group" />

Here the attribute of the bean which is used inside the select is chanced via the ajax call right after a new value is selected. So technically if the select is reset after the edit is canceled it shows the newly selected value.

It seems that this behavior can be changed by inserting a hidden filed storing the beans initial attribute value:

<p:column headerText="#{vtdb['acquirepartners.column5']}">
  <h:inputHidden value="#{partnerText.rolle}" id="partnerTextRoleBackup" />
  <p:cellEditor>
    <f:facet name="output"><h:outputText value="#{partnerText.rolle}" /></f:facet>
    <f:facet name="input">
      <p:selectOneMenu value="#{partnerText.rolle}">
        <f:selectItems value="#{tradingPartners.partnerKindsMap.entrySet()}" var="partnerKindsEntry" itemValue="#{partnerKindsEntry.key}" itemLabel="#{partnerKindsEntry.value}" />
        <p:ajax event="change" execute="@this" update="l1group l2group" />
      </p:selectOneMenu>
    </f:facet>
  </p:cellEditor>
</p:column>

But at the moment I have no obvious explanation for this behavior!