primefaces数据表不刷新新数据

时间:2014-11-13 00:48:44

标签: jsf primefaces

您好我有一个数据表可以很好地发布信息,但是,对于这种特殊情况发生的事情,在一列中有一个布尔值,只能在数据库的整个表中为真,所以如果我发现有人放了另一条记录为true然后更新上面的false,所以循环结束。更新是在数据库中完成的,但是当我想刷新数据表以显示另一条记录的修改时,并且不起作用...

这是我的xhtml:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="template.xhtml">
<ui:define name="content">
<h:form id="someForm">
<p:growl id="msg" showDetail="true" life="3000" autoUpdate="true"/>
<p:panelGrid style="100%">
<p:row>
<p:column style="350px">title 1</p:column>
<p:column>
<p:inputText id="cveSituacion" value="#{someBean.cve}" maxlength="20" />    
</p:column>
</p:row>
<p:row>
<p:column style="350px">title 2</p:column>
<p:column>
<p:inputText id="name" value="#{someBean.name}" />
</p:column>
</p:row>
<p:row>
<p:column colspan="2">
<p:spacer></p:spacer>
</p:column>
</p:row>
<p:row>
<p:column>
<p:commandButton action="#{someBean.searchAll}" value="Search All" ajax="true" update="someForm" immediate="true"/>
</p:column>
</p:row>
<p:row>
<p:column colspan="4">
<p:spacer></p:spacer>
</p:column>
</p:row>
<p:row>
<p:column colspan="4"> 
<p:dataTable id="resultSearch" var="someVariable" value="#{someBean.listOfData}" editable="true"> 
<p:ajax event="rowEdit" listener="#{someBean.onEdit}" update=":someForm:msg :someForm:resultSearch" />
<p:ajax event="rowEditCancel" listener="#{someBean.onCancel}" update=":someForm:msg" />   
<p:column headerText="Clave Sit Ticket" sortBy="#{someVariable.cve}">
<h:outputText value="#{someVariable.cve}" />
</p:column>
<p:column headerText="Name" sortBy="#{someVariable.name}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{someVariable.name}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{someVariable.name}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Description" sortBy="#{someVariable.desc}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{someVariable.desc}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{someVariable.desc}" />
</f:facet>
</p:cellEditor>
</p:column>       
<p:column headerText="Sit" sortBy="#{someVariable.situation}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{someVariable.situation}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu id="cboBox" value="#{someVariable.situation}" style="width=200px">
<f:selectItems value="#{commonCboBean.listOfData}" var="cboBox" itemValue="#{cboBox.cve}" itemLabel="#{cboBox.desc}" /> 
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Default" sortBy="#{someVariable.BSitDefault}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{someVariable.BSitDefault}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu id="cboVoF" value="#{someVariable.BSitDefault}" style="width=200px">
<f:selectItems value="#{fovBean.fov}" var="fov" itemValue="#{fov.bandera}" itemLabel="#{fov.descripcion}" />    
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:50px;" >
<p:rowEditor />
</p:column>
</p:dataTable>
</p:column>
</p:row>
</p:panelGrid>  
</h:form>
</ui:define>
</ui:composition>

这是我的支持bean:

@SuppressWarnings("serial")
@ManagedBean
@ViewScoped
public class SomeBean implements Serializable{

private String cve;
private String name;

private List<SomeObject> listOfData;
private SomeObject newDefault;
private SomeObject sitDefault;
private RequestContext context = null;

... some methods ....

public void onEdit(RowEditEvent event) {

/*
IF I JUST UPDATE DATA LIKE THIS: updateData(SomeObject obj) THE DATATABLE 
IS UPDATED CORRECTLY, BUT IF A LEAVE THE NEXT CODE, IT DOESNT
*/

newDefault = (SomeObject)event.getObject();

if( newDefault.getFlag.equals(Constants.V) ){

List<SomeObject> list = ejb.find(newDefault.getCve);

if( list == null || list.size() <= 0 ){

updateData( newDefault );

}else{

if( list.get(0).getCve().equals( newDefault.getCve() )  ){      

updateData( newDefault );

}else{

SomeObject sitDefault = list.get(0);

if( ejb.update(sitDefault) > 0 ){

updateData(newDefault);

searchAll();

}else
FacesContext.getCurrentInstance().addMessage( null, 
new FacesMessage(FacesMessage.SEVERITY_ERROR, 
"sometitle", 
"some messsage")
);


}

}

}else{
    updateData( newDefault );
}

}

public void updateNewDefault(){

sitDefault.setBSitDefault("F");

if( ejb.update(sitDefault) > 0 ){

updateData(newDefault);

searchAll();

}else
    FacesContext.getCurrentInstance().addMessage( null, 
    new FacesMessage(FacesMessage.SEVERITY_ERROR, 
    "error", 
    "some error has ocurred")
    );

}

private void updateData(SomeObject obj){

int result = ejb.update( obj );

if( result > 0 ){

FacesContext.getCurrentInstance().addMessage( null, 
new FacesMessage(FacesMessage.SEVERITY_WARN, 
"OK", 
"OK"
)
);

searchAll();

}else{

FacesContext.getCurrentInstance().addMessage( null, 
new FacesMessage(FacesMessage.SEVERITY_ERROR, 
"ERROR", 
"SOME ERROR")
);

}       
}


public void searchAll(){
setListOfData( ejb.findAll() );
}


/******** getters & setters *************/

}

请帮忙!!!花了一段时间坚持下去:(

0 个答案:

没有答案