I am Using Prime faces 3.5.8,I am getting duplicate rows with row edit event.I am getting my row count as fine but one record is showing twice instead of other.This I am getting when call my clintList to load.When I close dialog and open it it is fine,Even I checked my list It is getting right data,Thanks in Advance..
My BeanCode for edit,
public void onClientEdit(RowEditEvent event) {
try {
Client edtClient = (Client) event.getObject();
if (null == edtClient.getClientName()
|| edtClient.getClientName() == "") {
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_ERROR,
CommonStringUtil.getUIString("clintNameEmpty"),
CommonStringUtil.getUIString("clintNameEmpty")));
getAgencyClients();
return;
}
HibernateUtil.beginTransaction();
Agency tempAgency = agencyHome.findById(agency.getAgencyId());
Hibernate.initialize(tempAgency.getClients());
HibernateUtil.commitTransaction();
for (Client cl : (Set<Client>) tempAgency.getClients()) {
if (cl.getClientName().equalsIgnoreCase(
edtClient.getClientName().trim())) {
log.debug("Client Name Already exists");
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_WARN,
CommonStringUtil
.getUIString("clientNameExists"),
CommonStringUtil
.getUIString("clientNameExists")));
getAgencyClients();
return;
}
}
HibernateUtil.beginTransaction();
Client eClient = clientHome.findById(edtClient.getClientId());
eClient.setClientName(edtClient.getClientName());
clientHome.attachDirty(eClient);
clientName = null;
agencyHome.attachDirty(agency);
HibernateUtil.commitTransaction();
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_INFO, CommonStringUtil
.getUIString("clientNameEditSucc"), CommonStringUtil
.getUIString("clientNameEditSucc")));
} catch (Exception e) {
if (HibernateUtil.isTransactionActive())
HibernateUtil.rollbackTransaction();
log.error("Error Updating Client Name", e);
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_ERROR, CommonStringUtil
.getUIString("clientNameEditFail"), CommonStringUtil
.getUIString("clientNameEditFail")));
}
}
My View Part
<p:dialog widgetVar="clientDialogue" modal="true" id="clientdilogId"
showHeader="false" style="padding:0;">
<h:form id="clientDlgForm">
<p:toolbar style="height:38px;">
<p:toolbarGroup align="left">
<h:outputText
value="Edit Client Messages: #{adminAgencyBean.agencyName}"
styleClass="dialog-header-Text" style="line-height:38px"></h:outputText>
</p:toolbarGroup>
<p:toolbarGroup align="right" style="margin-left:50px;">
<p:inputText value="#{adminAgencyBean.clientName}" id="clientName"
maxlength="45" />
<p:spacer width="5"></p:spacer>
<p:commandButton action="#{adminAgencyBean.createClient}"
icon="ui-icon-custom-arrow" iconPos="right" value="Create"
style="margin-left:5px;margin-right:20px;" update="#form" />
<p:commandLink value="X" onclick="clientDialogue.hide()"
style="text-decoration:none;margin-right:10px;" process="#none"></p:commandLink>
</p:toolbarGroup>
</p:toolbar>
<p:messages id="clientMsgs" />
<p:scrollPanel style="width:980px;height:400px;width:100%;"
mode="native">
<p:dataTable value="#{adminAgencyBean.clientList}" var="client"
sortBy="#{client.clientName}" sortOrder="ascending" editable="true"
id="ClientTable">
<p:ajax event="rowEdit" listener="#{adminAgencyBean.onClientEdit}"
update=":clientDlgForm:clientMsgs"/>
<p:ajax event="rowEditCancel" />
<p:column headerText="Client Name" sortBy="#{client.clientName}"
style="white-space:pre-line;width:130px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.clientName}" />
</f:facet>
<f:facet name="input">
<p:inputText id="editClientName" value="#{client.clientName}"
maxlength="45" style="width:90px"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit Client"
style="white-space:pre-line;width:80px;">
<p:rowEditor
rendered="#{adminAgencyBean.clientTransactionMap[client.clientId] lt 1}" />
<h:outputText value="#{commonmessages.NoEdit}"
rendered="#{adminAgencyBean.clientTransactionMap[client.clientId] ge 1}" />
</p:column>
<p:column headerText="Remove Client"
style="width:85px;white-space:pre-line">
<p:commandButton value="Remove"
rendered="#{adminAgencyBean.clientTransactionMap[client.clientId] lt 1}"
action="#{adminAgencyBean.deleteClient}" update="#form"
process="#none" styleClass="blue_button">
<f:setPropertyActionListener target="#{adminAgencyBean.clientId}"
value="#{client.clientId}"></f:setPropertyActionListener>
</p:commandButton>
<h:outputText value="#{commonmessages.nodelete}"
rendered="#{adminAgencyBean.clientTransactionMap[client.clientId] ge 1}" />
</p:column>
</p:dataTable>
</p:scrollPanel>
</h:form>
</p:dialog>
Related
I am displaying list of some objects in primefaces datatable. Apart from object related columns, I have added two columns that contain commandbutton. Each of these commandbutton make ajax calls to desired methods in bean. I want to disable both commandbuttons in that row when any of the button is clicked and enable them again once action is completed successfully. The method execution is simulated by ajaxStatus which is working fine.
Following is selected code of xhtml
<h:form id="form1" >
<p:remoteCommand name="onload" action="#{controlBean.init}" autoRun="true" />
<h:outputtext>Sample Project</h:outputtext>
<p:ajaxStatus style="display:block;margin-bottom:2em;height:24px;">
<f:facet name="prestart">
<h:outputText value="Starting..." /> </f:facet>
<f:facet name="error"> <h:outputText value="Error" />
</f:facet>
<f:facet name="success"> <h:outputText value="Success" />
</f:facet>
<f:facet name="default"> <h:outputText value="Idle" />
</f:facet>
<f:facet name="start"> <h:outputText value="Please Wait" />
<p:graphicImage name="/images/ajaxloadingbar.gif" />
</f:facet>
</p:ajaxStatus>
<p:dataTable var="appl" id="tbl1" rowIndexVar="rowIndx" value="#{controlBean.applsList}">
<p:column headerText="Name">
<h:outputText value="#{appl.applName}" />
</p:column>
<p:column headerText="Type">
<h:outputText value="#{appl.applType}" />
</p:column>
<p:column headerText="Desc" rendered="true">
<h:outputText value="#{appl.applDesc}" />
</p:column>
<p:column headerText="Start Appl" id="col4">
<p:commandButton value="Submit" ajax="true"
process="#this"
widgetVar="startButtonVar"
id="startBtn" update="msgs, col4, startBtn"
action="#{controlBean.startAction}" style="margin-right:20px;"
styleClass="ui-priority-primary"
disabled="#{controlBean.startBtnDisabled}">
<f:setPropertyActionListener value="#{appl}" target="#{controlBean.selectedAppl}"/>
</p:commandButton>
</p:column>
<p:column headerText="Stop Appl" id="col5">
<p:commandButton value="Submit" ajax="true"
process="#this"
widgetVar="stopButtonVar"
id="stopBtn" update="msgs, col5"
action="#{controlBean.stopAction}" style="margin-right:20px;"
styleClass="ui-priority-primary"
disabled="#{controlBean.btnDisabled}">
<f:setPropertyActionListener value="#{appl}" target="#{controlBean.selectedAppl}"/>
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
backing bean methods are as under:
public void startAction()
{
System.out.println("In start action method");
this.btnDisabled = true;
for(int i=0;i<100000;i++)
{
if(i%10000 == 0)
{
System.out.println(i);
}
for(int j=0;j<10000;j++)
{
for(int k=0;k<1000;k++)
{
}
}
}
MessageUtils.info(getSelectedAppl().getApplName()+" has been started");
this.btnDisabled = false;
}
public void stopAction()
{
System.out.println("In stop action method");
this.btnDisabled = true;
for(int i=0;i<100000;i++)
{
if(i%10000 == 0)
{
System.out.println(i);
}
for(int j=0;j<10000;j++)
{
for(int k=0;k<1000;k++)
{
}
}
}
MessageUtils.info(getSelectedAppl().getApplName()+" has been stopped");
this.btnDisabled = false;
}
Everything is working fine except disabling/enabling of commandbuttons. Any help in this regard will be highly appreciated.
Regards
You could disable them on the onclick javascript handler:
<p:commandButton id="startBtn"
widgetVar="startButtonVar"
onclick="PF('startButtonVar').disable();"
.....
The onclick will be executed BEFORE the AJAX call. On return, as the button is updated, it will be reenabled.
I have a little project, reading/searching data from database include pictures. I have added primefaces-5.3.jar to my project , And my problem is that, When I change users photo to another it does not shows me that change Immediately, whereas I can see other changes(updates) in users record And only when I refresh the web page I am able to see another picture. Please help me with this
here is my piece of code:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
//....
<h:form id="searchform">
<!--1 Form for searching -->
<br/>
<br/>
<h:form id="searchform">
<p:outputLabel value="type the key"/>
<p:inputText value="#{personBean.searchinperson.searchAllUsingLikeOpSTRING}" required="true" requiredMessage="Please Enter the key"/>
<br/>
<p:commandButton value="Search by key" icon="ui-icon-search" action="#{personBean.displaySearchedPeopleList()}" update="searchform"/>
<p:dataTable id="searchdatatable_id" value="#{personBean.listofSeachedPeople}" var="person">
<p:column headerText="PersonId">
<p:outputLabel value="#{person.personid}"/>
</p:column>
<p:column headerText="FirstName">
<p:outputLabel value="#{person.firstname}"/>
</p:column>
<p:column headerText="LastName">
<p:outputLabel value="#{person.lastname}"/>
</p:column>
<p:column headerText="Age">
<p:outputLabel value="#{person.age}"/>
</p:column>
<p:column headerText="UserName">
<p:outputLabel value="#{person.username}"/>
</p:column>
<p:column headerText="Password" >
<p:outputLabel value="#{person.password}"/>
</p:column>
<p:column headerText="DataAddTime" >
<p:outputLabel value="#{person.dataaddtime}"/>
</p:column>
<p:column headerText="Person Photo">
<p:graphicImage value="#{personBeanApp.imageDisplay}" alt="no image" height="150" width="150">
<f:param value="#{person.personid}" name="image_id"/>
</p:graphicImage>
</p:column>
<p:column headerText="Modification">
<p:commandLink value="Modify" actionListener="#{personBean.readPersonID(person)}" oncomplete="PF('wdlgData').show();" update=":dlgDataform" />
</p:column>
<p:column headerText="Delete" style=" color: red;">
<p:commandLink value="Delete Person" actionListener="#{personBean.readPersonID(person)}" oncomplete="PF('wdlgconfirmation').show();" update=":dlgconfdelform" />
</p:column>
</p:dataTable>
</h:form>
<!-- Dialog for Modification column -->
<h:form id="dlgDataform">
<p:dialog header="Data" widgetVar="wdlgData" >
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="modifyDlgPersonid_id" value="PersonID"/>
<p:inputText id="modifyDlgPersonid_id" value="#{personBean.person.personid}" required="true" />
<p:outputLabel for="modifyDlgFirstname_id" value="FirstName"/>
<p:inputText id="modifyDlgFirstname_id" value="#{personBean.person.firstname}" required="true" />
<p:outputLabel for="modifyDlgLastname_id" value="LastName"/>
<p:inputText id="modifyDlgLastname_id" value="#{personBean.person.lastname}" required="true"/>
<p:outputLabel for="modifyDlgAge_id" value="Age"/>
<p:inputText id="modifyDlgAge_id" value="#{personBean.person.age}" required="true"/>
<p:outputLabel for="modifyDlgUsername_id" value="UserName"/>
<p:inputText id="modifyDlgUsername_id" value="#{personBean.person.username}" required="true"/>
<p:outputLabel for="modifyDlgPassword_id" value="Password"/>
<p:inputText id="modifyDlgPassword_id" value="#{personBean.person.password}" required="true"/>
</h:panelGrid>
<p:outputLabel value="add/alter Picture"/>
<p:fileUpload fileUploadListener="#{personBean.handleFileUploadForAdminModifyDlg}" mode="advanced" dragDropSupport="false"
update="adminModifyDlgUpload_msgs" sizeLimit="1000000" fileLimit="1" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
<p:messages id="adminModifyDlgUpload_msgs" for="adminModifyDlgPicUpload" showDetail="true" autoUpdate="true" closable="true" />
<br/>
<br/>
<p:separator />
<p:messages for="dialogModAdmin" showDetail="true" autoUpdate="true" closable="true" />
<br/>
<p:commandButton value="Modify" actionListener="#{personBean.modificatePersonData()}" update=":searchform:searchdatatable_id" />
<h:outputText value=" " />
<p:commandButton value="Cancel/Close" immediate="true" oncomplete="PF('wdlgData').hide();"/>
</p:dialog>
</h:form>
PersonBean.java:
#ManagedBean
#SessionScoped
public class PersonBean {
private List<Person> listofSeachedPeople;
public List<Person> getListofSeachedPeople() {
return listofSeachedPeople;
}
public void setListofSeachedPeople(List<Person> listofSeachedPeople) {
this.listofSeachedPeople = listofSeachedPeople;
}
public void displaySearchedPeopleList() throws Exception
{
PersonDAO dao;
try{
dao=new PersonDAO();
listofSeachedPeople=dao.searchByAll(searchinperson);
}
catch(Exception ex){throw ex;}
}
public void readPersonID(Person per) throws Exception{
PersonDAO dao;
Person temp;
try{
dao=new PersonDAO();
temp=dao.readID(per);
if(temp!=null){ persId=temp.getPersonid();persPass=temp.getPassword();this.person=temp; }
}
catch(Exception ex){throw ex;}
}
public void modificatePersonData() throws Exception{
PersonDAO dao;
try{
dao=new PersonDAO();
if("personIdFree".equals(dao.IsPersonIdFreeExceptThis(person)) && "passwordFree".equals(dao.IsPasswordFreeExceptThis(person))){dao.modificate(person);FacesContext.getCurrentInstance().addMessage("dialogModAdmin", new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", "The Data has been modified"));}
else {FacesContext.getCurrentInstance().addMessage("dialogModAdmin", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "PersonID or Password is already in use"));}
this.displaySearchedPeopleList();
}
catch(Exception ex){throw ex;}
}
public void handleFileUploadForAdminModifyDlg(FileUploadEvent event) throws Exception {
try{
if(event.getFile()!=null){
uplf.setUploadedFile(event.getFile());
person.setPersonimage(IOUtils.toByteArray(uplf.getUploadedFile().getInputstream()));
FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage("adminModifyDlgPicUpload", message);}
}
catch(Exception ex){throw ex;}
}
PersonDAO.java :
public void modificate(Person per) throws Exception {
PreparedStatement pst;
Date date = new Date();
DateFormat df = new SimpleDateFormat("dd/MM/YYYY - hh:mm:ss");
try {
this.connectDB();
pst = this.getConn().prepareStatement("UPDATE person SET personid=?,firstname=?, lastname=?, age=?, username=?, password=?,dataaddtime=?,personimage=? WHERE personid=? ");
pst.setInt(1, per.getPersonid());
pst.setString(2, per.getFirstname());
pst.setString(3, per.getLastname());
pst.setInt(4, per.getAge());
pst.setString(5, per.getUsername());
pst.setString(6, per.getPassword());
pst.setString(7, df.format(date));
pst.setBytes(8,per.getPersonimage());
pst.setInt(9,PersonBean.getPersId());
pst.executeUpdate();
} catch (Exception ex) {
throw ex;
} finally {
this.toClose();
}
}
public byte[] chosenPictureInBytes(int id) throws Exception{
PreparedStatement pst;
ResultSet rs;
byte[] byteArr =new byte[1048576];
try{
this.connectDB();
pst = this.getConn().prepareStatement("SELECT personimage FROM person WHERE personid=? ");
pst.setInt(1,id);
rs = pst.executeQuery();
while(rs.next()){
// byteArr=rs.getBytes("personimage");
Blob blobPic = rs.getBlob("personimage");
byteArr=blobPic.getBytes(1,(int) blobPic.length());
}
}
catch(Exception ex){throw ex;}
finally{this.toClose();}
return byteArr;
}
PersonBeanApp.java:
#ManagedBean
#ApplicationScoped
public class PersonBeanApp {
public StreamedContent getImageDisplay() throws Exception{
PersonDAO dao;
try{
dao=new PersonDAO();
FacesContext fc=FacesContext.getCurrentInstance();
String id=fc.getExternalContext().getRequestParameterMap().get("image_id");
if(fc.getCurrentPhaseId()==PhaseId.RENDER_RESPONSE){ return new DefaultStreamedContent(); }
byte[] imageInByteArray=dao.chosenPictureInBytes(Integer.parseInt(id));
return new DefaultStreamedContent(new ByteArrayInputStream(imageInByteArray));
}
catch(Exception ex){throw ex;}
}
}
Please help me...
In my case, i had to have an img tag in modal dialog and i updated #form on user clicking the submit button on the dialog.
<p:dialog widgetVar="dlg7" id="showImage" closable="true" modal="true" header="Edit Email Image" closeOnEscape="true" draggable="true" dynamic="true" >
<p:ajax event="close" listener="#{emailConfigurationEditAction.handleCloseEditImage}" update=":emailConfiguration" />
<h:form id="editImage">
<div id="editImageDiv" align="center">
<p:messages globalOnly="false" autoUpdate="true" id="messages"
rendered="true" closable="true">
<p:effect id="idar760" type="bounce" event="load" delay="500" />
</p:messages>
<h:panelGrid columns="2" width="500px;" id="editImageGrid" columnClasses="emailTemplatePadding,row1-padding">
<p:outputLabel value="#{msg.EMAIL_INLINE_IMAGE_NAME}" for="imageNameText" id="imageNameLable" />
<h:outputText value="#{emailConfigurationEditAction.editEmbeddedImage.cidname}" converter="upperCaseConverter" id="imageNameText" style="width:300px;" maxlength="20" validatorMessage="#{msg.EMAIL_INLINE_IMAGES_CIDNAME_VLDMSG}"/>
<p:outputLabel value="#{msg.EMAIL_INLINE_IMAGE_MIMETYPE}" for="imageMimeType" id="imagemimeLabel"/>
<p:selectOneMenu id="imageMimeType" value="#{emailConfigurationEditAction.editEmbeddedImage.mimeType}" style="width:310px">
<f:selectItem itemLabel="#{msg.DROP_SELECTONE }" itemValue="#{null}" />
<f:selectItems value="#{emailConfigurationEditAction.mimeTypeOptions}"/>
</p:selectOneMenu>
<p:outputLabel value="Uploaded Image:" id="imageUploadedLabel"/>
<img width="100" height="100" border="0" id="imageUploaded" src="data:image/jpg;base64,#{imageUtility.getImageAsString(emailConfigurationEditAction.editEmbeddedImage.imageByteArray)}" />
<!-- p:graphicImage value="#{emailImages.image}" id="imageUploaded" height="100px" width="100px" >
<f:param name="cidName" value="#{emailConfigurationEditAction.editEmbeddedImage.cidname}"/>
</p:graphicImage-->
<p:outputLabel value="#{msg.EMAIL_INLINE_IMAGE_UPLOAD}" for="imageUploader" id="imageUploaderLabel"/>
<p:fileUpload id="imageUploader" mode="advanced" dragDropSupport="true" fileLimit="1" update=":editImage" style="width:310px" label="#{msg.EMAIL_INLINE_UPLAOD_IMAGE}"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/" fileUploadListener="#{emailConfigurationEditAction.imageEditListener}" fileLimitMessage="#{msg.EMAIL_INLINE_IMAGES_FILELIMIT_VLDMSG}"/>
</h:panelGrid>
<p:commandButton value="#{msg.BTN_SUBMIT}" id="submitNewImage" action="#{emailConfigurationEditAction.updateEmbeddedImage}" process=":editImage" ajax="true" update="#form"/>
<p:commandButton value="#{msg.BTN_CANCEL}" id="cancelEditImage" action="#{emailConfigurationEditAction.cancel}" immediate="true" ajax="true" process="#this"/>
</div>
</h:form>
</p:dialog>
And my datatable looked as follows:
<p:dataTable var="image" value="#{emailConfigurationEditAction.searchedImages}" id="dataTableImages" rendered="#{emailConfigurationEditAction.searchedImages!=null}"
paginator="true" rows="10" paginatorPosition="top"
rowStyleClass="#{index%2==0?'row1Data':'row2Data'}" style="width:600px;"
styleClass="ui-citi-datatable-paginator"
rowClasses="row1Data,row2Data"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
currentPageReportTemplate="{currentPage} #{msg.LBL_OF} {totalPages}"
emptyMessage="#{msg.INFO_SEARCH_RESULT_EMPTY}" >
<p:column id="col1" headerText="#{msg.EMAIL_INLINE_IMAGES_COLHDR_NAME}" styleClass="centered" style="width:175px;">
#{image.cidname}
</p:column>
<p:column id="col2" headerText="#{msg.EMAIL_INLINE_IMAGES_COLHDR_MIMETYPE}" styleClass="centered" style="width:120px;">
#{image.mimeType}
</p:column>
<p:column id="col3" headerText="#{msg.EMAIL_INLINE_IMAGES_COLHDR_IMAGE}" styleClass="centered" style="width:120px;">
<img width="100" height="100" border="0" id="graphicImage3"
src="data:image/jpg;base64,#{imageUtility.getImageAsString(image.imageByteArray)}" />
<!--p:graphicImage value="#{emailImages.image}" id="graphicImage3" height="100px" width="100px;">
<f:param name="cidName" value="#{image.cidname}"/>
</p:graphicImage-->
</p:column>
<p:column id="col4" headerText="" styleClass="centered" style="width:60px;">
<!-- h:commandButton image="/global/images/Delete_But_small.png" title="#{msg.LBL_EVENTEMAILMAPPING_DELETE_BUTTON}" immediate="true" value="#{msg.BTN_DELETE}" id="imgDelete"/>
<pe:tooltip for="imgDelete" value="#{msg.LBL_EVENTEMAILMAPPING_DELETE_BUTTON}" myPosition="left" atPosition="right"
showEffect="slideToggle" hideEffect="slideToggle" id="tooltip_delimg"/-->
<h:commandButton image="/global/images/Edit_But_small.png" title="#{msg.LBL_EVENTEMAILMAPPING_EDIT_BUTTON}" value="#{msg.BTN_EDIT}" id="imgEdit" action="#{emailConfigurationEditAction.editImage(image)}">
<p:ajax update=":editImage" oncomplete="PF('dlg7').show()" process="dataTableImages"/>
</h:commandButton>
<pe:tooltip for="imgEdit" value="#{msg.LBL_EVENTEMAILMAPPING_EDIT_BUTTON}" myPosition="left" atPosition="right"
showEffect="slideToggle" hideEffect="slideToggle" id="tooltip_edim"/>
</p:column>
</p:dataTable>
When i used grpahicImage instead, i understood that it will not work due to the way it is designed
I am calling a rowEdit event and I want to refresh the table only when the event performs the db update successfully. Below are my code.
XHTML
<p:dataTable id="xobjTable" var="xobj" value="#{xListView.xListResponseObject}"
scrollRows="20" scrollable="true" liveScroll="true" scrollHeight="600"
rowKey="#{xobj.X}"
selection="#{xListView.selectedObject}" selectionMode="single"
style="margin-top: 20px; margin-bottom:20px" editable="true">
<f:facet name="header">
Search Results
<p:spacer width="20"/>
<h:commandLink id="csv">
<p:graphicImage value="csv.png" width="24"/>
<p:dataExporter type="csv" target="xobj" fileName="xListSearch" />
<p:tooltip id="toolTipFade" for="csv" value="Click on CSV to download entire table as a csv file. " />
</h:commandLink>
</f:facet>
<p:ajax event="rowEdit" listener="#{xListView.onRowEdit}" update=":xListform:xobjTable" />
<p:column headerText="X" style="width:60px;text-align: center">
<h:outputText value="#{xobj.X}" />
</p:column>
<p:column headerText="Y" style="width:60px;text-align: center">
<h:outputText value="#{xobj.Y}" />
</p:column>
<p:column headerText="Modified Date" style="width:160px;text-align: center">
<h:outputText value="#{xobj.modifiedDate}" />
</p:column>
<p:column headerText="Active" style="width:160px;text-align: center">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{xobj.active}"/>
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{xobj.active}">
<f:selectItems value="#{xListView.activeList}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Location" style="width:160px;text-align: center">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{xobj.location}"/>
</f:facet>
<f:facet name="input">
<p:inputText id="location" value="#{xobj.location}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="State" style="width:160px;text-align: center">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{xobj.state}"/>
</f:facet>
<f:facet name="input">
<p:inputText id="state" value="#{xobj.state}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="x Country Code" style="width:160px;text-align: center">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{xobj.xCountryCode}"/>
</f:facet>
<f:facet name="input">
<p:inputText id="xCountryCode" value="#{xobj.xCountryCode}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="xrarier" style="width:160px;text-align: center">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{xobj.carrier}"/>
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{xobj.carrier}">
<f:selectItems value="#{xListView.xarrierList}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px" headerText="Edit" rendered="#{allTabs.isShow(xListView.title)}">
<p:rowEditor />
</p:column>
<p:column style="width:160px;text-align: center" rendered="#{allTabs.isShow(xListView.title)}" headerText="Delete">
<p:commandButton id="deleteDid" actionListener="#{xListView.deletexy(xobj)}"
icon="ui-icon ui-icon-trash red" title="Delete" update="#form">
<p:confirm header="Confirmation" message="#{xListView.finalDeleteMessage}" icon="ui-icon-alert" />
</p:commandButton>
</p:column>
</p:dataTable>
Here is the event method
public void onRowEdit(RowEditEvent event) {
xListResponseObject editObject = (xListResponseObject) event.getObject();
logger.debug("Coming to edit the row.");
String editXYStatus = xListDAO.editxy(editObject);
if (editxyStatus.equals(SUCCESS_RESPONSE)) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO", "X/Y edit successful!");
FacesContext.getCurrentInstance().addMessage(null, msg);
} else {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "INFO", "X/Y edit failed :" + editxyStatus);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
I would like the update to happen only when the rowEdit event updates the db.
Can I have a boolean set in my method and access data in the update in the p:ajax ?
Add to end of your SUCCESS_RESPONSE
RequestContext.getCurrentInstance().update("form:npaobjTable");
Or whatever your table real id is.
I was having the same problem.
Below URL will solve your problem.
http://forum.primefaces.org/viewtopic.php?f=3&t=38412&p=153402#p153402
actual response :
public void onRowEdit(RowEditEvent event) {
NpaListResponseObject editObject = (NpaListResponseObject) event.getObject();
logger.debug("Coming to edit the row.");
String editNpaNxxStatus = npaListDAO.editNpaNxx(editObject);
if (editNpaNxxStatus.equals(SUCCESS_RESPONSE)) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO", "NPA/NXX edit successful!");
FacesContext.getCurrentInstance().addMessage(null, msg);
} else {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "INFO", "NPA/NXX edit failed :" + editNpaNxxStatus);
FacesContext.getCurrentInstance().addMessage(null, msg);
FacesContext.getCurrentInstance().validationFailed();
}
}
added FacesContext.getCurrentInstance().validationFailed(); at last in failure scenario.
Hi I have a datatable which publishes the information very well, however, for this particular case something happens, in one column have a Boolean value that can only be true once the entire table of the database, so if I detect someone puts another record as true then update the above false and so the cycle ends. The update is done right in the database but when I want to refresh the datatable to also show the modification of another record, and does not work ...
this is my 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>
this is my backing 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 *************/
}
Please help!!! took a while stuck with it :(
I´ve a datatable that has a column with selectoneradio, so I´m supposed to turn on the radios if they are on in my database. So I recover my data but I can´t figured how to tell my selectoneradio buttons to be on when my users consult the page with the table. Here is the code from my table:
<p:dataTable id="secciones" var="secciones" value="#{seccionesMB.seccionesList}" style="width: 60%;">
<p:column>
<f:facet name="header">
<h:outputText value="" />
</f:facet>
<h:outputText value="#{secciones.codigo}" />
<f:facet name="header" >
<h:outputText value="Seccion" />
</f:facet>
<h:outputText value="#{secciones.seccion}" />
</p:column>
<p:column>
<f:facet name="header">
<div align="left"> <h:outputText value="Alta Baja Consulta Mod N/A" /></div>
</f:facet>
<p:selectOneRadio id="options" value="#{secciones.nivel}" disabled="true">
<f:selectItem itemLabel="10000" itemValue="10000" />
<f:selectItem itemLabel="01000" itemValue="01000" />
<f:selectItem itemLabel="00100" itemValue="00100" />
<f:selectItem itemLabel="00010" itemValue="00010" />
<f:selectItem itemLabel="00001" itemValue="00001" />
</p:selectOneRadio>
</p:column>
</p:dataTable>
and here is the method from my backing bean that feeds my datatable:
public String consultarPerfil(int id, String perfil) {
this.setId(id);
this.setPerfil(perfil);
try {
List<Perfiles_Secciones> list = getPerfiles_SeccionesService().getPerfiles_Seccion(id);
int i = 0;
for(SeccionesDTO seccionDTO : seccionesList) {
for(Perfiles_Secciones ps : list) {
if (seccionDTO.getId() == ps.getId_seccion()) {
System.out.println(seccionDTO.getId() + " - " + ps.getId_seccion());
seccionDTO.setNivel(ps.getNivel());
}
i++;
}
i = 0;
}
for(SeccionesDTO seccionDTO : seccionesList) {
System.out.println(seccionDTO.getNivel());
}
} catch (Exception ex) {
Logger.getLogger(PerfilesManagedBean.class.getName()).log(Level.SEVERE, null, ex);
}
return CONSULTAR_PERFIL;
}
What do I need to do in order to feed my selectoneradio from my managed bean??