jsf primefaces - two p:dataTable pagination questions - jsf

I'm using a p:dataTable with pagination like so:
<p:dataTable var="user" value="#{userBean.users}"
paginator="true" rows="20"
paginatorTemplate="{PageLinks}" >
Two questions:
1) Is there a way to tell it to not show the page numbers when there's only one page?
2) When I click from page 1 to page 2, the whole web page refreshes. On the PrimeFaces demo the pagination flips pages with an AJAX-style update. What have I done wrong that the web page is refreshing?
Any help is greatly appreciated, thanks!
rob

Try the following for question 1:
paginatorAlwaysVisible="false"
From the primefaces javadoc:
paginatorAlwaysVisible: Defines if paginator should be hidden when number of rows displayed is less than paginator rowsPerPage option.

Related

How to only update input of p:selectOneMenu, not the suggestion panel

I'm using primefaces 5.3 and i have a page which has p:selectOneMenu as below:
<p:selectOneMenu id="addressCountry" value="#{myBean.address.country}">
<f:selectItems value="#{myBean.countries}" var="country"
itemValue="#{country.code}" itemLabel="#{country.name}" />
</p:selectOneMenu>
This is a combobox that allow users to select their country. It show all countries around the world (250 countries) so it lead to performance problem.
My page have several tabView and each of them has several comboboxes like this, when i switch tab and update whole tabView, all those comboboxes will be renderred again and it increase payload a lot.
I know with SelectOneMenu, Primefaces divide it into two parts: the input and the panel to hold all selectable options. When i update this component by id (update=":#{p:component('addressCountry')}"), Primefaces will render both parts, even the panel just static contents and no need to be rendered again for every request.
I've try to update by css selector (just select the input) but it also not work.
Can we only update the input, exclude the panel when we need?
Anybody can help me?
Thanks alot

Primefaces datatable and current page not working

I'm using Prime Faces 6.0.
I've a datatable with a LazyDataModel. The user can change the page with the built-in paginator.
When the user switch from the first page, to the second I need to know the currentPage, and I need it in the client part.
This is the code of the datatable
<p:dataTable
id="listingsTable"
value="#{listingsLazyDataModel}"
var="actualAd"
paginator="true"
rows="#{applicationScopedBean.advertisingsPaginationSize}"
lazy="true"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="10,20,30"
paginatorPosition="bottom"
widgetVar="listingsTableDesktop"
first="#{searchAdvertisingModel.currentPage*applicationScopedBean.advertisingsPaginationSize}">
...
...
<p:ajax event="page" listener="#{listingsController.pageChanged}" oncomplete="pageChangedOnDetails(PF('listingsTableDesktop'))" />
...
---
</p:dataTable>
and this is the js code
function pageChangedOnDetails(listingsTableDesktop){
console.log(listingsTableDesktop.paginator.getCurrentPage());
}
The problem is that the getCurrentPage() method returns the previous page. Not the actual one. Just for information, the page is base 0. So the first page is the page 0.
Example of the actual behaviour vs expected one
User land in the page and see the first page.
User switch to the second page. getCurrentPage -> 0 WRONG expected 1
User switch to the third page. getCurrectPage -> 1 WRONG expected 2
User switch to the first page. getCurrentPage -> 2 WRONG expected 0
In which way can I solve this?
Thank you
The base is 0 but your event function is running way to soon it seems.
Try running your function else where other then event="page".
I mean by this, when your page is a 1 (default) and you click for example on page 3, it outputs a 0 (0+1= page 1) and ONLY AFTER THAT it goes to page 3. If you click on page 6 now, it outputs a 2 (2+1= page 3) and ONLY AFTER that it goes to page 6.
This happen even with oncomplete instead of onclick. Hope it helped.
This problem was a bug found in PF 6.0 and 6.1, but with the current version (6.2) this problem is solved

Primefaces Paginator

I have a simple primefaces datatable with paginator="true". The table has data and the arrow buttons are showing for the paginator but when I click one nothing happens. It doesn't even appear to post back to the server. Here is my datatable declaration:
<p:dataTable id="datatable" var="currentRow" value="#{myBean.Items}" paginator="true" rows="10">
Am I missing something?
Thanks!
Make sure your table is inside a <h:form> element.

Primefaces : lazy loaded datatable's paginator buttons not showing

i have previously used datatable pagination and it worked as a charm. This time i needed to use the lazy loaded pagination and its showing the first page and there are no paginator buttons. I have tried a lot of things but it just isnt showing the paginator buttons. if i change the number of rows, it works i.e the number of rows on tht page changed but the paginaotor buttons are not showing. if i inspect the datatable in chrome, it shows thr is a div for the paginator bottom
<div xmlns="http://www.w3.org/1999/xhtml" id="j_idt7:contentTable_paginatorbottom" class="ui-paginator ui-paginator-bottom ui-widget-header ui-corner-bl ui-corner-br"></div>
this is my datatable
<p:dataTable id="contentTable" value="#{chatroomBean.lazyLoadedChatroomBeans}"
var="chatroom" paginator="true" paginatorPosition="bottom" rows="10" lazy="true"
paginatorTemplate=" {PreviousPageLink} {CurrentPageReport} {NextPageLink} "
rendered="#{chatroomBean.chatroomSearchText!=null}">
i am using jsf2, primefaces 2.2.1 and apache tomcat 6.
any help idea will be much appreciated. thanks
regards
khizar
I think you've run into this bug.
From the linked-to forum discussion:
Here is a workaround. Copy the
following lines in your load-Methode,
to update the pagination:
RequestContext context =
RequestContext.getCurrentInstance();
if(context!=null)context.addCallbackParam("totalRecords",
i);
The Variable i stand for the result of
the projections query.
its late but i just saw this question n remembered tht i had solved the prob so i thot i shud leave an answer here just in case sum1 else runs into it. the problem was tht the theme i was using cudnt find the images for the buttons, due to sum reason i cant remember now, i was not using the jar for the theme, i just added the theme.css to my project and it started working ... only problem was the links to images in the theme.css were like
url("#{resource['primefaces-glass-x:images/default.png']}") 0 0
changed them to this
url(images/default.png) 0 0
n it works like a charm ...
another solution (n probably the better one) wud be to add the jar for the theme in classpath and add the theme to web.xml but everyone probably knows tht ... :)
Regards,
khizar

JSF Datatable current Page Primefaces

I would like to display the current page of a datatable outside of the table (I actually need it for paging a the items on a google maps component). How can I get the current page of the datatable?
Thanks,
D
In tomahawk you can use dataScroller pageIndexVar (only inside datascroller component)
<t:dataScroller for="data_table" pageIndexVar="current_page">
<h:outputText value="#{current_page}" />
</t:dataScroller>
http://myfaces.apache.org/tomahawk-project/tomahawk/tagdoc/t_dataScroller.html

Resources