我在编辑后在数据台上更新列有问题。我使用对话框编辑您想要的数据。您将所有内容保存在数据库中,问题重新齐德更新表,正在使用新值更新字段,只有一个不更新的,只有对话框中的SelectoneMenu。未更新的字段来自Lotação,其余的都在工作。
我的桌子..
<h:head>
</h:head>
<h:body>
<ui:composition template="/WEB-INF/template/template.xhtml">
<ui:define name="TituloCorpo">Alterar Impressora</ui:define>
<ui:define name="Corpo">
<div align="center">
<h:form id="form">
<!-- BOTÕES QUE GERA RELATÓRIOS EM PDF E CSV -->
<div style="width:2958px">
<h:commandLink>
<h:graphicImage value="/resources/img/icon_pdf.png" width="35" title="Relatório em PDF"/>
<p:dataExporter type="pdf" target="tab" fileName="impressoras" pageOnly="true"/>
</h:commandLink>
<h:commandLink>
<h:graphicImage value="/resources/img/icon_csv.png" width="35" title="Relatório em CSV"/>
<p:dataExporter type="csv" target="tab" fileName="impressoras" pageOnly="true" />
</h:commandLink>
</div>
<!-- SCRIPT QUE CRIA UMA TABELA -->
<p:dataTable id="tab" var="impressora" widgetVar="tab" value="#{impressoraMB.impressoras}" editable="true" reflow="true" style="width:1100px">
<p:column id="fabricante" headerText="Fabricante" filterBy="#{impressora.fabricante}" filterMatchMode="contains" style="width:170px">
<h:outputLabel value="#{impressora.fabricante}"/>
</p:column>
<p:column id="modelo" headerText="Modelo" filterBy="#{impressora.modelo}" filterMatchMode="contains" style="width:170px">
<h:outputLabel value="#{impressora.modelo}"/>
</p:column>
<p:column id="modeloCartucho" headerText="Modelo do Cartucho" filterBy="#{impressora.modeloCartucho}" filterMatchMode="contains" style="width:180px">
<h:outputLabel value="#{impressora.modeloCartucho}"/>
</p:column>
<p:column id="patrimonio" headerText="Patrimonio" filterBy="#{impressora.patrimonio}" filterMatchMode="contains" style="width:120px">
<h:outputLabel value="#{impressora.patrimonio}"/>
</p:column>
<p:column id="lotacao" headerText="Lotação" filterBy="#{impressora.nome}" filterMatchMode="contains" style="width:110px">
<h:outputLabel value="#{impressora.nome}"/>
</p:column>
<p:column headerText="Alterar" style="width:70px" exportable="false">
<p:commandButton update=":formAlterar:panelAlterar" icon="ui-icon-pencil" title="Alterar" style="height:35px;width:35px"
oncomplete="PF('alterarImpre').show()" ajax="true">
<f:setPropertyActionListener value="#{impressora}" target="#{impressoraMB.impressora}"/>
</p:commandButton>
</p:column>
<p:column headerText="Remover" style="width:90px" exportable="false">
<p:commandButton update=":formExcluir:panelExcluir" oncomplete="PF('excluirImpre').show()" icon="ui-icon-trash"
styleClass="btn btn-small" style="height:35px;width:35px" title="Excluir">
<f:setPropertyActionListener value="#{impressora}" target="#{impressoraMB.impressora}"/>
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
</div>
<!-- PAGINA COM A CAIXA DE DIALOGO -->
<ui:include src="/panel.xhtml"/>
</ui:define>
</ui:composition>
</h:body>
我的对话..
<p:dialog id="editar" header="Altere os dados desejados" widgetVar="alterarImpre" width="600" location="center"
draggable="true" modal="true" responcive="true" showEffect="fade" hideEffect="fade">
<h:form id="formAlterar">
<h6 align="center"><i>*Para abrir o campo de edição, clique em cima do valor</i></h6>
<br/>
<h:panelGrid id="panelAlterar" columns="2" cellpadding="5" width="75%">
<h:outputLabel for="fabricante" value="Fabricante:"/>
<p:inplace id="fabricante" editor="true" emptyLabel="Me edite">
<p:inputText value="#{impressoraMB.impressora.fabricante}" required="true" label="text"/>
</p:inplace>
<h:outputLabel for="modelo" value="Modelo:"/>
<p:inplace id="modelo" editor="true" emptyLabel="Me edite">
<p:inputText value="#{impressoraMB.impressora.modelo}" required="true" label="text"/>
</p:inplace>
<h:outputLabel for="modeloCartucho" value="Modelo do Cartucho: "/>
<p:inplace id="modeloCartucho" editor="true" emptyLabel="Me edite">
<h:inputText value="#{impressoraMB.impressora.modeloCartucho}" required="true" label="text"/>
</p:inplace>
<h:outputLabel for="patrimonio" value="Patrimonio"/>
<p:inplace id="patrimonio" editor="true" emptyLabel="Me edite">
<p:inputText value="#{impressoraMB.impressora.patrimonio}" required="true" label="text"/>
</p:inplace>
<h:outputLabel for="lotacoes" value="Lotações:"/>
<h:panelGroup>
<h:selectOneMenu id="lotacoes" value="#{impressoraMB.impressora.id_Lotacoes}" effect="fold" required="true"
immediate="true" style="width:100%">
<f:selectItems value="#{lotacoesMB.listLotacoes}" var="item"
itemLabel="#{item.nome}" itemValue="#{item.id}"/>
<f:ajax execute="@this"/>
</h:selectOneMenu>
</h:panelGroup>
</h:panelGrid>
<br/>
<div align="center">
<h:panelGrid>
<h:panelGroup>
<p:commandButton id="btnAlterar" value="Alterar" action="#{impressoraMB.alterar}" onclick="PF('alterarImpre').hide()"
oncomplete="PF('form').hide(); #{impressoraMB.impressora}" ajax="true" process="@form" title="Alterar">
<f:ajax execute="@all" render=":form:tab"/>
</p:commandButton>
<p:commandButton id="btnCancelar" value="Cancelar" onclick="PF('alterarImpre').hide()" title="Cancelar"/>
</h:panelGroup>
</h:panelGrid>
</div>
</h:form>
</p:dialog>
我的豆..
public class ImpressoraMB {
private Impressora impressora;
private ImpressoraDAO dao;
private List<Impressora> impressoras;
public ImpressoraMB() {
impressora = new Impressora();
impressoras = new ArrayList<Impressora>();
dao = new ImpressoraDAO();
}
public List<Impressora> getImpressoras() {
if (impressoras.size() == 0) {
impressoras = dao.getImpressoras();
}
return impressoras;
}
public void adicionar() {
dao.adicionar(impressora);
impressora = new Impressora();
}
public void remover() {
dao.remover(impressora);
impressoras.remove(impressora);
impressora = new Impressora();
}
public void alterar() {
dao.alterar(impressora);
impressora = new Impressora();
}
public void showMsgAdicionar() {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Impressora adicionada", "com sucesso!");
RequestContext.getCurrentInstance().showMessageInDialog(message);
}
public Impressora getImpressora() {
return impressora;
}
public void setImpressora(Impressora impressora) {
this.impressora = impressora;
}
}
非常感谢您。
在您的对话框中您有
<h:selectOneMenu id="lotacoes" value="#{impressoraMB.impressora.id_Lotacoes}" effect="fold"
required="true" immediate="true" style="width:100%">
当您的数据使用
时<p:column id="lotacao" headerText="Lotação" filterBy="#{impressora.nome}"
filterMatchMode="contains" style="width:110px">
<h:outputLabel value="#{impressora.nome}"/>
</p:column>
如果在两个不同的.xhtml文件之一中更改值,则应该具有预期的结果
您必须在命令按钮或ajax调用中使用更新属性。
<p:commandButton id="btnAlterar" value="Alterar" action="#{impressoraMB.alterar}" update=":form:tab" onclick="PF('alterarImpre').hide()"
oncomplete="PF('form').hide(); #{impressoraMB.impressora}" ajax="true" process="@form" title="Alterar">
或
<f:ajax execute="@all" update=":form:tab" render=":form:tab"/>
确保对象已在后座的bean中更新