首页 文章

p:selectOneMenu在p:面板中保存后无负载正确

提问于
浏览
0

我正在使用STS(Spring工具套件)与spring boot,primefaces和hibernate .

我有一个页面,其中包含p:datatable . 在最后一列中,有一个p:commandbutton用于编辑表的数据(p:dialog) . 当我打开对话框时,所有数据加载正确 . 如果我在没有保存的情况下关闭de dialog并打开其他行的表数据再次加载正确,但是,如果我保存数据并打开表的其他行的新对话框,则字段p:selectOneMenu加载了错误的数据 . 您的值与上次保存的对话框的值相同 . 所有对话框数据都正确,少了组合框(p:selectOneMenu) . 在debug中,backing bean中返回的值是正确的 .

我试过的一些事情:

  • 将p:commandbutton更改为p:commandlink;

  • 在对话框的按钮"save"中,"update"字段与表格的p:面板,h:form,h:datable;

  • 将onComplete更改为onClick;

  • 使用h:selectOneMenu而不是p:selectOneMenu;

  • 降级素数(目前为6.1)和myfaces(目前为2.2.12) .

一切都没有成功 .

ps:数据表被过滤和分页 .

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...

beans :

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 回答

  • 0

    在p:selectOneMenu缺少值标记:

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

相关问题