How to write <table> markup without JSF tag libraries (h:datatable or ui:repeat) but still use JSF for controlling page flow - ajax

I have various tables with the following size : 12 columns and up to 1800 rows. It takes 8 seconds to render it to the user. I currently use h:dataTable. I tried ui:repeat to get the row data from a Java List object, managed by JSF. Although this works fine, the 8 seconds to render the table is unacceptable. I'm trying to find other ways to do this, but need to keep JSF as my controller for action buttons on the page. In other words I want to create the 'table markupto send to thepage myselfand then still associate actions onh:commandButtons` to the managed bean methods. Is there a way to do this?
The only ways I can think of is to use jquery or ajax to create the table markup, although I am new to technologies other than JSF for UI development.Maybe then I would somehow pass that to the client for render. The only problem is I don't know how to generate the markup from my list, and second how I would inject it between h:commandButtons that are in my XHTML file currently.
Does any one know how I can solve this without having to completely rip OFF JSF? One main problem I have is that the business requirement that says we can't page the datatable (i.e: Next / Back buttons displaying 100 at a time for example). So, possibly I was thinking I could do this by Ajax calls to the server and get 100 rows at a time after page ready, and append new rows behind the scenes to the user. This would be a "perceived" speed of load, but I don't know how to do this at all.

8 seconds isn't bad for a whopping 1800 rows on 12 columns. 10~100 rows is done in less than a second, right?
Before continuing with this, are you absolutely positive that all those 1800 rows are supposed to be shown at once? Isn't this very user unfriendly? Wouldn't the user have to need Ctrl+F to find the information it is looking for? Isn't that annoying? Why don't you introduce filtering (a search field) and pagination exactly like as Google is doing to present the zillion of results in a sane and user friendly manner?
Anyway, you could consider using "On-Demand data" option of PrimeFaces <p:dataTable>, wherein the data is loaded by ajax during scrolling via <p:dataTable liveScroll="true">. See also the showcase example. No homegrown code nor manually fiddling with jQuery necessary. PrimeFaces has done it all under the covers.
It you don't want to use PrimeFaces for some reason, then you could consider using OmniFaces <o:componentIdParam> in combination with some jQuery "live scrolling" plugin. See also the last example in its (snapshot) showcase page for a kickoff example (which should easily be adapted to be triggered by hitting the scroll bottom instead of by clicking).

Related

Ajax Load Vs Pagination

Is there a 'right' way to load lists of data/classifieds/articles on a web page, I'm currently loading 8 items via an AJAX request with a view more option at the bottom of these 8 items which once clicked will load the next 8 items and so on until there are no more new items to display.
I was looking around and there is an almost 50/50 split between Ajax loading and pagination listing for data depending on what website you look at. I'm wondering is it easier for a user to use one or the other or is it all the same these days and it's just down to me as the developer to decided?
I know that if I go down the pagination route it removes the overhead of an javascript or jquery needed to be used which is a negligible difference.
Technically it doesn't matter either way to me as I've implement both options before numerous times.
This is more a question of user experience then a coding issue.

AngularJS performance with many custom directives

For this specific project, my team and I are thinking of leveraging the power of AngularJS directives and use them to build custom elements specific to our project, and use them like they were real HTML components.
For instance...
Say we have this table where each row is composed with a bunch of information that we get from a request, each row will be repeated with ng-repeat. Inside each row we will have multiple custom buttons with the same custom behavior. This button will also be used across different modules/pages on the website and not only on this specific table.
Our first thought was to use 2 directives, one for the table row and one for the button. The idea is that these are custom components/elements with custom attributes to define the custom behavior of the element. This would allow us to have a really nice modular application where each component is developed and unit-tested individually. Our HTML would also be easy to ready and understand.
Does this sound good?
Now, what about performance issues? Could we encounter big issues with this approach if, say we have a table with 100 of those rows and 5 of those buttons per row. Could this be big a problem if those rows/buttons had a couple of bindings to update information each X seconds?
The father of Angular Misko Hevery has this to say about performance and data-binding:
How does data binding work in AngularJS?
But in short like he says as long as you dont have more than 2000 data-bound items per page performance wont be an issue...

COLDFUSION CFGRID Datapass with a post

I have a bit of a unique challenge today. I have a client that wants to be able to search for multiple items based on inserts into a cfgrid. Suppose we have the following web form:
A Country selection dropdown
A State Selection dependent AJAX dropdown
A city Selection dependent AJAX dropdown
An ADD Button
----------------------------------------------------
A CFGRID that will populate a row with selections when the user clicks the add button
----------------------------------------------------
And finally, a CLEAR button, and a GO button on the bottom.
The resulting page will then query the database and get some statistics about the cities selected. So, suppose an individual picks USA > Arizona > Scottsdale and USA > Arizona > Flagstaff. The grid below the options will 'save' each selection and reset to their default options, waiting for a user to pick additional options or click on 'GO'.
The resulting page will then generate columns that list some statistics about the communities and highlight the 'best of' between each selected community.
Each time a user selects the ADD button (assuming three criteria are selected) I want the information to be added into a CFGRID that displays the options selected. Then, After the user selects at least one country/city/state option, have all of the data in the CFGRID get passed to another page that does a query from the data selected. In theory, the user could pick as many communities as they want, assuming they are willing to let the database sludge through enough data to get what they want and wait through a 'loading' screen to get it.
I'm having these challenges, in no particular order:
- I have an HTML grid that I must use per client spec (No Java or Flash, must be HTML)
- I have no idea how to get the selected options into the CFGRID. I assume there is some JavaScript I can write that uses some sort of AddRow function to add data into the grid with the add button but cannot seem to find how to it on the interwebs
- After we conquer the above challenge, how do I pass the data from the grid into the results page? I thought about passing one big string or a structure, but I'm not sure how to do that through the URL or posting, nor how to get the data out of the grid. I wonder if I am better off coding some sort of string that gets passed from the options page to the results page with a get method instead of dealing with the stuff in the CFGRID and have the CFGRID serve only as a 'dummy' display container.
- Finally, after the pass is complete, I would need to loop through through the structure and perform a CFQUERY or CFSTOREDPROC on each row of data, then get the statistics I need to display on the results page. I assume this would depend on how I am getting the data from the options selection page to the results page.
THANK YOU ALL!
CFGRID is great to start, but it can be b*tch to customize and extend... Have you tried editable CFGRID with bind? See how far off it is from what you want first. If it turns out to be very far, then you might want to go for a jqGrid and code up some jQuery.
To start, read Using HTML grids and make the cfgrid editable.
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7a01.html#WSc3ff6d0ea77859461172e0811cbec22c24-72e0
Once you got that working, look at these provided JS functions that you can use with CFGRID
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WS0ef8c004658c1089-6262c847120f1a3b244-8000.html
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSd160b5fdf5100e8f-4439fdac128193edfd6-7f5f.html
If you still demand a bit more, you might need to dig into the underlying ExtJS component. At that point I would rather use jqGrid
I found out that the best way to handle this was by using a SerializeJSON call and a Deserialize JSON call back and forth. By using JavaScript notation we are able to pass a complex JavaScript object (array) between one page and another. This has the value add of not having to worry about sessions timing out and making URLs clickable from one solution to the next.

Is it better to use ajax pager or plain post back?

I'm creating a pager for grid data. Basically, I can do it in two ways: when user clicks on a page number, load grid data by using ajax call, or, post back to server (GET or POST) and use query string parameters (or POST variables) to know which page to display. With both methods, sorting of grid items must be persisted.
What is better considering performance and SEO and why?
-- UPDATE --
I need pros and cons for both approaches. I know this is somewhat discussion rather than question, but I need your experiences.
Also, when using ajax, it is not only SEO that I'm wondering about. Will browser's back button behave as expected?
Why not do both.
Have the grid load with SEO friendly anchor GET links then implement some JavaScript to convert them to AJAX calls.
People without JavaScipt (like spiders) can then still navigate around while fancy people will get the enhanced AJAX experience.
With AJAX you can alter history and make the back button work as expected.
Your grids are loaded via AJAX? and you are worried that SEs won't pick them up?
What you can do to get your content indexed is to:
use segmented URLS like CodeIgniter and WordPress instead of query strings. SEs will (supposedly) see them as subfolders.
Instead of loading everything in AJAX, grid data can also be represented as tabular data. What you can do is to load the tabular format for the static page, then with JS, you can replace the table with your grid.
say for example i want to load sports stats, mysite.com/sports/stats should give me tabular data when JS is off, and if i had JS, that data is replaced with the grid.

jsp dynamic gui

i am asking myself if it is possible to somehow create a dynamic gui in jsp. So that i could have something like a dropdown menue for the country and based on what i have selected in that window a dropdown menue for cities, without reloading the jsp page. Or, in a dialog with multiple input lines, to be able to add an additional line with a button, again without reloading the whole page. In the first case the cities information would be in a database, in the second the information provided would be stored at the end in a database, so i cant just use java script (and don't really want to).
At a minimum, you would need to utilize JavaScript to implement what you want. Most would implement it the way Tim describes in his first paragraph.
Set up two .JSP's:
The first contains your main form with the country drop-down menu. Some JavaScript on the first .JSP triggers an AJAX request to a second .JSP. The second .JSP accepts a country-ID parameter and uses a servlet to query your DB for a list of cities, then renders that data. Once the request returns, the JavaScript in your first .JSP inserts the list of cities into a new drop-down menu.
This may seem complex, but several JavaScript libraries exist to assist you with this task. Look into jQuery or Dojo.
To update the page without posting back the whole page, the browser would use ajax. Using a database does not eliminate ajax. Ajax calls server code that digs your data out of the database.
Regardless, to do what you want, without writing your own javascript, look at GWT (Google Web Toolkit). You right ajax applications in Java that generates the javascript for you.

Resources