Persisting a DataTable state through views in Primefaces - jsf

First of all: not native english speaker here, so sorry if I may sound a little confusing sometimes.
I'm looking for a way to persist a DataTable (that shows a query result list) state when I navigate through different views in my application (so it's not an Ajax call), in other words: I need to render a new page with a DataTable exactly as it was in the previous view. First thing you should know about this is that I have a way to transport objects through my views using ELFlash.getFlash().put(param, obj), so my problem is not recovering objects.
I was able to make the DataTable open with all the previous result list with no problems... BUT it has a paginator and I was supposed to get to the second view not only with the query results but also opened in the same page that it was before.
I already tried to keep the current page number in an object and put a code to change the paginator to that page in the post construct, but it didn't work:
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent(":form:dataTable");
String javaScript = "PF('widgetVarName').getPaginator().setPage(" + this.pageNumber + ")";
RequestContext.getCurrentInstance().execute(javaScript);
The saddest thing here is that It didn't work in post construct and the DataTable doesn't open in the right page, but if I call this code in another button, after the page is already rendered, it works.
Do you guys have any ideia?

Related

How to pass a list object from one page to another

I'm struggling to pass a list of objects from one page to another. Object data is displayed on the first page, but I can switch to another page if I want to display more details about objects.
When I click on the Back button on another page, I would like to go back to the first page and still got the same list so I can show all filtered objects again without querying them again from DB.
I have checked the documentation of passing values but I can't do that with list:
Method expression (JSF 2.0)
f:param
f:attribute
f:setPropertyActionListener
Is it with list object possible? Can someone give me example?
Thanks!

View data being cached/failing to refresh

I have a tabbed panel containing different sections of a form. In one section, users are given the ability to add a child document to the currently open document. In a second section, they are given a listbox, where the options are dynamically generated (via #DbLookup) by looking at a view of all the child documents, filtered by the current document's ID. This functionality all works correctly, however, there is a problem with the dynamic listbox options.
When a user adds a new child document, then switches to the next tab, the listbox is not updated with this new document. If they save/re-edit the main document or refresh the page, it makes no different, the user must load another XPage before going back to the original in order for the listbox to update. I have tried to resolve this by doing full updates of the page, using session.evaluate and "NoCache" in the #DBLookup call, or calling database.getView("My view").refresh(), but without luck.
There is also a similar problem where I have a repeat control which uses a view of child documents (again filtered by main document ID) as a datasource. When a user adds a child document using a button, it partially refreshes the repeat - but doesn't show the new child document until the page is refreshed again (or you leave the page and return).
Is there something crucial I am missing with regards to the JSF lifecycle/the way that view data is cached?
As first measure I would add another formula item to the listbox which simply returns the current time (#Now() should work). That way you can check if the listbox options are refreshed on the update in the first place.
If the options are refreshed fine it's indeed clear that the #DbLookup does some caching, although I'm not aware of any default caching logic.
At least for a test I would change the code to use a NotesView object instead of the #DbLookup, something like this:
var nview = database.getView("someview");
var nc = nview.getAllEntriesByKey(currentDocument.getDocument().getUniversalID(), true);
var a = [];
var ve = nc.getFirstEntry();
while (ve) {
a.push(ve.getColumnValues().elementAt(0)); // value of first column
ve = nc.getNextEntry(ve);
}
return a;
(I wrote the code from memory, there may be syntax errors).
Since the code only works with view entries it should be equally fast than the #DbLookup. And you could even do a nview.refresh() if needed.

How can I implement dynamic scrolling with ajax / JSF2.2?

I have a list of items that I would like to present. I want to ajax load items as the user scrolls down (I have no problem doing this using JS). The problem that I am experiencing is that I can only re-render the whole ui:repeat and not just a component that contains new items.
Is there an common way to do this? Can I code a bean method that returns only the <li> part of the dom and handle the weaving on the client-side? Should I just write a method that returns raw data and then use JS to handle rendering?
PS .I am sure this has been asked before, but I can't find the relevant posts

Infinite List (Pattern) with JSF/Richfaces (mobile web app)

I am currently introducing a mobile friendly version of our web-application.
In a first step I transformed a rich:dataTable with a lot of columns into a rich:dataList containing only a few columns as values.
The old table used pagination and I want to reuse this existing mechanism to some extend in the new list. In the new list, however, I don't want to paginate but append! So when I click on a "Load More" button, I want to append the new elements to the already existing ones.
However appending should not happen on the server side, but on the client side. Because the normal mechanism is to append elements on the backing bean's list on "Load More" and then trigger some reRendering (e.g. via ). The result of this, is that the old data is fetched from the server again, which I don't want. I just want the new data, which is the next pagination, to be appended to the already existing ones.
Does someone has an idea, how I can realize that?
(limiting factors: JSF 1.X and Richfaces 3.X [in combination with jQuery mobile])
An list pagination example (it's primefaces, cause I couldn't find a richface example): http://www.primefaces.org/showcase/ui/dataListAjax.jsf And something like this I want to transform into an infinite list with a "Load More" button.
Would really appreciate your help and/or ideas about that!
Thanks in advance!
Just in case somebody else is interested in this...
I found a solution or rather a workaround:
I introduced another rich:dataList, that gets rerendered every time I click on "Load More".
The "Load More" button is a "a4j:commandButton" and its action triggers pagination. Finally I use its oncomplete-attribute to call a JavaScript function, that moves the next pagination (temporary list) to my main list via jQuery DOM manipulation.
It works just fine

Make JSF wait for database

I have a JSF page to submit form values to a database. When clicking a button, values are submitted to my ManagedBeans and written to a database via JPA. Then the updated values from the database should be displayed in a dataTable at the same page.
The problem is: The database is too slow, so JSF seems to render the page before those are in the database (thus only rendering the older ones already there). How can I make JSF wait for the database to finish writing the values? I can figure out how to get the current phase of a lifecylce, but not how to stop it...
The problem is: The database is too slow, so JSF seems to render the page before those are in the database (thus only rendering the older ones already there). How can I make JSF wait for the database to finish writing the values?
This makes honestly no sense. JSF just does the job you told it to do in the bean's action method. Apparently you are not reloading the list from the DB after the persist. Perhaps you are referring to that the updated item is only visible when you refresh the page so that a new GET request is fired which reloads the data from the DB.
The canonical approach is to just reload the data from the DB immediately after the save.
public void save() {
someService.save(some); // Save item in DB.
list = someService.list(); // Reload list from DB.
}

Resources