jsf edit rows, database performance - jsf

i am new to JSF and i followed an online sample to take the edit data table as follows. May i know is this the good practice because i doubt that when the user the save the table, it will update every rows in the database thus it will causes the slow performance issue right?by the way, is JSF come with auto ajax? or it have to depend on jsf library like richfaces, primefaces and etc.

when the user the save the table, it will update every rows in the database
Instead of saving all the elements of the list, it's better to create another list with the elements that have been edited and then save the filtered list. This way you are only updating the edited elements, not all elements.
is JSF come with auto ajax?
You can add AJAX functionality to standard JSF components with the <f:ajax> tag. See http://www.jsftoolbox.com/documentation/help/12-TagReference/core/f_ajax.html.

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.

filtering/searching on a repeat control

In my application, i would like to replace a viewpanel with a repeat control.
However, part of the functionality is there is a UI aspect that allows users to select certain fields (that correspond to the view), and only display the documents that match. The view is doing a filter that allows users to select aspects of the view to create a search (the code is under search of the view) that allows the view panel to be updated with the results of the search.
one of the things that is curious is that the viewpanel has a value of "#{javascript:view2}" vice an actual view name.
The viewpanel defines the search view and the ...
I'd like to be able to apply that same functionality to the repeat control. I don't see those attributes on the repeat control... Any pointers? Its been a while since i've worked with xpages... long enough that I've forgotten a lot already....
TIA !
Read this blog post I did a while back, it should explain what you need.
The view panel doesn't filter anything, it just displays rows from a datasource, same as a repeat control. Indeed you can add components to a ViewPanel's column, pulling from the current row by adding a var property to the dominoView datasource.
The view is bound to #{javascript:view2} (which would be better done by binding to #{view2} - there's no need to call SSJS here). view2 is a dominoView datasource somewhere on your page. The datasource is a wrapper that has properties to capture the settings for filtering and searching that you want to do. At runtime, they are calculated and changes the ViewEntries in the datasource.
Finally there's is the underlying Domino View object available also to LotusScript. This holds and will always hold all entries. The dominoView datasource queries that using the filtering and searching properties and retrieves a ViewEntryCollection or a ViewNavigator.
So whether you use a View Panel, Repeat Control, Data View or whatever else, those are just components to visually represent a collection of ViewEntries or Documents. All can be bound to a dominoView datasource. Where repeat controls and Data Views give you extra power is you can bind them to any kind of collection, not just a dominoView datasource (e.g. DocumentCollection, ViewEntryCollection, multi-value field, Java collection, etc).
I often find that doing the searches in Java and then passing the results to the repeat as a List work better and allow more options. I can get all the information I need in Java and load that into a Map or Tree. This gives me the ability to do custom sorting in the Java class and also to combine data from other views/databases easily. Since the data is now in memory it gets reloaded fast. The only thing you have to watch for is the size of the data. If you have a view with many entries (10K?) you might not want to load everything into memory...
Howard
I'm not sure if you've found a solution yet, but consider using jQuery dataTables. Oliver Busse wrote a very detailed blog post about integrating dataTables into XPages.
To get the specific formatting, I used a repeat control to include the "td", "tr" and "thead" attributes Oliver listed in his blog post.

Storing properties of a custom component in session scope or bean

