p:commandLink doesn't trigger p:blockUI - jsf

I am using PrimeFaces. Here is the code:
<h:form>
<p:dataTable...>
<p:column...>
<p:commandLink id="featuresLinkId"...>
</p:column>
</p:dataTable>
</h:form>
<p:blockUI block=":smForm" trigger="featuresLinkId">
<p:graphicImage alt="loader image" value="/images/loader.gif"/>
</p:blockUI>
When the page is being loaded, I see the following error:
javax.servlet.ServletException:
Cannot find component with identifier "featuresLinkId" in view.
Seems like commandLink can't be used to trigger blockUI in such a scenario. What could the problem be?

Because it won't find that compnent because its inside the form/datatable.
Make changes as
1-
<h:form id="formId">
2-
<p:dataTable id="tbl">
3-
<p:blockUI block=":smForm" trigger=":formId:tbl:featuresLinkId">
Try above .

There's a bug in Primefaces 3.5 I think
see: How to reference p:commandLink in p:dataTable from p:blockUI trigger?
You could try using JQuery BlockUI http://www.malsup.com/jquery/block/

Related

Issue with primefaces dynamic dialog

I have a dynamic Dialog with a CommandButton or an OutputLabel inside, using a value that takes time to generate. To avoid loosing time when loading the page, I used the dynamic param of the dialog. Unfortunately, my function is still called and the necessary time to display the page is very long.
<p:dialog dynamic="true">
<h:outputText value="#{myBean.myFunction()}"/>
</p:dialog>
Any idea what the issue could be?
Using PF Version 11.0.7
Add appendTo="#(body)" to p:dialog, that should help.
<p:dialog appendTo="#(body)" dynamic="true">
<h:outputText value="#{myBean.myFunction()}"/>
</p:dialog>
visit: https://primefaces.github.io/primefaces/12_0_0/#/core/dialogframework

Primefaces blockUI stops responding

I have a datatable and a commandbutton. I want to use blockui when user either clicks to datatable paginators or refresh button. At first blockui works with paginators good but after when I click to commandbutton, blockui works once and then it stops working. Is there any idea?
<p:commandButton value="refreshDatatable"
id="refreshLogListButtonId2"
onclick="loading.show();"
oncomplete="loading.hide();"
immediate="true"
update="logsTableId"
icon="ui-icon-refresh"
actionListener="#{logViewerController.refreshLogsFromDB()}"/>
<p:dataTable id="logsTableId" var="log"....../>
<p:blockUI block="logsTableId" trigger="logsTableId" widgetVar="loading">
Refreshing<br />
<p:graphicImage library="images" name="loading.gif"/>
</p:blockUI>
Did you try to add the id of your in the trigger attribute of the separated by ",", like that:
<p:blockUI block="logsTableId" trigger="logsTableId,refreshLogListButtonId2" widgetVar="loading">
Refreshing<br />
<p:graphicImage library="images" name="loading.gif"/>
</p:blockUI>
Do not update blockUI component. Use either the trigger attribute or the widgetVar, there is no reason to use both.

primefaces panelgrid update from datatable

I am getting "Cannot find component with identifier "contentForm:tabView:form:addressDialogPanel" referenced from "contentForm:tabView:form:addressBookTable" " error. How can I update my panelGrid inside the widget?
<h:form id="form">
<p:dataTable id="addressBookTable">
<p:ajax event="rowSelect" listener="#{addressBookController.onRowSelect}"
update="contentForm:tabView:form:addressDialogPanel" oncomplete="addressDialog.show()" />
</p:dataTable>
<p:dialog id="addressDialogId" widgetVar="addressDialog">
<h:panelGrid id="addressDialogPanel" columns="2" cellpadding="4">
</h:panelGrid>
</p:dialog>
</h:form>
The main problem is that you are giving the wrong client ID of component's. Also p:tabView is a component it is not a form. When you define a h:form, it generates a standart HTML form element. And when you submit the page JSF uses POST to submit your data into backing bean. So nesting them is going to occur lot's of issues that you don't expect. You should seperate forms into sections like sideForm or searchForm or etc.
You should detect the correct client ID of your component when you try to update it. You can do this with your browser's developer settings(press f12 for chrome). Then select component with the magnifier button and give that ID into update property. Just like here:
You should read to learn basics of JSF for example from here

