How to pass a list object from one page to another - jsf

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!

Related

Persisting a DataTable state through views in Primefaces

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?

How to populate datalist on new page in View Scope?

I have a dashboard with number of items on it. One of them is "Teachers". I am using <h:link> to go to show-teachers.xhtml which has a search box on it initially. Scope of this bean is view scope and it has two methods:
getAllTeachers - This method is void as it is called when user clicks on the search button and results are populated on the page using datalist and rendered is set to true to display the datalist. This work fine.
getAllStudentsByTeacher - Once I have the list of teachers from above method the next step is to fetch the list of students under a specific teacher and list them using datalist on a new page(show-students.xhtml).
Above method fetches the list of students from the database and return string show-students which is another XHTML page on which I want to show the list of matching students using datalist.
But I always get result No records found on show-students page.
When I change the scope of this bean to session, it works fine. But I would like to use either request or view scope.
Please suggest me If I am missing anything as I am learning JSF/Primefaces :)
Thanks
Rahul Saraswat

passing value while using view scope in jsf

I have a table with few rows and one of the columns consists a button,now when i click on the edit button it takes me to a new JSF page.The details in the edit page are not getting populated.I am using view scope for my Managed Bean.I have gone through some of the posts and understood that view scope will be lost once the user leaves from that page.
I have gone through various other posts which suggested me to pass value to another bean and then get it into new jsf or by using f:viewparam. I wanted to know how i could achieve this functionality:
I want this flow to be achieved using view scoped managed bean JSF1-->on click of edit button in table-->View Scoped Managed Bean-->JSF2(details need to be populated but shows null values)
In the edit details page the value is shown null.
Could you let me know how I can achieve this functionality.Thanks.

The buttons in a repeat don't hide/show after refreshing the panel the repeat is in?

I have a repeat that has buttons embedded in it. The repeat is in a panel. When the user clicks a button the button should hide/show (I partial refresh the panel). The repeat is tied to a Domino view and I see the other values that I from that view get updated in the repeat, so, it does not seem like a view index issue (I refresh the view index in my code.)
If I use context.reloadPage() in my button onclick code then the buttons will hide/show like they should, but, that seems like I am using a sledge hammer! Any suggestions on how to get the buttons to recompute the visible property when the panel that holds the repeat is rendered? Another strange thing is that the visible property gets computed three times whenever I refresh the panel that holds the repeat.
thanks, Howard
I think your looking for
getComponent("<id>").setRendered(true / false);
Hi For Repeat control's entry is used to make our head hard. Because handling the entry by SSJS, we can get the value and set the value. But rendering part, id of the repeating component are same for all. So if we try to give reder as false. It hides all of our repeating component.
Try to use the following., [Put this in button onclick, and see the value of below]
var entryValue= getComponent("repeat1").getChildren().get(0).getValue()
getComponent("inputText1").setValue(entryValue)
But in client side we can easily handle. Because the id of the DOM object is unique for all repeating component.
var id1="view:_id1:repeat2:"+'2'+":button1"
document.getElementById(id1).style.display="none"
This will hide the third entry of your repeat control component.
Please see the post, You may get better idea
Found a solution. My original solution was getting values from the repeat rows (using the collection object, which was a viewentrycollection and using getColumnValues) to compute the rendered property for the buttons.
Instead, I created a viewScope variable (a Vector) that holds the state of the buttons (which set of buttons to show). This gets populated in the beforePageLoad event of the page.
The button onclick code updates this viewScope variable after performing its processing. All works very nice now. I guess it was something in the JSF lifecycle that kept the buttons from being properly updated. Using the viewScope variable works fine.
With addition to what Ramkumar said, you can use the index variable in the repeat control to identify each and every occurrences inside the repeat control. You will get more idea, if you inspect with element from firefox[You might need firebug]. Usually the field mentioned inside a repeat control itself can be considered as an array

Automatically open document when only one document is listed in repeat control

I have a repeat control for a domino view which displays the results from a search field.
As you type more characters into the search field the number of items in the list is reduced. If/When the the list only contains a single item I would like to open item automatically, without having to click the link.
Any ideas are appreciated.
Edit: after some very interesting responses, here are some screenshots
I have 3 elements on the page, a searchbar, a repeat control and a form:
When I start typing in the search bar, the repeat is refreshed with every keystroke:
the list is reduced, typing the next character ...
again the list is reduced, only 2 left, typing again....
Only one left, now it would be time to open the document in the form ..... without clicking the link.
I've tried several events on the page, but it seems that I could not find the one that will allow me to "select" the document and display the data in the form.
It seems that it's not as simple as I thought
Since you want to open the link automatically I don't know if I would try to base it on the getRowCount() of the repeat itself. You don't want to even get that far right? you just want to go to the single document.
I would put a function in beforePageLoad event maybe. Not totally sure which event but I'd try that first. Use SSJS and do a lookup that would basically return a collection of what the repeat would show. If the collection count = 1 then get your destination from that entry and do your redirection from there.
That what I would try at least. Interesting scenario!
Now that I see the screenshots this might be easier then you think and I have already implemented something similar on an internal application that I have built. It does rely on the fact that each entry in the list is 100% unique.
First of all you will need to bind the search field to a scoped variable and the onchange/onkeypress event will need to perform a partial refresh of a panel that contains both the list and the document portion of the page.
For the list the link on each item should set the value of the same scoped variable used in the search box and clicking the link should be set to run a partial refresh of the document area.
For the document area you will need two panels, the first panel will only display if there is no matching document and the second panel will only display if there is a matching document, you can do this in the rendered section by writing some ssjs that grabs a handle to the db/view and does a dblookup and returns either true or false if the document exists depending on panel your dealing with.
With this setup, when somebody clicks a link or fills out the searchbox the scoped variable will contain a value, the document panels will then check to see if this is a unique value in the view in the db and update themselves to either display the 'no document' panel or the 'document' panel accordingly.
You could add a evaluation script to the entry of your repeat control which checks the size of your repeat control using the method getRowCount() from the component. If this is 1 you could execute a context.redirectToPage("yourpage.xsp?id=yourid",true) this forces the current page to send a redirect request back to the browser and therefore redirects you to the correct page.
All you need to know is which xpage you need to open and which parameters you should use. But these could be retrieved from the content you are iterating over.

Resources