【发布时间】:2018-06-07 12:30:17
【问题描述】:
我正在使用 STS(Spring 工具套件)和 spring boot、primefaces 和 hibernate。
我有一个带有 p:datatable 的页面。在最后一列中,有一个用于编辑表格数据的 p:command 按钮(p:dialog)。 当我打开对话框时,所有数据加载正确。如果我在不保存的情况下关闭对话框并再次打开表格的其他行数据加载正确,但是,如果我保存数据并打开表格其他行的新对话框,则字段 p:selectOneMenu 加载了错误的数据。您的值与保存的最后一个对话框的值相同。所有对话框数据都正确,少了组合框 (p:selectOneMenu)。在调试中,backing bean 中返回的值是正确的。
我尝试过的一些事情:
- 将 p:commandbutton 更改为 p:commandlink;
- 在对话框的“保存”按钮中,使用表格的 p:panel、h:form、h:datable 的“更新”字段;
- 将 onComplete 更改为 onClick;
- 使用 h:selectOneMenu 代替 p:selectOneMenu;
- 降级 primefaces(当前为 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...
豆子:
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());
}
}
}
【问题讨论】:
-
您在更新属性中使用了错误的值。在开发模式下运行你的应用程序并阅读stackoverflow.com/questions/8634156/…
-
“更新”属性已更新,例如您的链接和问题。但没用。
标签: jsf primefaces jsf-2