I have this dialog:
<p:dialog
id="dlgComment"
widgetVar="dialogComentario"
modal="true"
header="#{messages.comentarios}"
width="600px"
resizable="false" showEffect="clip" hideEffect="clip">
<h:form id="formComentario">
<p:panelGrid columns="2" style="width: 100%">
<f:facet name="header">
<h:outputText value="#{monitorarEventoControlador.eventoSelecionado.titulo}"/>
</f:facet>
<h:outputText value="#{messages.inicio}" />
<h:outputText value="#{monitorarEventoControlador.eventoSelecionado.inicio}" />
<h:outputText value="#{messages.gravidade}" />
<h:outputText value="#{monitorarEventoControlador.eventoSelecionado.gravidade}" />
</p:panelGrid>
<p:dataTable id="tableComentario" var="comentario" value="#{monitorarEventoControlador.eventoSelecionado.getComentariosAsList()}" emptyMessage="#{messages.noRecordsFound}">
<f:facet name="header">
#{messages.comentarios}
</f:facet>
<p:column headerText="#{messages.dataHora}">
<h:outputText value="#{comentario.dataHora}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm" timeZone="#{monitorarEventoControlador.buscaTimeZone()}"/>
</h:outputText>
</p:column>
<p:column headerText="#{messages.usuario}">
<h:outputText value="#{comentario.usuario.orgao.sigla} - #{comentario.usuario.apelido}"/>
</p:column>
<p:column headerText="#{messages.texto}">
<h:outputText value="#{comentario.texto}" />
</p:column>
</p:dataTable>
<p:panelGrid columns="2" style="width: 100%">
<h:inputText value="#{monitorarEventoControlador.comentarioSelecionado.texto}" maxlength="80"/>
<p:commandButton value="#{messages.comentar}" actionListener="#{monitorarEventoControlador.adicionarComentario()}" icon="ui-icon-check" update="tableComentario" />
</p:panelGrid>
</h:form>
</p:dialog>
And the bean:
public void adicionarComentario() {
comentarioSelecionado.setDataHora(new Date());
comentarioSelecionado.setEvento(eventoSelecionado);
comentarioSelecionado.setUsuario(autenticador.getUsuarioCorrente());
todosOsComentarios.colocar(comentarioSelecionado);
notificarComentario(comentarioSelecionado);
eventoSelecionado.getComentarios().add(comentarioSelecionado);
todosOsEventos.colocar(eventoSelecionado);
iniciarComentario(eventoSelecionado);
}
private void notificarComentario(Comentario comentario) {
Notificacao n = new Notificacao();
n.setDataHora(comentario.getDataHora());
n.setDescricao(DateUtil.dataHoraFormatada(n.getDataHora()) + " - " + comentario.getUsuario().getOrgao().getSigla() + "(" + comentario.getUsuario().getApelido() + "): " + comentario.getTexto());
n.setComentario(true);
n.setInforme(comentario.getEvento().getInforme());
comentario.getEvento().getInforme().getNotificacoes().add(n);
}
public void iniciarComentario(Evento evento) {
comentarioSelecionado = new Comentario();
setEventoSelecionado(evento);
}
The commandButton should update a dataTable. I have just moved from Prime 3.5 to 5.1 and among other problems I managed to figure out, there is this one that's realy annoying. It was working on Prime 3.5.
To be more specific about what is going wrong here: The action is fired normaly, the data is inserted correctly, but the dataTable is no longer updated. It is the very same code I was using yesterday with Prime 3.5, but now, using Prime 5.1 the dataTable does not refresh anymore.
Any ideas ? Thanks
use : before id
Remember
if you make a dialog
Before dialog old form tag should be close
then dialog content should be placed into another form.
use :dialogid, :dialogFormId
Related
I'm working with primefaces and I'm having a problem when using p:dataTable.
<p:dataTable id="dataTable" var="label" value="#{myBean.labels}" editable="true" editMode="cell" widgetVar="dataTable" style="width: 350px;">
<p:ajax event="cellEdit" listener="#{myBean.onEdit}" update=":messages" />
<p:column headerText="Column 1" width="20">
<h:outputText id="current" value="#{myBean.currentTimeMillis}" />
</p:column>
<p:column headerText="Column 2" width="150">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{label.name}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{label.name}"/>
</f:facet>
</p:column>
</p:dataTable>
I would like that when I update the value of the second column of a row, then the value of the first column of this row is updated with a new value (currentTimeMillis).
public void public void onEdit(CellEditEvent event)
{
UIData table = (UIData) event.getComponent();
String updateClientId = table.getClientId() + ":" + table.getRowIndex() + ":current";
FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add(updateClientId);
}
Although this method in being invoked the first column is not being updated. Why? It is not working only in Firefox. It works on IE and Chrome.
Thanks in advance
I have a scenario where I have to generate input text fields against each selection of a <pickList> in the same page. I am using PrimeFaces 5.2 and JSF 2.2.
Kindly advice.
Here goes answer:
XHTML:
<p:pickList id="PojoPickList"
value="#{editRoleAction.funcFieldDTO}" var="trnxDto"
effect="bounce" itemValue="#{trnxDto.fieldValue}"
itemLabel="#{trnxDto.fieldName}" showSourceControls="true"
showTargetControls="true" converter="pickListConverter">
<p:ajax event="transfer" update="#form"
listener="#{editRoleAction.transactionTransferToDestination}" />
<f:facet id="idar556" name="sourceCaption">#{msg.LBL_AVALIABLE_ROLES} </f:facet>
<f:facet id="idar557" name="targetCaption">#{msg.LBL_SELECTED_ROLES}</f:facet>
</p:pickList>
<h:panelGrid id="myGrid" width="400px;">
<p:dataTable value="#{editRoleAction.moduleTransactionList}" rendered="#{editRoleAction.moduleTransactionList.size() gt 0}" var="mainMenu">
<p:column>
<h:panelGrid columns="2">
<h:outputText value="Price of #{msg[mainMenu.labelId]}"/>
<p:inputText value="#{mainMenu.kioskType}"/>
</h:panelGrid>
</p:column>
</p:dataTable>
</h:panelGrid>
Java:
public void transactionTransferToDestination() {
List<FunctionalityFieldDTO> destTrnx = funcFieldDTO.getTarget();
for (FunctionalityFieldDTO dto : destTrnx) {
moduleTransactionList.add(dto);
}
}
I am attempting to make a nested (Through row expansion) data table editable which is inside of another editable datatable. It appears to be having a problem with the ajax rowEdit event. When I only have one datatable as editable e.g. comment out the nested ajax tag it works. But when I try to use both It returns an error saying :
Method not found: com.aglabexpress.Admin.Billing.CompleteInvoiceController#1146df77.editInvoiceItem(javax.faces.event.AjaxBehaviorEvent)"
Is this because of the double ajax events?
How do I rectify this while keeping both tables editable?
HTMLX:
<h:form id="mainForm" >
<p:dataTable id="mainFormTable" editable="true" value="#{completeInvoiceController.labNumberBill}" var="lab" paginator="true" rows="10" rowStyleClass="#{lab.colorStatus}">
<p:ajax event="rowEdit" listener="#{completeInvoiceController.editBill}" />
<p:column>
<p:rowToggler/>
</p:column>
...
...
<p:column headerText="Date" footerText="Date">
<p:cellEditor>
<f:facet name="output">
<p:outputLabel value="#{lab.creationDateString}" />
</f:facet>
<f:facet name="input">
<p:calendar value="#{lab.creationDate}" />
</f:facet>
</p:cellEditor>
</p:column>
...
...
<p:column headerText="Edit">
<p:rowEditor />
</p:column>
<p:rowExpansion>
<p:dataTable value="#{lab.invoiceItems}" var="item" editable="true">
<p:ajax event="rowEdit" listener="#{completeInvoiceController.editInvoiceItem}" />
...
...
<p:column headerText="Description" footerText="Description">
<p:cellEditor>
<f:facet name="output">
<p:outputLabel value="#{item.description}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{item.description}" />
</f:facet>
</p:cellEditor>
</p:column>
...
...
<p:column headerText="Edit">
<p:rowEditor />
</p:column>
</p:dataTable>
</p:rowExpansion>
Beans
public void editInvoiceItem(RowEditEvent event){
InvoiceItemConstructor itc = (InvoiceItemConstructor) event.getObject();
if(cih == null){
cih = new CompleteInvoiceHelper();
}
cih.updateItem(itc);
}
public void editBill(RowEditEvent event){
CompleteInvoiceLabNumberBill bill = (CompleteInvoiceLabNumberBill) event.getObject();
if(cih == null){
cih = new CompleteInvoiceHelper();
}
cih.updateBill(bill);
}
You need to replace your nested datatable event method signature to
public void editInvoiceItem(javax.faces.event.AjaxBehaviorEvent event)
Is this because of the double ajax events?
Yes. This is a known issue (which had been originally reported for nested p:tabView) which seems to be fixed since PrimeFaces 5.0.
You can find further information in a thread (from July 2013) of the PrimeFaces forum
I have a bean:
#ManagedBean
#SessionScoped
public class MainTable
{
static List<MainTableRow> rows;
public MainTable()
{
rows = new ArrayList<>();
}
public static boolean addRow(MainTableRow mainTableRow)
{
return rows.add(mainTableRow);
}
public List<MainTableRow> getRows()
{
return rows;
}
public void setRows(List<MainTableRow> rows)
{
MainTable.rows = rows;
}
}
And my xhtml page is:
<h:body>
<h3>Query Modeling Tool - Select Excel file</h3>
<h:form>
<p:fileUpload
fileUploadListener="#{fileUploadController.handleFileUpload}"
mode="advanced" dragDropSupport="false" update="messages"
sizeLimit="10000000" fileLimit="3" allowTypes="/(\.|\/)(xls)$/"
style="font-size: 14px" />
<p:growl id="messages" showDetail="true" />
<p:dataTable id="dataTable" var="mainTableRow"
value="#{mainTable.rows}" style="font-size: 14px">
<f:facet name="header">Main Table</f:facet>
<p:column sortBy="" headerText="Index">
<h:outputText value="#{mainTableRow.index}" />
</p:column>
<p:column sortBy="" headerText="Query">
<h:outputText value="#{mainTableRow.query}" />
</p:column>
<p:column sortBy="" headerText="S1">
<h:outputText value="#{mainTableRow.s1}" />
</p:column>
<p:column sortBy="" headerText="S2">
<h:outputText value="#{mainTableRow.s2}" />
</p:column>
<p:column sortBy="" headerText="S3">
<h:outputText value="#{mainTableRow.s3}" />
</p:column>
<p:column sortBy="" headerText="S9">
<h:outputText value="#{mainTableRow.s9}" />
</p:column>
<p:column sortBy="" headerText="Uygunluk">
<h:outputText value="#{mainTableRow.uygunluk}" />
</p:column>
<p:column sortBy="" headerText="Kural">
<h:outputText value="#{mainTableRow.kural}" />
</p:column>
<p:column sortBy="" headerText="Kaynak">
<h:outputText value="#{mainTableRow.kaynak}" />
</p:column>
<p:column sortBy="" headerText="Query Type">
<h:outputText value="#{mainTableRow.queryType}" />
</p:column>
<p:column sortBy="" headerText="User Intent">
<h:outputText value="#{mainTableRow.userIntent}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
"rows" in MainTable is filled by another class, after uploading a file.
After uploading I want to refresh dataTable without clicking any button.
How can I do it?
It can be solved by one of the following points:
1. <p:fileUpload> has an attribute update that is used to ajax-update the components with a specified list of comma/space-separated ids, so you need to add id of your data table to that attribute:
<p:fileUpload ... update="messages dataTable" />
2. When a file has been uploaded, the table can also be updated programmatically in your action method:
RequestContext context = RequestContext.getCurrentInstance();
context.addPartialUpdateTarget("<path_to_your_table>");
See also:
jsf/primfaces update ui components from server event
I am trying to user a form in 'panelGrid' to render values in a dataTable using <f:ajax>. However, when submitting using the <h:commandButton> the values sent are not displayed in the dataTable. I am not getting a stack or any console errors in the browsers.
This is the my xhtml (Simplified):
Product Catalog:
<p:tabView id="tabView" style="width: 65%" >
<p:tab id="books" title="Books">
<p:dataGrid var="book" value="#{saleBean.productList}" columns="3"
rows="9" paginator="true" paginatorTemplate="{CurrentPageReport}
{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink}
{LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="3,6,9">
<h:form id="product" >
<p:panel header="#{book.name}" style="text-align: center">
<h:panelGrid columns="1" style="width: 65%">
<!-- Add Book Images here -->
<h:outputText value="#{book.price}"/>
<h:outputLabel value="Dct (in dollars): " />
<h:inputText id="discount" value="#{saleBean.item.unit_discount}" style="width: 50%" />
<p:commandButton value="Add to Cart" update=":dataTableForm:sc"
action="#{saleBean.doAddItem}"/>
</h:panelGrid>
</p:panel>
</h:form>
</p:dataGrid>
</p:tab>
<p:tab id="arts" title="Art / Various">
<!-- Art Products to be added here -->
</p:tab>
<p:tab id="other" title="Other">
<!-- Various Products to be Added here -->
</p:tab>
</p:tabView>
<hr/>
<h1>Shopping Cart</h1>
<hr/>
<h:form id="dataTableForm">
<p:dataTable id="sc" value="#{saleBean.sd}" var="item" style="width: 60%">
<p:column>
<f:facet name="header">
<h:outputText value="Product"/>
</f:facet>
<h:outputText value="#{item.product_fk}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Quantity"/>
</f:facet>
<h:outputText value="#{item.quantity}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Unit Price"/>
</f:facet>
<h:outputText value="#{item.unit_Cost}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Unit Discount"/>
</f:facet>
<h:outputText value="#{item.unit_discount}"/>
</p:column>
</p:dataTable>
</h:form>
</h:body>
This the bean (Simplified):
public String doAddItem()
{
item.setUnit_Cost(product.getPrice());
item.setProduct_fk(product);
item.setQuantity(1);
sd.add(item);
return "productCatalog";
}
According to PrimeFaces documentation :
http://www.primefaces.org/docs/vdl/3.4/primefaces-p/commandButton.html
Your actionListener="#{saleBean.doAddItem}" must use a function corresponding to that :
public void doAddItem(ActionListener event)
{
// do your stuff
}
To use action here is an example :
action="#{saleBean.doAddItem}"
public String doAddItem(void)
{
item.setUnit_Cost(product.getPrice());
item.setProduct_fk(product);
item.setQuantity(1);
sd.add(item);
return "productCatalog";
}
Try to use only pf components when you can eg p:datatable. Replace the button with a p:commandButton and use process and update instead of f:ajax.
Also maybe it will by better to include the p:datatable in the form too.