p:commandButton with p:fileDownload and no ajax only works in second click

I'm using JSF 2.0, Primefaces 3.4.2, Spring 3.1.2.
I'm facing a similar problem of the guy of this link: h:commandButton works from the second click.
Like him I'm not using ajax in the <p:commandButton> but I'm using a <p:fileDownload /> inside the button tag.
I have two views: "list.xhtml" and "downloadView.xhtml". In myBean.java I send a DataModel from view "list.xhtml" to view "downloadView.xhtml" as a request attribute as shown in the code below:
FacesUtil.getServletContext().setAttribute("myDataModelFromRequest", this.myDataModel);
The bean is anotted with #Scope("view")
In view "downloadView.xhtml" I populated succesfully a dataTable with the DataModel sent from request. But the problem happens when I click in the button to download the file. It only works on second try.
I already tried to change the return of my method from null to "downloadView" but the problem was not solved.
In debug mode I noticed that only enter in the "downloadMethod()" on second click.
Anyone have an idea to solve it?
myBean.java
public String viewListMethod() {
//some work here...
FacesUtil.getServletContext().setAttribute("myDataModelFromRequest", this.myDataModel);
return "downloadView";
}
downloadView.xhtml
<h:form id="formId" prependId="false">
<p:dataTable
id="dataTableId" var="myVar" value="#{myDataModelFromRequest}"
selection="#{cargaProcessoControlador.myArray}"
paginator="true" rows="10" paginatorPosition="bottom" paginatorAlwaysVisible="false">
<f:facet name="header">
bla bla bla
</f:facet>
<p:column selectionMode="multiple" style="width:18px" />
//collumns here...
</p:dataTable>
<p:commandButton id="btDownload" ajax="false" value="Download" icon="ui-icon-document" >
<p:fileDownload value="#{myBean.downloadMethod()}" />
</p:commandButton>
</h:form>
The scope "view" on spring doesn´t exist... So you created your own, right? Just to check...
I had that kind of problem once, and I think it was something to do with validation... the
immediate=true attribute solved my problem.
This is something to do with the scope of the page. Your problem is due to partial rendering of page. Initially when you load the page it is not getting loaded fully and because of that the button is not part of that particular view when you try to click on the button for the first time. Try to make you view proper or explicitly render the page from the backing bean before displaying the page

How to update a component inside of dataTable from outside of it

I am using Mojarra implementation of JSF 2.1 with Primefaces 3.2.
My problem approximately looks like this:
<p:dialog id="someDialog">
..
<h:form id="dialogForm">
<p:commandLink action=".."update=":someForm:someUIRepeat:someDataTable:someInputTextArea"/>
</h:form>
</p:dialog>
<h:form id="someForm">
<ui:repeat id="someUIRepeat" value=".." ..>
<p:dataTable id="someDataTable" value=.. >
<p:column>
<p:inputTextarea id="someInputTextarea" value=../>
<p:column>
.. here go other columns
<ui:repeat>
</h:form>
The issue is that when I click on the commandLink in the dialog the inputTextarea is not updated. However, if I write this in the update of the commandLink:
update=":someForm:someUIRepeat:someDataTable,:someForm:someUIRepeat:someDataTable:someInputTextArea"
then the whole dataTable gets updated and the inputTextarea updates as well, but the values in the fields located in other columns get erased after I click on the commandLink in the dialog.
The reason why I put dataTable inside of ui:repeat is that I need to bind a dataTable with each row of one collection and I think it's not related to my problem.
Any ideas how I can solve this problem?
Thanks in advance,
Nurzhan.
for start try this
added onclick="jQuery('#someForm:someButton').click();"(check the exact id of your hidden button) to your <p:commandLink inside the dialog
set the update to update=":someForm:someUIRepeat:someDataTable"
and add
<h:commandButton id="someButton" style="display:none">
<f:ajax execute="#form"></f:ajax>
</h:commandButton>
to <h:form id="someForm">
explanation: the purpose of the hidden button is to execute (send its values) the form to the server so that when you do call update the fields wont be erased...

Resources