Primefaces get all data in lazy model - jsf

I am using lazy model for datatable in Primefaces. For exporting I want to get all data, by that I mean the data that is used for counting rows.
I can get all data that is shown currently on datatable page by using:
List<Info> data = (List<Info>) lazyModel.getWrappedData();
but there may be more data on more pages. Is there any method similiar to just mentioned one to get all data from datatable?
I've tried using this, but this would always return null:
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot()
.findComponent(":form:infoTable");
List<Info> data = dataTable.getFilteredValue();
Another way I've tried is to just make nearly the same query I am making for counting rows, with difference being that I get list of objects, not number of rows, but for that I also need a filter. If this could be a solution, how do I get a filter that I am using for lazy loading?
Generally, how could I solve this issue?

Solution is to get a filter.
I've fetched my custom filter from lazy model, and used it to query from overriden load method, so the only difference is that I did not use arguments first and page size.
Nothing really new to show in solution, I just had to get the filter:
Map<String, Object> filters = ((MyLazyDataModel) lazyModel).getFilters().getFilters();

Related

Lazy Loading in Primefaces

I have used Primefaces DataTable and Datascrollerwith version 5.3.x. I have a requirement which should have multiple rows . the exising one is like fetching all the records(more than 100 records) at the same time. I have a idea of lazy loading with a component that supports global filter and lazy loading with collapse panel(should close the previous opened row when new row is selected) inside each row. Can someone please guide me on this , there is a ongoing issue on performance when it fetches all the records at the stretch
You have existing solution on Lazy datatable. Your service should extend LazyDataModel and implement methods on how to fetch data. Combine that with filter and you are good to go.

Xpages: how to have a custom function return type ahead values

I have a SSJS object/function that does a custom full text search, as the results need to be in a specific order defined by my client. This function works fine in the search results view. It has a method to build the search query (add the * and the AND and all that), a property that returns the sorted results and I just added a method that returns the HTML needed for the type ahead.
My object is called SortedSearchResults. It needs to be instantiated with the search query in order to get the results and the type ahead HTML. How would I code that in the the type ahead values, so I don'T end up creating one SortedSearchResults object each time a letter is added to the type ahead field?
Would I be better off with a session managed bean? Would that make it easier? Would it make it faster? The search is limited to a maxiumum of 15 results.
Sor far, I only used SSJS code, but I am not sure how what I should do to avoid a memory hole. Here is the current code:
//TODO Memory management???
var results = new SortedSearchResults( getComponent("inputSearch").getValue());
return results.typeAheadValues;
How can I optimize this code so I don'T create unecessary "var results"? Or is it OK that way???
Thanks :)

Retrieving column values in filtered xpages view

I have a view defined on an xpage. I also have several filters (based on the columns) that the user can select and combine to filter the results in the view. I generate a query string based on this that I construct in dominoView.search (doing a complete refresh). What I would like to do is get the results of the search so that I can then update some counts displayed elsewhere on the page. I'm having a hard time figuring out where I can perform this logic, though. I'm trying to use view.getAllEntries() and then iterating over the collection. Sometimes it seems like it works, but other times I seem to be getting the unfiltered view. Someone suggested I explicitly call view.FTSearch inside one of the events (beforePageLoad?) and immediately after do my getAllEntries call, saving the results in viewScope, but I get an "Error while browses Notes view" runtime error when I try to do that. Any pointers? TIA!
EDIT: After studying the xpages lifecycle a bit (which is still a little confusing), I think I can fine-tune my question. This is my first stackoverflow question, so I hope this is okay to do and productive....
As I described, I have a dominoView defined on my xpage. A repeat iterates over the rows of the view, displaying certain fields from the documents. If I define a query in the search property, then the repeat correctly displays the reduced set of documents rather than the complete set. (The query is computed in the search property via SSJS from some variables defined in the viewScope in a combobox's eventHandler.) However, if I try to access the current entries in the view inside of the repeat's rendered section (with SSJS) using myView.getAllEntries (where myView is what's defined as the "value" of the repeat), I am still getting all of the documents, even if a query has been done. It seems like at that point, the view variable has already had its search applied (since the repeat works), so why the differing results? Is there another way to access the view's rows? To complicate this further, this is just a simple experiment that might clarify the problem; as I indicated earlier, I don't actually want to access the view data within the repeat, I want to access it in the rendered or value sections of some comboboxes defined before the repeat in the xpage file.
I hope that makes more sense now....
EDIT #2: I forgot to add that if I manually call FTSearch (or FTSearchSorted) before calling myView.getAllEntries, then I think I can make this work. It just seems unnecessary to have to do that in addition to the view's built-in search.
From what I get you want to iterate over the entries in a view that before has been filtered, i.e. whose resulting entry collection is smaller than the the view itself.
What I don't get (yet) is what you want to do with the result, or what you're axpecting to get from the iteration over your filtered view (you're mentioning some counts to be displayed somewhere else).
Probably a good way is to use the view's .getAllEntriesByKey method which returns a NotesViewEntryCollection object which then can be used for your iteration.
Don't forget to recycle the resulting NotesViewEntry objects; reason for this has been explained several times here at stackoverflow.

Default Sort of tr:table?

Is there a way to sort the initial data displayed on UI using tr:table? I know there are sort properties which can be defined on tr:column and which are used to sort the data present in the table.
But the requirement here is to have the data sorted by default when the page is opened. Is there a way to do that except sorting the table data from back end?
You can't sort a table by default, but you have to do it programmatically. With a little bit of work you can write a reusable PhaseListener which you can control from your JSF page.
Make sure it only handles a single phase (for example PhaseId.RESTORE_VIEW) and use it to set the sort order using setSortCriteria:
List<SortCriterion> sortCriteria = new ArrayList<SortCriterion>(1);
String property = "myProperty";
boolean ascending = true;
sortCriteria.add(new SortCriterion(property, ascending));
myCoreTable.setSortCriteria(sortCriteria);
Now you only have to add two <f:attribute/>s on your table to pass both the property name and the ascending boolean so you can create a reusable listener for all your tables.
In your <tr:document> you can have a <f:attribute/> with a list of table ID's to process.
as far as I know: No!
You can read from here for more information:
"TRINIDAD-1491"

Search filter using a bean's field values

Given a JSF/EJB stack, how do I filter the contents of a dataTable listing automatically using the values of a field in a pojo/entity bean?
i.e. I have an entity bean Employee with name field having a value of "John" I would like to use this bean to filter the data table to show only records with name John, and not having to construct the where clause manually?
I use PrimeFaces' dataTable with filtering and eventually lazy-Loading. Filtering alone is done at a client level, but lazy-loading is done at a server level.
Here you can find some examples.
Both are implemented with Ajax features by PrimeFaces: on typing each character, the filters are applied and the results updated.
With PrimeFaces' lazy-loading you have also the possibility to handle by yourself the filters: on typing a character in a filter, your implementation of the filter is invoked: with a little of Criteria Builder queries you can write the WHERE conditions in a type-safe and OO way, by building an array of Predicates: this implies that you don't need to write a single line of sql code.

Resources