I've written a new back-end Java component (extending UIComponentBase) as an alternative for the ExtLib Application Layout control. The control needs to show a collection of data that is looked up from another Notes application. The data is user dependant and doesn't change from page to page so, to avoid repeatedly doing a lookup to the other application, I want to store it in the session scope. (Note that because this is a layout control, there will only ever be one per page.)
I know I could use a session-scoped maanged bean (and have done in previous iterations) but the data only needs to be used in this control and shouldn't be used elsewhere on the page which it could be with a bean. So my question is, what's the best practice approach I should take here? Should I just directly store the data in the sessionMap or am I missing a trick with the component stateHolder? Or am I stuck with using a bean?
Thanks
(Edited for clarification)
It looks like you're talking about your own back-end Java components rather than Custom Controls within a single NSF.
I'm not sure at what level, when you write your own native XPages components, the properties are cached by the stateHolder when calling saveState(). I would presume no higher than View, for the reasons Frantisek says, that otherwise it would be unclear which instance to update if you had multiple on one XPage but one on another. It couldn't update both at the same time on the same page, so I would guess that each is a separate instance. As a result, the same component on multiple pages would be a separate discreet instance.
But there's nothing stopping you, in specific setters of the component, writing to sessionScope as well as the private property, and then doing the reverse on the getter. I'm not sure if you'd want to try the internal property before trying sessionScope or vice versa. It would depend how you wanted to handle the situation of the same sessionScope being updated from multiple pages (if the collection could change).

JSF 2 - Dynamically added component's ids are not retained on postback

I have a facet within a component within which i add components dynamically using
UIComponent c = new UICustomComponent();
c.setId("someIdGeneratedDynamically");
facet.getChildren().add(c);
But on postback, when i iterate over this list, i realize that the components are present but their ids are different from the ones i specified earlier. (more specifically, these ids are of the form "j_id9, j_id10" etc)
I debugged a bit of code in StateManagementStrategyImpl and realized that they are deliberately not storing the component ids while saving the view.
My question is, why doesn't JSF store the component id?
To answer your question stated at the end: in RestoreView phase, JSF rebuilds requested view from the template file(s). It is assumed components always receive the same ids as long as the templates don't change. The state is saved using clientIds as keys. If you modified the clientId programmatically it would be impossible to restore the state properly: the recreated component would have the original id and its state would be stored under another (modified) id. That's why it doesn't "store" clientId, it's that thing that's expected to remain constant and allows matching the recreated component with its state from the previous request.
I believe this behavior applies only to components created from the templates. JSF has a dedicated mechanism to handle programmatically added components and I would expect this mechanism to deal with clientIds as expected.

Data flow between views in JSF 2

I'm currently building my first JSF 2 application and I have some questions regarding flow of data between views.
Background
The application keeps track of competences of IT-consultants. To illustrate my questions, I will just describe a small part of it. A Competence entity has a many-to-one relation to a Area entity, putting the different competences in groups. I have views to handle these: Competence.xhtml, EditCompetence.xhtml and EditCompetenceArea.xhtml. These are backed up by a ManagedBean, AdminCompetenceController.
Competence.xhtml lists all Areas in a table, and lists all Competences in an Area if the user clicks on its row. It also has a new-button for Competences and Areas, and an Edit-button for each Competence and Area. these leads to EditCompetence.xhtml and EditCompetenceArea.xhtml respectivly, where the user can fill in information about a Competence or and Area.
Questions
What is the recommended way to handle flow of information between these pages? For example: EditCompetenceArea.xhtml needs to know which Area it should edit (or if it should make a new one). Should I have one backing bean per view or one for all of them? Should it be Session scoped and keep track of the selected Area/Competence with variables? Or should it be View scoped and send the id of the selected object with viewParams? Is it even possible to use Request scope? I've tried several of these and have run into practical problems with each method.
Is it possible to use viewParam to transfer information between views using different backing beans?
Is it possible to use viewParam with a Request scoped backing bean? The data seems to disappear from the bean before I can use it in the postback.
Also, if anyone can recommend any reading material (preferably free, online) regarding more general design patterns rather than specific smaller problems in JSF 2, I would really appreciate it.
To retain data in conversations with the same view, put the bean in view scope. The data will get lost after you navigate to a different view.
To retain data in conversations with different views, either put the bean in session scope to keep it alive among all requests/views, or use <h:inputHidden>, <f:setPropertyActionListener>, etc to retain request scoped data in subsequent request.
In your particular case, I'd go with single main #ViewScoped bean and a single CRUD view wherein the display table and the edit form is included/rendered conditionally.

Resources