为什么的内容没有刷新afterb Ajax Action
问题描述:
我试图在更新AJAX(触发数据库中的更新请求) 在我的程序中用户单击commandLink或更新后更新dataTable的内容数据库中的“odm.valide_manag1”字段(使用The Datatable执行的请求通过不幸地测试此字段将图像(项目符号)从红色更改为绿色,此阶段未正确执行,测试始终保持未选中状态(不更新领域的吸气剂) 我调用在@PostConstruct的listodm对象的再生,在吸气剂,在验证方法中,我改变了范围没有成功为什么<h:dataTable>的内容没有刷新afterb Ajax Action
@ManagedBean
@ViewScoped // or RequestScoped
public class listeOdm {
public static Logger log= LogManager.getLogger(listeOdm.class.getName());
private List<odm> listOdm= new ArrayList<odm>() ; // a changer vers ListDataModel
private odmService odmservice = new odmServiceImpl();
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession httpsession = (HttpSession) fc.getExternalContext().getSession(false);
private String n_odm;
private String operation;
private HtmlDataTable dataTable;
@PostConstruct
public void initMyBean()
{ listOdm=null;
log.info("1- debut PostConstruct : " );
listOdm = odmservice.findByMatricule("1000"); /*(String) httpsession.getAttribute("Matricule")*/
//listOdm = odmservice.findAll();
log.info("1- PostConstruct NOMBRE DES ODM : " + listOdm.size()+ " The Object Is "+ listOdm.hashCode());
RequestContext.getCurrentInstance().update("basicDT");
/* if("edit".equals(getParam("operation")))
{
editOdm();
}*/
}
public String getParam(String name)
{
Map<String, String> params=fc.getExternalContext().getRequestParameterMap();
return params.get(name);
}
public void onValid_manag(RowEditEvent event)
{
odmservice.validManager(((odm) event.getObject()).getNum_odm());
FacesMessage msg = new FacesMessage("Odm validée", ((odm) event.getObject()).getNum_odm());
FacesContext.getCurrentInstance().addMessage(null, msg);
// ((odm) event.getObject()).setValide_manag1("2");
// listOdm.clear();
// listOdm = odmservice.findAll();
listOdm = odmservice.findByMatricule("1000");
log.info("2- on valid Method la nouvelle valeur de Valide_manage1 est :" + ((odm) event.getObject()).getValide_manag1());
log.info("2- on valid Method : " + listOdm.size()+ " The Object Is "+ listOdm.hashCode());
RequestContext.getCurrentInstance().update("basicDT");
}
public void onCancel_manag(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Odm Non validée", ((odm) event.getObject()).getNum_odm());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void editOdm()
{ // setN_odm(getParam("numOdm"));
// setOperation(getParam("operation"));
log.info("0- edit methode : "+getParam("numOdm"));
odmservice.validManager(getParam("numOdm"));
//listOdm = odmservice.findByMatricule("1000"); /*(String) httpsession.getAttribute("Matricule")*/
log.info("edit de l'ODM N°: ");
listOdm = odmservice.findByMatricule("1000");
}
public void modif()
{ log.info("on Expand Start ");
listOdm = odmservice.findByMatricule("1000");
}
public void printOdm()
{}
public List<odm> getListOdm() {
log.info("getter list odm"+this.listOdm.hashCode());
if (FacesContext.getCurrentInstance().getRenderResponse()) {
log.info("getter list odm"+this.listOdm.hashCode());
listOdm = odmservice.findByMatricule("1000");
}
return listOdm ;//= odmservice.findByMatricule("1000");
}
public void setListOdm(List<odm> listOdm) {
this.listOdm=listOdm ;
}
public String getN_odm() {
return n_odm;
}
public void setN_odm(String n_odm) {
this.n_odm = n_odm;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
public HtmlDataTable getDataTable() {
dataTable.clearInitialState();
return dataTable;
}
public void setDataTable(HtmlDataTable dataTable) {
this.dataTable = dataTable;
}
}
的XHTML
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"></link>
<title>Insert title here</title>
</h:head>
<h:body>
<ui:debug />
<h:form id="formulaire1">
<h:inputHidden value="#{listeOdm.n_odm}" />
<h:inputHidden value="#{listeOdm.operation}" />
<p:growl id="msgs" showDetail="true"/>
<h:dataTable id="basicDT" var="odm" value="#{listeOdm.listOdm}" binding="#{listeOdm.dataTable}" >
<h:column headerText="Etat" id= "bulet">
<h:panelGroup rendered="#{odm.valide_manag1 eq '2'}">
<h:graphicImage library="img" name="if_bullet-green_44189.png" width="24" height="24" style="border-style: none"/>
</h:panelGroup>
<h:panelGroup rendered="#{odm.valide_manag1+odm.valide_manag2 eq '1'}">
<h:graphicImage library="img" name="orange.gif" width="24" height="24" style="border-style: none"/>
</h:panelGroup>
<h:panelGroup rendered="#{odm.valide_manag1+odm.valide_manag2 eq '0'}">
<h:graphicImage library="img" name="if_bullet-red_44191.png" width="24" height="24" style="border-style: none"/>
</h:panelGroup>
</h:column>
<h:column headerText="valid">
<h:outputText value="#{odm.valide_manag1}" />
</h:column>
<h:column headerText="Num Odm">
<h:outputText value="#{odm.num_odm}" />
</h:column>
<h:column headerText="Client">
<h:outputText value="#{odm.client}" />
</h:column>
<h:column headerText="Station">
<h:outputText value="#{odm.station}" />
</h:column>
<h:column headerText="Destination">
<h:outputText value="#{odm.destination}" />
</h:column>
<h:column headerText="date dep">
<h:outputText value="#{odm.date_dep}" pattern="dd/MM/yyyy"/>
</h:column>
<h:column headerText="date retour">
<h:outputText value="#{odm.date_ret}" pattern="dd/MM/yyyy"/>
</h:column>
<h:column headerText="Cient">
<h:outputText value="#{odm.client}" />
</h:column>
<h:column headerText="Edit" width="24">
<h:commandLink
actionListener="#{listeOdm.editOdm}" update=":formulair1:basicDT" ajax="true">
<f:param name="numOdm" value="#{odm.num_odm}"></f:param>
<f:param name="operation" value="edit"></f:param>
<h:graphicImage library="img" name="118805-128.png" width="24" height="24" style="border-style: none"/>
<!-- <i class="fa fa-envelope"></i> -->
</h:commandLink>
<h:commandLink
actionListener="#{listeOdm.printOdm}" update="formulaire1">
<f:param name="numOdm" value="#{odm.num_odm}"></f:param>
<f:param name="operation" value="edit2"></f:param>
<h:graphicImage library="img" name="Print-2-128.png" width="24" height="24" style="border-style: none"/>
<!-- <i class="fa fa-envelope"></i> -->
</h:commandLink>
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>
JSF2.2.9的Tomcat 8.5
答
我已经解决了我的问题!!!!! 我想与初学者分享这种体验,因为对于专家来说显而易见。 DataTable的行是对象,执行列表程序或命令<p:ajax event="rowEdit" listener="#{listeOdm.onValid_manag}" update=":formulaire1:basicDT"/>
更新数据库中的记录而不更新数据表行。
public void onValid_manag(RowEditEvent event)
{
odmservice.validManager(((odm) event.getObject())); // herer was my error, before i passed a string instead of the object event.getObject().getNum_Odm
listOdm = odmservice.findByMatricule("1000");
}
,并在梅索德调用Hibernate的更新我在DB更新记录这样
正确的方法是:
public void validManager(odm odm) { //object in the selected row as parameter
session.beginTransaction();
// updating the object in memory
odm.setValide_manag1("2");
//hibernate execute the update query in DB
session.save(odm);
session.getTransaction().commit();
}
+0
嗨,有没有任何全球性的解决方案,数据库中的对象和记录同时更新? –
你能做出正确的句子?这太难以阅读了。 –
对不起,我说法语 –
我试图在AJAX调用后更新dataTable的内容 –