Command button onclick event is not working its not invoking Banking bean Method. There are some other commandButtons like
action="#{editBean.editQuestionAction}"
action="#{editBean.addNewQuestionAction}"
were working fine but its not in the case of `action="#{editBean.updateQuestionAction}"
<p:tab title="Questions">
<h:outputText value="Select a project to add questions: " />
<h:selectOneMenu id="projects_dpd" value="#{editBean.currentProject.projectId}" onchange="">
<f:selectItems value="#{projectBean.projects}" />
</h:selectOneMenu><br/>
<h:form id="listForm">
<p:panel id="listPanel" header="List of Questions" toggleable="false" closable="false">
<p:dataList paginatorAlwaysVisible="false" paginatorPosition="bottom" effect="slide"
value="#{editBean.editBeanList}" var="q"
paginator="true" rows="5" effectSpeed="fast"
paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:column>
<p:commandButton action="#{editBean.**editQuestionAction**}" update="editPanel" title="Edit Question" image="edit">
<f:setPropertyActionListener value="#{q}" target="#{editBean.editQuestion}" />
</p:commandButton>
<p:spacer width="30" height="30" />
<h:outputText value="#{q.question.questionId} -> #{q.question.questionText} ->"/> <b><h:outputText value="#{q.question.questionType}" /></b>
</p:column>
</p:dataList>
<p:commandButton value="New Question !!" action="#{editBean.**addNewQuestionAction**}" update="editPanel" />
<p:commandButton ajax="false" value="Home Page !!" action="#{indexBean.**gotoHomePage}**" />
</p:panel>
</h:form>
<p:layoutUnit position="center" scrollable="true">
<p:panel id="editPanel" header="Edit Section" toggleable="false" closable="false" >
<h:form id="form">
<table cellspacing="20">
<tr>
<td><h:outputLabel value="Question Text:" /></td>
<td><p:inputTextarea id="questionText" required="true" value="#{editBean.editQuestion.question.questionText}" autoResize="true" effectDuration="400" maxHeight="100" /></td> <td><p:message for="questionText" /></td>
</tr>
<tr>
<td>Review:</td>
<td><p:inputTextarea id="reviewText" required="true" value="#{editBean.editQuestion.question.reviewText}" autoResize="true" effectDuration="400" maxHeight="100" /></td>
<td><p:message for="reviewText" /></td>
</tr>
<tr>
<td>Option Type:</td>
<td>
<h:selectOneRadio label="Option Type" value="#{editBean.editQuestion.question.optionType}">
<f:selectItem itemLabel="Currency" itemValue="currency" />
<f:selectItem itemLabel="Hours" itemValue="hours" />
</h:selectOneRadio>
</td>
</tr>
<tr>
<td>Question Type:</td>
<td>
<h:selectOneRadio label="Question Type" value="#{editBean.editQuestion.question.questionType}">
<f:selectItem itemLabel="Mandatory" itemValue="mandatory" />
<f:selectItem itemLabel="Linked" itemValue="linked" />
</h:selectOneRadio>
</td>
</tr>
<tr>
<td align="right">
<h:selectBooleanCheckbox label="Hide Weight until Review !!" value="#{editBean.editQuestion.question.hideWeight}" />
</td>
<td>Hide Weight Until Review</td>
</tr>
<tr>
<td>Options:</td>
<td>
<p:panel header="Add Option">
<h:panelGrid columns="2" id="grid">
<h:outputLabel value="Text : " for="txt_title"></h:outputLabel>
<p:inputText id="txt_title"
value="#{editBean.placeHolderForOption.optionText}" />
<h:outputLabel value="Weight : " for="txt_author"></h:outputLabel>
<p:inputText id="txt_author"
value="#{editBean.placeHolderForOption.weight}" />
<p:commandButton value="Reset" type="reset"/>
<p:commandButton value="Add" update="options #parent"
action="#{editBean.initOption}" >
<p:collector value="#{editBean.placeHolderForOption}"
addTo="#{editBean.editQuestion.options}" />
</p:commandButton>
</h:panelGrid>
</p:panel>
<p:outputPanel id="options">
<p:dataTable value="#{editBean.editQuestion.options}" var="opt">
<p:column headerText="Text" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{opt.optionText}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{opt.optionText}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Weight" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{opt.weight}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{opt.weight}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Linked Question" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{opt.linkedQuestionId}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{opt.linkedQuestionId}">
<f:selectItems value="#{editBean.linkedQuestionIds}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Display Order" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{opt.displayOrder}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{opt.displayOrder}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Operation" />
</f:facet>
<p:commandLink value="Remove" update="form:options" process="#this">
<p:collector value="#{opt}"
removeFrom="#{editBean.editQuestion.options}" />
</p:commandLink>
<p:spacer width="10" />
<p:rowEditor />
</p:column>
</p:dataTable>
</p:outputPanel>
</td>
</tr>
</table>
<p:commandButton ajax="false" value="Update Question" action="#{editBean.updateQuestionAction}"
rendered="#{editBean.operation eq 'edit'}" />
<p:commandButton ajax="false" value="Add Question" update="msgs listForm:listPanel" action="#{editBean.saveQuestion}"
rendered="#{editBean.operation eq 'add'}">
<p:collector value="#{editBean.editQuestion}"
addTo="#{editBean.editBeanList}" />
</p:commandButton>
<p:commandButton ajax="false" value="Delete Question" update="msgs listForm:listPanel" action="#{editBean.deleteQuestionAction}"
rendered="#{editBean.operation eq 'edit'}">
<p:collector value="#{editBean.editQuestion}"
removeFrom="#{editBean.editBeanList}" />
</p:commandButton>
</h:form>
</p:panel>
</p:layoutUnit>
</p:tab>
Its not getting executing when i click on button
#ManagedBean
#RequestScoped
public class EditBean {
#ManagedProperty(value = "#{questionDao}")
private QuestionDao questionDao;
private String operation;
private QuestionHelper editQuestion;
private SelectItem[] linkedQuestionIds;
private List<QuestionHelper> linkedQuestions = new ArrayList<QuestionHelper>();
private List<QuestionHelper> allQuestions = new ArrayList<QuestionHelper>();
public void editQuestionAction() {
operation = "edit";
}
public void deleteQuestionAction() {
questionDao.delete(editQuestion.getQuestion());
listBean.getListOfQuestions().remove(editQuestion);
addNewQuestionAction();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Question: ", "Question Deleted !"));
}
public void updateQuestionAction() {
editQuestion.getQuestion().getOptionses().clear();
for (Options o : editQuestion.getOptions()) {
o.setQuestions(editQuestion.getQuestion());
editQuestion.getQuestion().getOptionses().add(o);
}
getQuestionDao().update(editQuestion.getQuestion());
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Question: ", "Question Updated !"));
}
Hi I found answer for my question, The command button is not working because of rendered tag and Request scope of managed bean , as on every subsequent request after pressing command button my request scoped (iseditable ) is getting resetting. When i made it Session scoped its working Fine.
Related
I´m trying to show the progress of several batch processes using a progressbar for each one of them. The problem is that only one progressbar is been sent to server side (the last one). Here is the code...
I made a RequestScoped Named bean for the progress beacause I read that for multiple progressBar it is needed a bean instance for each one of the progressbars, but that do not resolve my problem.
I'm using Primefaces 6.1 with JSF 2.2.
Any ideas? Thanks!
<h:form id="formExecutions">
<p:dataGrid id="jobs" value="#{jobExecutorController.jobExecutions}" var="job" rows="5" paginator="true" emptyMessage="#{MessageResources['text.noRecordsFound']}"
paginatorPosition="bottom" columns="1" layout="grid">
<f:facet name="header">
#{MessageResources['text.batchProcesses']}
</f:facet>
<p:outputPanel layout="block" >
<p:panelGrid cellpadding="5" styleClass="vf-panelGrid">
<p:row style="width:100%">
<p:column>
<p:outputLabel for="executionId" value="#{MessageResources['text.executionId']}:" style="font-weight:bold"/>
</p:column>
<p:column>
<h:outputText id="executionId" value="#{job.executionId}" />
</p:column>
<p:column>
<p:outputLabel for="name" value="#{MessageResources['text.name']}:" style="font-weight:bold"/>
</p:column>
<p:column style="width:10%">
<h:outputText id="name" value="#{job.name}"/>
</p:column>
<p:column style="width:50%" rowspan="2">
<p:progressBar id="progressBar" widgetVar="progressBar" ajax="true" value="#{progressController.progress(job)}" labelTemplate="{value}%" styleClass="animated" style="height: 20px; line-height: 20px;" global="false" interval="3000">
<p:ajax event="complete" listener="#{progressController.onCompleteJob(job)}" update="messageDisplay" process="#this"/>
<p:ajax update="jobInfo"/>
</p:progressBar>
</p:column>
<p:column style="width:4%" />
<p:column rowspan="2" style="text-align:right">
<p:commandButton id="restart" onclick="PF('confirmRestartJob').show()" styleClass="coloured-icons-batch restart-image-icon blink"
disabled="#{not job.enableRestartAbandon}" immediate="true" title="">
<f:setPropertyActionListener value="#{job.executionId}" target="#{jobExecutorController.executionIdSelected}" />
<f:setPropertyActionListener value="#{job.name}" target="#{jobExecutorController.executionNameSelected}" />
</p:commandButton>
<p:tooltip for="restart" value="#{MessageResources['text.restartJobExecution']}" position="top"></p:tooltip>
<p:spacer width="10" />
<p:commandButton id="stop" onclick="PF('confirmStopJob').show()" styleClass="coloured-icons-batch stop-image-icon blink"
disabled="#{not job.enableStop}" immediate="true" title="">
<f:setPropertyActionListener value="#{job.executionId}" target="#{jobExecutorController.executionIdSelected}" />
<f:setPropertyActionListener value="#{job.name}" target="#{jobExecutorController.executionNameSelected}" />
</p:commandButton>
<p:tooltip for="stop" value="#{MessageResources['text.stopJobExecution']}" position="top"></p:tooltip>
<p:spacer width="10" />
<p:commandButton id="abandon" onclick="PF('confirmAbandonJob').show()" styleClass="coloured-icons-batch abandon-image-icon blink"
disabled="#{not job.enableRestartAbandon}" immediate="true" title="">
<f:setPropertyActionListener value="#{job.executionId}" target="#{jobExecutorController.executionIdSelected}" />
<f:setPropertyActionListener value="#{job.name}" target="#{jobExecutorController.executionNameSelected}" />
</p:commandButton>
<p:tooltip for="abandon" value="#{MessageResources['text.abandonJobExecution']}" position="top"></p:tooltip>
</p:column>
</p:row>
</p:panelGrid>
<h:panelGroup id="jobInfo" >
<p:panelGrid columns="4" cellpadding="5" styleClass="vf-panelGrid">
<p:outputLabel for="creationDate" value="#{MessageResources['text.creationDate']}:" style="font-weight:bold"/>
<h:outputText id="creationDate" value="#{job.formattedDate(job.createdDate)}" />
<p:outputLabel for="startDate" value="#{MessageResources['text.dateStartProcess']}:" style="font-weight:bold"/>
<h:outputText id="startDate" value="#{job.formattedDate(job.startedDate)}" />
<p:outputLabel for="lastUpdate" value="#{MessageResources['text.lastUpdate']}:" style="font-weight:bold"/>
<h:outputText id="lastUpdate" value="#{job.formattedDate(job.lastUpdate)}" />
<p:outputLabel for="toProcess" value="#{MessageResources['text.itemsToProcess']}:" style="font-weight:bold"/>
<h:outputText id="toProcess" value="#{job.itemsToProcess}" />
<p:outputLabel for="endDate" value="#{MessageResources['text.ended']}:" style="font-weight:bold"/>
<h:outputText id="endDate" value="#{job.formattedDate(job.endedDate)}" />
<p:outputLabel for="processed" value="#{MessageResources['text.itemsProcessed']}:" style="font-weight:bold"/>
<h:outputText id="processed" value="#{job.itemsProcessed}" />
<p:outputLabel for="status" value="#{MessageResources['text.state']}:" style="font-weight:bold"/>
<h:outputText id="status" value="#{job.status}" />
</p:panelGrid>
</h:panelGroup>
</p:outputPanel>
<p:spacer width="5"/>
<p:separator />
<p:spacer width="5"/>
</p:dataGrid>
My RequestScope backing bean...
#Named("progressController")
#RequestScoped
public class ProgressController
{
#EJB
private EJBJobRepositoryLocal ejbJobRepository;
public Long progress(DMJob jobExecution) throws VfCmsSqlException
{
if (jobExecution.getStatus().equals(BatchStatus.STARTED.name())) {
jobExecution.setProgress(ejbJobRepository.getJobProgress(jobExecution.getExecutionId()));
}
PrimeUtil.get().update("formExecutions:jobInfo");
return jobExecution.getProgress();
}
public void onCompleteJob(DMJob jobExecution)
{
Object[] parameters = {jobExecution.getName(), jobExecution.getExecutionId()};
Messages.displayInfoMessage("text.jobComplete", parameters);
}
}
Ok. The problem is that the PrimeFaces().start() method is not been executed over all the components generated by JSF. So, what I did is a javascript function which is executed when the page is fully loaded. In my case the components that I needed to initialize are several progress bar. My components are inside a data scroller which is inside a form, that's why I concat those id's. The 'i' is the index of each of the rendered progress bar in the page.
<script type="text/javascript">
$(window).load(function() {
startProgress();
});
function startProgress(){
var pid = document.getElementsByClassName('ui-progressbar');
var pidLength = pid.length;
for (var i = 0; i < pidLength; i++) {
var id = "formExecutions:scroller:".concat(i).concat(":progressBar");
PrimeFaces.getWidgetById(id).start();
}
}
</script>
And that was all!
I´ve a couple issues with a page I´m working on.
I have two sections: frmConf and frmData.
The first one has some parameters I use for searching purposes.
The second one has a DataTable defined as lazy and algo I have it´s corresponding backing wich extends LazyDatamodel.
In the mentioned DataTable in section 2 I have a column with a commandLink which creates a PDF document for the selected row in the DataTable.
The problem I´m facing is it works just fine the first time I load the page:
It calls the load (#override) method from LazyDatamodel and presents the first 10 records of the query results from the DB.
Then, when I click on the commandLink column it shows the "save as" dialog for the corresponding PDF just fine and I can proceed to download the file.
But then, for some reason wich I don´t yet understand, if I click another row´s PDF commandLink it goes and calls the referred load method a requeries the DB assuming I´m trying to do some pagination and it doesn´t even generate the required PDF.
What I´m trying to achieve is just load the page for every pagination case and not for any unrelated event like clicking the PDF button for the selected row.
Why is it reloading and requerying (even though it shows the same results as the indexes for pagination haven´t change) the entire page content after the first (correct)PDF generation?
It´s my guess something happens after the first PDF generation (it leaves the page with some "reload required" state.
I´m leaving the markup from the page as well as the corresponding backing bean PDF generation method.
Please I´d really appreciate if someone could help me with this.
Thanks!
JSF markup:
<!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:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/templates/cimaTemplate.xhtml">
<ui:define name="tituloPagina">
<h:outputText value="Consulta Documentos" />
</ui:define>
<ui:define name="tituloFormulario">
<h:outputText value="Documentos" styleClass="titulo" />
</ui:define>
<ui:define name="contenido">
<style>
.style1 {
text-align: right;
}
.style3 {
text-align: left;
}
.style2 {
text-align: center;
background: blue;
color: white;
font-weight: bold;
}
.colEstadoStyle {
td:nth-child(1)
width: 20px;
}
.imageClass {
display: block;
background-image: url('/imagenes/pdf.png') no-repeat 100%;
}
</style>
<h:form id="frmConf" styleClass="form" >
<p:growl id="growl" showDetail="true" sticky="true" />
<p:panel id="datosEmisorPanel">
<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
<p:panelGrid style="margin: 0 auto;" id="panelG">
<p:row>
<p:column>
<p:panelGrid>
<p:row>
<p:column style="text-align: center;" colspan="2">
<strong><h:outputLabel styleClass="label" value="Seleccionar Archivo" /></strong>
<p:selectManyCheckbox style="text-align: center;"
value="#{cabDocumentoMB.selectedOptionsEmail}">
<f:selectItem itemValue="PDF" itemLabel="PDF" />
<f:selectItem itemValue="XML" itemLabel="XML" />
</p:selectManyCheckbox>
</p:column>
</p:row> <p:row>
<p:column colspan="2">
<strong><h:outputLabel styleClass="label"
value="E-Mails" /></strong>
<br></br>
<h:inputTextarea value="#{cabDocumentoMB.correos}"
cols="40" />
<br></br>
</p:column>
</p:row> <p:row>
<p:column colspan="2">
<strong><h:outputLabel styleClass="style1"
value="Formato: email1#email.com,email2#email.com" /></strong>
</p:column>
</p:row> <p:row>
<p:column rowspan="2">
<p:commandButton icon="ui-icon-mail-closed"
value=" Envio normal" id="bto_enviarEmail"
oncomplete="bloquearPagina.hide()"
onstart="bloquearPagina.show()"
action="#{cabDocumentoMB.EnviarCorreos('Normal')}"
update="growl">
</p:commandButton>
<p:blockUI block="frmConf" widgetVar="bloquearPagina">
Enviando correo...<br />
<p:graphicImage value="/imagenes/ajax-loader.gif" />
</p:blockUI>
<p:blockUI block="frmConf" widgetVar="bloquearReproceso">
Reprocesando...<br />
<p:graphicImage value="/imagenes/ajax-loader.gif" />
</p:blockUI>
</p:column>
<p:column rowspan="2">
<p:commandButton value=" Envio ZIP" icon="ui-icon-tag"
action="#{cabDocumentoMB.EnviarCorreos('ZIP')}"
oncomplete="bloquearPagina.hide()"
onstart="bloquearPagina.show()" update="growl">
</p:commandButton>
<br />
</p:column>
</p:row> </p:panelGrid>
</p:column>
<p:column colspan="0">
<p:panelGrid> <p:row>
<p:column colspan="1" styleClass="style1">
<strong><h:outputLabel styleClass="label" size="30"
value="Cédula/RUC/Pasaporte" /></strong>
</p:column>
<p:column colspan="1" styleClass="style3">
<h:inputText styleClass="text" style="font-weight: bold;"
value="#{cabDocumentoMB.ruc}" />
</p:column>
</p:row> <p:row>
<p:column colspan="1" styleClass="style1">
<strong><h:outputLabel styleClass="label" size="30"
value="Nombres:" /></strong>
</p:column>
<p:column colspan="1" styleClass="style3">
<h:inputText styleClass="text" style="font-weight: bold;"
value="#{cabDocumentoMB.razonSocial}" />
</p:column>
</p:row> <p:row>
<p:column styleClass="style1">
<strong><h:outputLabel styleClass="label"
value="Número del Documento:" /></strong>
</p:column>
<p:column styleClass="style3">
<h:inputText value="#{cabDocumentoMB.numDocumento}"
size="30" title="Número del Documento" placeHolder="TBD"/>
</p:column>
</p:row> <p:row>
<p:column styleClass="style1">
<strong><h:outputLabel styleClass="label"
value="Tipo de Documento:" /></strong>
</p:column>
<p:column styleClass="style3">
<p:selectOneMenu
value="#{cabDocumentoMB.seleccionTipo}">
<f:selectItems value="#{cabDocumentoMB.tipo}" />
</p:selectOneMenu>
</p:column>
</p:row> <p:row>
<p:column styleClass="style1">
<strong><h:outputLabel styleClass="label"
value="Estados:" /></strong>
</p:column>
<p:column styleClass="style3">
<p:selectOneMenu
value="#{cabDocumentoMB.seleccionTipoEstado}">
<f:selectItems value="#{cabDocumentoMB.tipoEstados}" />
</p:selectOneMenu>
</p:column>
</p:row> <p:row>
<p:column>
<strong><h:outputLabel styleClass="label"
value="Fecha Inicial:" /></strong>
<br></br>
<p:calendar id="txt_inicial"
value="#{cabDocumentoMB.fechaInicio}"
pattern="yyyy-MM-dd" mask="true" mode="popup" showOn="button"
readonlyInput="true">
<f:convertDateTime type="date" dateStyle="short"
pattern="yyyy-MM-dd" />
</p:calendar>
</p:column>
<p:column>
<strong><h:outputLabel styleClass="label"
value="Fecha Final:" /></strong>
<br></br>
<p:calendar id="txt_final"
value="#{cabDocumentoMB.fechaFinal}"
pattern="yyyy-MM-dd" mask="true" mode="popup" showOn="button"
readonlyInput="true">
<f:convertDateTime type="date" dateStyle="short"
pattern="yyyy-MM-dd" />
</p:calendar>
</p:column>
</p:row> <p:row>
<p:column style="text-align: center;">
<p:commandButton value=" Busqueda " icon="ui-icon-search"
title="Buscar Filtrado"
action="#{cabDocumentoMB.findDocumentos()}"
update=":frmData:listaDocumentos,:frmConf:datosEmisorPanel">
</p:commandButton>
</p:column>
<p:column>
<p:commandButton value="Reprocesar documentos "
icon="ui-icon-tag"
action="#{CabDocumentoMB.reprocesarDocumentos()}"
disabled="#{CabDocumentoMB.botonReprocesarActivo}"
update=":frmData:listaDocumentos,:frmConf:datosEmisorPanel">
</p:commandButton>
<br />
</p:column>
</p:row> </p:panelGrid>
</p:column>
</p:row>
</p:panelGrid>
</p:panel>
</h:form>
<h:form id="frmData" styleClass="form">
<p:panel id="datosDetalle22" >
<h:panelGroup id="listaDocumentos">
<p:dataTable id="lazyDataTable"
var="documento"
value="#{cabDocumentoMB.allDocumentos}"
paginator="true" rows="10" rowsPerPageTemplate="10,50,100"
selection="#{cabDocumentoMB.seleccionDocu}"
update=":frmData:listaDocumentos"
lazy="true">
<f:facet name="header">
Consulta de Documentos
</f:facet>
<p:column headerText="Identificación" style="width:10% ; font-size:11px" >
<h:outputText value="#{documento.identificacionComprador}" style="font-size:11px;" />
</p:column>
<p:column headerText="Razón Social" style="width:25% ; font-size:11px">
<h:outputText value="#{documento.razonSocialComprador}" style="font-size:11px;" />
</p:column>
<p:column headerText="Comprobante" style="width:10% ; font-size:11px">
<h:outputText value="#{documento.codigoDocumento}" style="font-size:11px;" />
</p:column>
<p:column headerText="Número" style="width:10% ; font-size:11px">
<h:outputText value="#{documento.id.serie}" style="font-size:11px;" />
</p:column>
<p:column headerText="Importe total" style="width:7% ; text-align:right ; font-size:11px">
<h:outputText value="#{documento.importeTotal}" style="font-size:11px;" />
</p:column>
<p:column headerText="Fecha Emisión" style="width:7% ; text-align:center ; font-size:11px">
<h:outputText value="#{documento.fechaEmision}" style="font-size:11px;" />
</p:column>
<p:column headerText="Ambiente"
style="width:10% ; text-align:center ; font-size:11px">
<h:outputText value="#{documento.id.ambiente}" style="font-size:11px;" />
</p:column>
<p:column headerText="Estado" style="width:20% ; font-size:11px">
<p:row>
<p:column>
<h:outputText value="#{documento.estadoTransaccion}" style="font-size:11px;" />
</p:column>
<p:column>
<p:commandButton update=":frmData:display" oncomplete="detalleEstadoDiag.show()" icon="ui-icon-search" style="float:right;">
<f:setPropertyActionListener
target="#{cabDocumentoMB.seleccionDocumentos}"
value="#{documento}"
/>
</p:commandButton>
</p:column>
</p:row>
</p:column>
<p:column headerText="PDF" style="font-size:11px" >
<p:commandLink action="#{cabDocumentoMB.pdf(documento,'')}"
ajax="false"
disabled="#{CabDocumentoMB.desactivaBotonPDF}"
update=":frmData:datosDetalle22">
<p:graphicImage value="/imagenes/pdf.png" ></p:graphicImage>
<f:setPropertyActionListener
target="#{cabDocumentoMB.documentos}"
value="#{documentos}" >
</f:setPropertyActionListener>
</p:commandLink>
</p:column>
<p:column headerText="XML" style="font-size:11px" >
<p:commandLink
action="#{cabDocumentoMB.xml(documento)}"
ajax="false"
update=":frmData:datosDetalle22"
disabled="#{CabDocumentoMB.desactivaBotonXML}">
<p:graphicImage value="/imagenes/xml.png"></p:graphicImage>
<f:setPropertyActionListener
target="#{cabDocumentoMB.documentos}"
value="#{documentos}">
</f:setPropertyActionListener>
</p:commandLink>
</p:column>
<p:column selectionMode="multiple"/>
</p:dataTable>
<p:dialog header="Detalle de estado" widgetVar="detalleEstadoDiag" resizable="false" width="400" showEffect="explode" hideEffect="explode" style="font-size:11px" >
<h:panelGrid id="display" columns="2" cellpadding="4">
<div align="left" style="font-size:11px;"><h:outputText value="Descripción: " style="font-weight:bold" /></div>
<h:outputText value="#{cabDocumentoMB.seleccionDocumentos.msjError}" />
</h:panelGrid>
</p:dialog>
</h:panelGroup>
</p:panel>
<p:panel id="datosExcel" style="align=center">
<h:commandLink>
<p:graphicImage value="/imagenes/excel.png" />
<p:dataExporter type="xls"
postProcessor="#{manager.postProcessXLS}" target="myData"
fileName="myexcel" />
</h:commandLink>
</p:panel>
</h:form>
</ui:define>
</ui:composition>
</html>
Backing: (PDF Method)
...
JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(detallesAdiciones);
String reportPath = pathReports.get(doc.getId().getCodigoDocumento());
JasperPrint jasperPrint = null;
try {
jasperPrint = JasperFillManager.fillReport(reportPath, obtenerMapaParametrosReportes(obtenerParametrosInfoTriobutaria(doc), obtenerInfoFactura(lstFactDetAdictDocumento,doc)), beanCollectionDataSource);
} catch (JRException e) {
e.printStackTrace();
}
HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
httpServletResponse.addHeader("Content-disposition", "attachment; filename="+name);
ServletOutputStream servletOutputStream = null;
try {
servletOutputStream = httpServletResponse.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
try {
JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
} catch (JRException e) {
e.printStackTrace();
}
FacesContext.getCurrentInstance().responseComplete();
Here, XHTML code, Which have 2primeface datatable.
I want to pass dialog box inputText value to addRow() of Managed Bean with #{invoice.id} value.
But value of all inputText is become NULL.
After new row data will update in invoiceTable and display new entery.
<p:panelGrid columns="3">
<p:outputLabel value="Enter Invoice Number :" />
<p:inputText id="inputInvoiceNumber"
value="#{invoiceBean.invoiceNumber}" />
<p:commandButton value="Search" type="submit">
<f:ajax execute="inputInvoiceNumber" render="outputInvoiceNumber" />
</p:commandButton>
</p:panelGrid>
<br />
<p:dataTable id="outputInvoiceNumber"
value="#{invoiceBean.invoices}" var="invoice">
<p:column headerText="Invoice Id ">
<p:outputLabel value="#{invoice.id}" />
</p:column>
<p:column headerText="Email">
<p:outputLabel value="#{invoice.email}" />
</p:column>
<p:column headerText="Invoice Number ">
<p:outputLabel value="#{invoice.invoiceNumber}" />
</p:column>
<p:column headerText="Date">
<p:outputLabel value="#{invoice.date}" />
</p:column>
<p:column headerText="Delivery Note ">
<p:outputLabel value="#{invoice.deliveryNote}" />
</p:column>
<p:column headerText="Supplier Reference">
<p:outputLabel value="#{invoice.supplierReference}" />
</p:column>
<p:column headerText="Other Reference">
<p:outputLabel value="#{invoice.otherReference}" />
</p:column>
<p:column headerText="Buyer Name">
<p:outputLabel value="#{invoice.buyerName}" />
</p:column>
<p:column headerText="Buyer Address">
<p:outputLabel value="#{invoice.buyerAddress}" />
</p:column>
<p:column headerText="Dispatch Document Date">
<p:outputLabel value="#{invoice.dispatchDocumentDate}" />
</p:column>
<p:column headerText="Dispatch Through">
<p:outputLabel value="#{invoice.dispatchThrough}" />
</p:column>
<p:column headerText="Destination">
<p:outputLabel value="#{invoice.destination}" />
</p:column>
<p:column headerText="Terms Of Delivery">
<p:outputLabel value="#{invoice.termsOfdelivery}" />
</p:column>
<p:column headerText="Net Total">
<p:outputLabel value="#{invoice.netTotal}" />
</p:column>
</p:dataTable>
<br />
<p:dataTable id="invoiceTable" var="invoiceProductsServicesDetail"
value="#{invoiceBean.invoiceProductsServicesDetails}" border="1"
editable="true">
<p:column headerText="Sr. No.">
<p:outputLabel
value="#{invoiceProductsServicesDetail.serialNumber}" />
</p:column>
<p:column headerText="Description of Goods">
<p:outputLabel
value="#{invoiceProductsServicesDetail.descriptionOfGoodsOrService}" />
</p:column>
<p:column headerText="HSN Code">
<p:outputLabel value="#{invoiceProductsServicesDetail.hsnCode}" />
</p:column>
<p:column headerText="Quantity">
<p:outputLabel value="#{invoiceProductsServicesDetail.quantity}" />
</p:column>
<p:column headerText="Rate">
<p:outputLabel value="#{invoiceProductsServicesDetail.rate}" />
</p:column>
<p:column headerText="Percentage Discount">
<p:outputLabel
value="#{invoiceProductsServicesDetail.percentDiscount}" />
</p:column>
<p:column headerText="Amount">
<p:outputLabel
value="#{(invoiceProductsServicesDetail.rate) * (invoiceProductsServicesDetail.percentDiscount) }" />
</p:column>
<p:summaryRow>
<p:column colspan="5" style="text-align:right">
<p:outputLabel value="Total" />
</p:column>
<p:column>
<p:outputLabel value="#{invoiceBean.netTotal}" />
</p:column>
</p:summaryRow>
<f:facet name="footer">
<p:commandButton value="Add Invoice" type="button"
onclick="PF('addInvoice').show();" />
</f:facet>
</p:dataTable>
<p:dialog id="invoiceDialog" header="Add Invoice"
widgetVar="addInvoice" minHeight="40" showEffect="explode"
hideEffect="fold">
<table border="1" id="dialogTable">
<tr>
<td><p:outputLabel value="Description Of Goods Or Services" /></td>
<td><p:outputLabel value="HSN Code" /></td>
<td><p:outputLabel value="Quantity" /></td>
<td><p:outputLabel value="Rate" /></td>
<td><p:outputLabel value="Percentage Discount" /></td>
</tr>
<tr>
<td><p:inputTextarea id="description"
value="#{invoiceBean.descriptionOfGoodsOrService}" cols="45"
required="true" label="Description"
requiredMessage="Description Require Entry" /></td>
<td><p:inputText value="#{invoiceBean.hsnCode}" size="6" /></td>
<td><p:inputText id="quaintity"
value="#{invoiceBean.quantity}" size="3" styleClass="Alingment"
required="true" label="Quantity"
requiredMessage="Quantity Require Entry" autocomplete="off" /></td>
<td><p:inputText id="rate" value="#{invoiceBean.rate}"
styleClass="Alingment" required="true" label="Rate"
requiredMessage="Rate Require Entry" autocomplete="off" /></td>
<td><p:inputText value="#{invoiceBean.percentDiscount}"
size="2" styleClass="Alingment" autocomplete="off" /></td>
</tr>
</table>
<p:commandButton type="submit" value="Save New Invoice"
action="#{invoiceBean.addRow}" update=":form:invoiceTable growl"
process="#this invoiceTable" onsuccess="PF('addInvoice').hide();"
onerror="PF('addInvoice').show();">
<f:ajax render=":form:invoiceTable" />
</p:commandButton>
<p:growl id="growl" showDetail="true" sticky="true" />
</p:dialog>
<br />
<p:commandButton value="Create Pdf"
action="#{createPdf.createPdfFile}" ajax="false">
<f:setPropertyActionListener value="#{invoiceBean.invoiceNumber}"
target="#{createPdf.invoiceNumber}" />
</p:commandButton>
</h:panelGroup>
Here, Managed Bean addRow() method which use to add new row in invoiceTable with new value of dialog box input : invoiceBean
public void addRow() {
invoiceProductsServicesDetail = new InvoiceProductsServicesDetail();
invoiceDao = new InvoiceDao();
FacesContext facesContext = FacesContext.getCurrentInstance();
DataTable dataTable = (DataTable) facesContext.getViewRoot()
.findComponent("form:invoiceTable");
UIComponent uiTable = ComponentUtils.findParentForm(facesContext,
dataTable);
final AjaxBehavior behavior = new AjaxBehavior();
try {
if (descriptionOfGoodsOrService != ""
&& descriptionOfGoodsOrService != null && rate != 0
&& quantity != 0) {
invoiceProductsServicesDetail.setSerialNumber(dataTable
.getRowCount() + 1);
invoiceProductsServicesDetail
.setDescriptionOfGoodsOrService(descriptionOfGoodsOrService);
invoiceProductsServicesDetail.setHsnCode(hsnCode);
invoiceProductsServicesDetail
.setPercentDiscount(percentDiscount);
invoiceProductsServicesDetail.setQuantity(quantity);
invoiceProductsServicesDetail.setRate(rate);
invoiceProductsServicesDetail.setInvoiceId(id);
invoiceProductsServicesDetails
.add(invoiceProductsServicesDetail);
amount = (rate * quantity);
this.grossTotal = amount = (amount - (amount * (percentDiscount / 100)));
this.netTotal = ((amount) + (amount * (Constants.VAT / 100)) + (amount * (Constants.SERVICE_TAX / 100)));
System.out.println(grossTotal);
System.out.println(netTotal);
invoiceDao
.insertInvoiceProductsServicesDetail(invoiceProductsServicesDetail);
RowEditEvent rowEditEvent = new RowEditEvent(uiTable, behavior,
invoiceProductsServicesDetail);
rowEditEvent.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
dataTable.broadcast(rowEditEvent);
}
} catch (AbortProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Your dialog submit button
<p:commandButton type="submit" value="Save New Invoice"
action="#{invoiceBean.addRow}" update=":form:invoiceTable growl"
process="#this invoiceTable" onsuccess="PF('addInvoice').hide();"
onerror="PF('addInvoice').show();">
<f:ajax render=":form:invoiceTable" />
</p:commandButton>
Only processes itself and the invoiceTable and not the invoiceDialog with all the values you enter in the dialog. Try changing it to
process="#form invoiceTable"
to process the whole dialog. Additionally, it is advisable to contain a dialog in an own form to be able to process the form without having to process all surrounding input elements not related to the dialog.
I'm currently working with a PrimeFaces dataTable and am trying endlessly to append a new to the dataTable immediately after the user adds it. Server-side, everything is working -- data is saved to both the database and hard disk. I'd like to see a partial-page update following the successful request, and I just can't seem to get it to work. Here is my XHTML code:
<div class="content">
<div id="mainContent">
<div class="topNav">
<h:form id="navForm">
<p:commandButton value="Upload"/>
<p:commandButton value="New Folder" onclick="createDlg.show();" />
<p:commandButton value="Delete Folder" action="#" />
</h:form>
</div>
<div id="filePanel">
<h:form id="dataTable" prependId="false">
<p:dialog header="Create" widgetVar="createDlg" modal="true" height="200">
<p:panel header="New Folder">
<h:panelGrid columns="2">
<h:outputLabel value="Name:" for="txt_name"></h:outputLabel>
<p:inputText id="txt_name" value="#{directoryController.newDir.name}" required="true" />
<p:commandButton value="Create" actionListener="#{directoryController.createNew}" update="dGrid" oncomplete="createDlg.hide();"/>
<p:ajaxStatus style="width:16px; height:16px;">
<f:facet name="start">
<h:outputText value="Saving..." />
</f:facet>
<f:facet name="">
<h:outputText value="Complete." />
</f:facet>
</p:ajaxStatus>
</h:panelGrid>
</p:panel>
</p:dialog>
<p:dataTable id="dGrid" value="#{directoryController.itemsByOwner}" var="dir">
<p:column selectionMode="multiple"/>
<p:column sortBy="#{dir.name}">
<f:facet name="header">
File Name
</f:facet>
<h:outputText value="#{dir.name}" />
</p:column>
<p:column>
<f:facet name="header">
File Size
</f:facet>
</p:column>
</p:dataTable>
</h:form>
</div>
</div>
</div>
And finally, here is my backing bean.
public String createNew(){
newDir.setDateCreated(new Date());
newDir.setDateModified(new Date());
newDir.setId(BigDecimal.ZERO);
newDir.setLocation(ROOT_DIRECTORY + currentUser.getUsername() + "/");
newDir.setFilesCollection(f);
newDir.setDescription("");
newDir.setOwner(currentUser);
current = newDir;
create();
persistDirectoryFromObject(newDir);
newDir = new Directory();
RequestContext.getCurrentInstance().addPartialUpdateTarget("dGrid");
return null;
}
If you are using 3.0.M4 you could do:
...
...
<p:outputPanel autoUpdate="true">
<p:dataTable id="dGrid" value="#{directoryController.itemsByOwner}" var="dir">
<p:column selectionMode="multiple"/>
<p:column sortBy="#{dir.name}">
<f:facet name="header">
File Name
</f:facet>
<h:outputText value="#{dir.name}" />
</p:column>
<p:column>
<f:facet name="header">
File Size
</f:facet>
</p:column>
</p:dataTable>
</p:outputPanel>
or you could simply:
<p:commandButton value="Create" action="#{directoryController.createNew}" oncomplete="createDlg.hide();" ajax="false" />
I am having trouble updating components in primefaces. Here is one example:
<h:form>
<p:panel style="width: 350px;" header="Partial Process">
<p:dataTable id="tablaPersonas" var="per" value="#{manejador.lista}">
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="Nombre" />
</f:facet>
<h:outputText value="#{per.nombre}" />
</p:column>
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="Apellido" />
</f:facet>
<h:outputText value="#{per.apellido}" />
</p:column>
<p:column headerText="Editar" style="text-align: center;">
<p:commandButton value="Editar"/>
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton value="Abrir" onclick="widgetDlgAgregar.show();"/>
<p:dialog header="Agregar" widgetVar="widgetDlgAgregar" width="250" height="150" closable="true">
<h:panelGrid id="gridAdd" columns="2">
<h:outputLabel value="Nombre:"/>
<p:inputText value="#{manejador.auxiliarAgregar.nombre}"/>
<h:outputLabel value="Apellido:"/>
<p:inputText value="#{manejador.auxiliarAgregar.apellido}"/>
<p:commandButton oncomplete="widgetDlgAgregar.hide();" update="tablaPersonas,gridAdd" value="Agregar" actionListener="#{manejador.agregarPersona}"/>
</h:panelGrid>
</p:dialog>
</h:form>
As you see, I click on a CommandButton called "Abrir" and a Dialog opens with "Agregar" as title. I fill in the input boxes and when I click the CommandButton "Agregar", the DataTable isn't updated. Why is this happening?
Oh sorry i think you forgot this update
try this it should work
<h:form prependId="false">
<p:panel style="width: 350px;" header="Partial Process">
<p:dataTable id="tablaPersonas" var="per"
value="#{manejador.lista}">
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="Nombre" />
</f:facet>
<h:outputText value="#{per.nombre}" />
</p:column>
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="Apellido" />
</f:facet>
<h:outputText value="#{per.apellido}" />
</p:column>
<p:column headerText="Editar" style="text-align: center;">
<p:commandButton value="Editar" />
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton value="Abrir" onclick="widgetDlgAgregar.show();" update="gridAdd" />
<p:dialog header="Agregar" widgetVar="widgetDlgAgregar" width="250"
height="150" closable="true">
<h:panelGrid id="gridAdd" columns="2">
<h:outputLabel value="Nombre:" />
<p:inputText value="#{manejador.auxiliarAgregar.nombre}" />
<h:outputLabel value="Apellido:" />
<p:inputText value="#{manejador.auxiliarAgregar.apellido}" />
<p:commandButton oncomplete="widgetDlgAgregar.hide();"
update="tablaPersonas,gridAdd" value="Agregar"
actionListener="#{manejador.agregarPersona}" />
</h:panelGrid>
</p:dialog>
</h:form>
try to put your
<p:dialog header="Agregar" widgetVar="widgetDlgAgregar" width="250" height="150" closable="true">
outside the form and add prependId="false" to your form <h:form prependId="false" >