0
votes

I'm using STS (Spring tool suite) with spring boot, primefaces and hibernate.

I have an page with a p:datatable. In the last column, have a p:commandbutton for edit data of the table (p:dialog). When I open the dialog, all data load correct. If I close de dialog without save and open other line of the table data load correct again, but, if I save the data and open a new dialog of other line of the table, the field p:selectOneMenu is loaded with wrong data. Your value is the same value of the last dialog saved. All dialog data has correct, less the combobox (p:selectOneMenu). In debug, the value returned in backing bean is correct.

Some things I've tried:

  • Changed p:commandbutton to p:commandlink;
  • In button "save" of dialog, "update" field with the p:panel of table, the h:form, h:datable;
  • Change onComplete to onClick;
  • Use h:selectOneMenu instead of p:selectOneMenu;
  • Downgrade primefaces (currently 6.1) and myfaces (currently 2.2.12).

All no sucess.

ps: Datatable is filtered and paginated.

xhtml:

<p:panel id="pnlData" header="My Table">
    <h:form id="frmTable">
        <p:dataTable var="item" value="#{RSDMBean.myData}"
                id="tblTicketsID" widgetVar="tabelaTickets" some things of pagination and filters here...>

                <p:column />
                <p:column /> ...

            <p:column headerText="Edit">
                    <p:commandButton value="Edit"
                        actionListener="#{RSDMBean.editTicketLoad(item.idTicket)}" 
                        update=":formPnl:pnlTkct" oncomplete="PF('dlgtkt').show();">
                   </p:commandButton>
           </p:column>
     </p:datatable>
  </h:form
</p:panel>

<p:dialog id="dlgtktID" header="Edit ticket" widgetVar="dlgtkt"
        modal="true">
        <h:form id="formPnl">
<h:panelGrid id="pnlTkct" columns="2" cellpadding="10"
                cellspacing="1" style="absolute">

                <h:outputText style="font-weight:bold" value="Id Ticket: " />
                <h:outputText value="#{RSDMBean.ticketEdited.id}" />

       Others fields here...

<h:outputText style="font-weight:bold" value="County: " />
                <p:selectOneMenu style="min-width: 162px;" required="true">
                    <f:selectItem itemLabel="#{RSDMBean.ticketEdited.county.name}"
                        itemValue="#{RSDMBean.ticketEdited.county.id}" />
                    <f:selectItems
                        value="#{RSDMBean.countyItensedit.entrySet()}" var="entry"
                        itemValue="#{entry.key}" itemLabel="#{entry.value}" />
                </p:selectOneMenu>

                <p:commandButton value="Save" action="#{RSDMBean.saveEdit}"
                    update=":frmTable:tblTicketsID" oncomplete="PF('dlgtkt').hide();" />
end tags here...

Bean:

import javax.annotation.PostConstruct;
import javax.faces.bean.RequestScoped;
import org.springframework.beans.factory.annotation.Autowired;
.
.
.

@Controller("RSDMBean")
@RequestScoped
public class MyMBean implements Serializable {
@Autowired
private ResiduoService residuoService;
@Autowired
private ResiduoRepository residuoRepository;
@Autowired
private CountyRepository countyRepository;

private Residuo ticketEdited;

private List<County> county;

private Map<Long, String> countyItensEdit = new HashMap<Long, String>();


public void editTicketLoad(String param) {
    long idTicket = Long.parseLong(param);
    ticketEdited = residuoRepository.findOne(idTicket);
    county = countyRepository.findAll();
}

@PostConstruct
public void construct() {
//some loads database here...
    county = countyRepository.findAll();

    if (countyItensEdit.isEmpty()) {
        for (Municipio c : countyItensEdit) {

            countyItensEdit.put(c.getId(), c.getNome());
        }
    }
}
1
You use wrong values in the update attributes. Run you app in development mode and also read stackoverflow.com/questions/8634156/…Kukeltje
The "update" attributes has been updated such as your link, and the question too. But not worked.vctlzac

1 Answers

0
votes

In p:selectOneMenu was missing value tag:

<p:selectOneMenu style="min-width: 162px;" required="true"
                    value="#{RSDMBean.ticketEdited.county.id}">