Posted by Tom (Guest)
on 18.08.2006 17:32
hi, I have some questions.

i'm trying to emulate the LiveGrid in the same way as the movie 
database- as from the tutorial, but i want to get the data from the 
resultset that was created through the oracle sql queries. how do i go 
about doing it?

also, in the livegrid tutorial
there is this line inside the table id data_grid

<logic:iterate id="reports" 
collection="<%=GetMovieTableContentAction.getMovies(request) %>" 
lenght="<%= "" + pageSize %>" type="org.openrico.demos.beans.Movies">

what is GetMovieTableContentAction method, and where is it? is it inside 
the getMovietableContent.do?


thanks
Posted by Chris Latimer (Guest)
on 21.08.2006 14:56
I'm working through the same problem that you are right now...  The 
tutorial is less than comprehensive to put it midly.  The technology is 
impressive, but unfortunately there's no documentation, so you're kind 
of on your own for getting things to work.  One thing you'll notice is 
that the tutorial is outdated because it is written using Struts as the 
example, but the OpenRico site is in RoR now, so the struts URL they 
tell you to try in your browser won't work.

Basically, from what I can tell, the server side implementation is up to 
you to figure out and design.

The most useful approach I've found so far is to look at the page source 
for the demo page and you'll see that they define a javascript method 
updateHeader that gets called when someone scrolls on the table.  Follow 
through the JavaScript, and you'll start to piece together a vague 
picture of how the interactions would have to occur to get it working. 
I'm still in the vague stages of getting it implemented, but as I make 
progress I'll post anything I can to help.

If you do the same that would be great because it sounds like we've got 
about the same problem.  I'm connecting to an Oracle db using Java with 
Struts for my MVC layer.   My approach at the current point is to take 
the ResultSet, put it into a Collection, and store it in the session. 
Then when my updateHeader method is called I'm returning the XML 
response to the live grid.  This is the part I'm working through now. 
I'll let you know if I make any progress that would help you out.

Chris
Posted by Chris Latimer
on 22.08.2006 14:47
Okay Tom,

I got this thing working with Java/Struts, here's the jist:

I've got a Struts action that gets my entire data set, and puts it into 
a Collection of objects from my backend database.  I get the entire 
Collection up front right now and store it in the session.  I then get a 
subset of that Collection and make it available in the 
HttpServletRequest object.  If it's successful, I 
ActionMapping.findForward to a JSP I have that looks a lot like the 
OpenRico LiveGrid demo page in terms of the JavaScript, LiveGrid 
definition, and div blocks surrounding the header and grid tables.  I 
use logic.iterate to go through the subset of my collection and populate 
the rows of the table.

I then have a second struts action that I am using as the handler, I use 
this URL in my LiveGrid definition.  This action will get my Collection 
out of the session and build a subset Collection by using the values 
passed to me in the request.getParameter("page_size") and 
request.getParameter("offset").  So basically I make a collection that 
has all the values from Collection.get(offset) to Collection.get(offset 
+ page_size). I then make that Collection available to the request, and 
I have another JSP that creates the <ajax-response> XML.  Make sure you 
put the <%response.setHeader("Content-Type", "text/xml");%> in your JSP. 
I tried to put that line in the Struts action, but for some reason it 
only worked when I put it in the JSP.  Not sure what the issue is 
there...

It was a bit tricky to get working, but if you post a reply with any 
problems you're having I'll help you out if I can... Thanks.

Chris
Posted by Tom (Guest)
on 24.08.2006 16:47
hi Chris,
     thanks for your input. your feedback helps alot, but then i'm 
bogged down by the requirements. My dataset is very big (over 10k 
records), and my goal is to not get the entire dataset at once and dump 
it into a collection...taking up all the memory. my goal is to by using 
the livdGrid, i can find out the range within the table as one scroll 
through the table. like when it first opens, it shows the FIRST ten 
records....but then as i scroll down it shows 2-11th records...then 
3-12th records.....etc etc......

so at first, when table is displayed, i would call a function that get 
the first 20 records from the database, dump them into a collection, and 
show 10 records in the table.....and then as user scroll down, i display 
the remaning records, but once the scroll bar reaches to the 20th 
record, the livdGrid would call the same function to get the next 20 
records and dump/replace previous records in the collect set, and 
dispaly next 20 records as needed.

so by doing this way, i never have to allocate a huge amount of memory 
to hold the records, only as needed. since these records are for display 
purpose only, it's not important to know what records were being called.

i'm beginning to think that perhaps LiveGrid doesnt support this 
functionality.

thanks
tom
Posted by Tom (Guest)
on 24.08.2006 17:13
Also, is there anyway to use LiveGrid without using Struts in JSP?
Posted by Chris Latimer
on 25.08.2006 14:36
Yeah, I believe you could do the whole thing without the Struts layer in 
there.  Just instead of pointing the handler URL to a struts action, 
you'd point it to the JSP that creates the XML.

Unfortunately, Oracle is a little bit lacking when it comes to getting a 
particular subset (say rows x through y) in an ordered query.  There is 
a way to do it, a pretty cumbersome way albeit, that would let you do 
pretty much what you want to do.  See the article here from AskTom about 
limiting records returned and pagination.

http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html

Here's the basic query structure if you want to cut to the chase...

select *
  from ( select /*+ FIRST_ROWS(n) */
  a.*, ROWNUM rnum
      from ( your_query_goes_here,
      with order by ) a
      where ROWNUM <=
      :MAX_ROW_TO_FETCH )
where rnum  >= :MIN_ROW_TO_FETCH;

Basically, you'd just use (offset + page_size) as the :MAX_ROW_TO_FETCH 
value, and offset as the :MIN_ROW_TO_FETCH value.

You'll also need an initial select count(*) query when the page loads to 
get the total number of rows to know the size you want your table to be. 
I think that would get you pretty much everything you want.

Good luck!

Chris

Posted by Chris Latimer
on 25.08.2006 17:58
I switched my implementation to use the pagination query above because 
I'm getting about 5k rows returned in my initial query and it was taking 
about 30-45 seconds to get a response back.  This way works a lot 
better, the initial load is happening in about 7 seconds, and 
incremental XML comes back in about 3 seconds.  I'd like to get it even 
quicker, but I'm fairly content with that performace.

The incremental isn't as fast as it was already having the Collection 
stored in the session, but the initial load is a lot faster and the 
solution is more scalable not storing all that data in the session.  The 
first rows hint really speeds it up, without it in there the incremental 
query was taking about 5-6 seconds to return, and the initial was taking 
around 15 seconds.  Much better now.

Chris
Posted by Tom (Guest)
on 31.08.2006 13:04
hi Chris
    thanks for all yor feedback and suggestion. i got the LiveGrid to 
work without using struts.

    basically, i passed a servlet (url) to LiveGrid, and the servlet 
calls a java class method to make a sql call to the database to get 
records within specific range.
this is my sql query format:

SELECT ROWNUM, {rest of columns u want}
from table
having rownum between {offset} and {offset+pagesize}
group by rownum, {rest of columns }
order by rownum

then from that the servlet generates a xml document using stringbuffer 
and write out through response handler of the servlet.

the only problem is that when i have a table of 1+ million records, the 
query takes a long time to compute (5 million records takes 25-30 
seconds)

i'm having my database guru at work to make it more efficient. i've also 
forwared her your sql query suggestion to see if she can modify it to 
our needs.


thanks!
tom
Posted by dries dries
on 13.11.2006 15:28
Hello,

would someone be so kind to post in there action?
following is a bit unclear to me:
-----------
  I get the entire
Collection up front right now and store it in the session.  I then get a
subset of that Collection and make it available in the
HttpServletRequest object.  If it's successful, I
ActionMapping.findForward to a JSP I have that looks a lot like the
OpenRico LiveGrid demo page in terms of th
----------

Thanks !
Dries
Posted by Phil Shanks
on 27.12.2006 02:47
I don't know what this would look like with an Oracle backend, but just
for the sake of rapid prototyping I did the query in a single JSP using
JSTL tags against a MySQL database.  I simply worked backwards from the
repsonse structure (this is for a sermon database that I'm building for 
my church). I started out using the "LIMIT" clause in my SQL, but 
quickly switched to using the maxRows and startRows attributes of the 
<sql:query> tag.

I know this isn't proper MVC, but it serves the purpose of getting to a 
working demo. For my purposes, this may even be more than sufficient for 
production. The far bigger headache is the complete absence of 
documentation for fine tuning in the rico.js API.

If you have a huge amount of data, probably it is better to query for a 
partial ResultSet (including buffering, which LiveGrid does for 
client-side performance reasons), rather than to store an entire copy of 
the entire set for each session (that's a lot of session memory wasted). 
You need to base your design decision on the amount of traffic and 
visitor behavior you expect. For example, if you have a million plus 
rows, it is highly unlikely that anyone would page through all of them. 
Give them a way to narrow down the search, and you will have a much more 
workable solution.

Now, going off on a tangent... I sometimes wish that Javascript 
developers would treat the lack of documentation as a BUG, with the same 
priority as other bugs... I would gladly trade a new feature/refinement 
or three for some workable documentation. After all, what good are the 
features if I can't figure out how to get the leverage?  I'd do it 
myself if I had time. Maybe I can if I can manage to get my own app 
working decently with openrico.

Anyway, all grousing aside, kudos to the openrico developers for a nifty 
alternative to paging! Perhaps documentation will come in the near 
future. I will see what I can contribute.

ajaxResponse.jsp:

<?xml version="1.0" encoding="UTF-8"?>
<%@page contentType="text/xml" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<ajax-response>
   <response type="object" id="data_grid_updater">
      <rows update_ui="true">
         <sql:query maxRows="<%= 
Integer.parseInt(request.getParameter("page_size")) %>"
                    startRow="<%= 
Integer.parseInt(request.getParameter("offset")) %>"
                    var="result">
            SELECT _title, _scrptr, _date, _dur, _spkr FROM vdisplay 
ORDER BY _date DESC
         </sql:query>
         <c:forEach var="row" items="${result.rows}">
            <tr>
               <td><c:out value="${row._date}"/></td>
               <td><c:out value="${row._title}"/> (<c:out 
value="${row._dur}"/>)<br />
               <c:out value="${row._scrptr}"/></td>
               <td><c:out value="${row._spkr}"/></td>
               <td>none</td>
            </tr>
         </c:forEach>
      </rows>
   </response>
</ajax-response>
Posted by tom chung
on 22.01.2007 19:08
I'm using LiveGrid Plus and i've noticed that when i use a very large 
table (over 5 million records), the scrollbar would not work (not 
activated) when i use FireFox. With IE, the scrollbar works fine.

has anyone have that problem?

thanks
Posted by Chris Latimer
on 22.01.2007 20:05
I have not encountered that problem.  I'd recommend limiting the results 
to a more manageable number; i mean, seriously... will a user really 
look at all 5 million results?

If that's not an option, please post your code and I'll see if I can 
reproduce it...
Posted by Rangaram Devarajan
on 22.03.2007 05:42
hi ,
    i don't know what code u ve to write in the updateHeader method in 
opts onscroll. somebody plz help me as soon as possible.
   Thanks in advance
regards,
ranga
Posted by John Cartwright
on 29.03.2007 00:02
Hello All,

I had the same issues w/ a large dataset in oracle.  I ended up used one 
of their window functions in a servlet and it seems to work pretty well. 
I just calculate the end record based on the offset and page_size 
parameters in each request.

select
>   OBJECTID,WDEPTH,YEARMODA,CRUISE,FACILITY
> from
>   (select
>     row_number() over (order by OBJECTID) as rn,
>     OBJECTID,WDEPTH,YEARMODA,CRUISE,FACILITY
>   from
>      TEST.TEST_DATA
>   where
>      FACILITY = 'LDEO' and
>      WDEPTH  < 10
>   ) x
> where
>   rn between 6 and 10

-- john
Posted by Cédric Ced
on 16.04.2007 00:33
Hello,

I'm trying to setup my first livegrid using struts. I don't how to write
the request handler action. Could you please post the piece of code you
are using ?

Thks a lot,

Cédric
Posted by Chris Latimer
on 16.04.2007 14:25
I used a JSP to generate the ajax-response.

Then used a Struts action to get my data and pass it to the JSP.

If you look at:

http://www.openrico.org/rico/ajax_livegrid_content?id=grid_data&offset=0&page_size=2

You can see the XML generated for the demo. Basically just reverse 
engineer your Struts Action/JSP to generate similar XML for you 
application.

Chris
Posted by Joseba Irujo
on 30.05.2007 10:10
I think this code is not being executed correctly in the onload of the
jsp, The onload is executed correctly but I think that this not:

liveGrid = new Rico.LiveGrid( 'data_grid', <%= pageSize %>, <%=
totalRows %>,
	'getContenidoListaCanales.do', opts );

What could it be the problem?

I include the rico.js and prototype.js before.

I get to load the first page of the table, but it remains static, it 
never exucutes the action mapped by getContenidoListaCanales.do

Thanks is advance.
J.
Posted by Joseba Irujo
on 31.05.2007 08:04
Do I need to do an special include? Where is the Rico.LiveGrid written,
I need to see if this code is executed, if it does not work because I do
not have a correct parameter or why, please help me!
Posted by Chris Latimer
on 31.05.2007 15:53
How do you have your table defined?  Can you post the code of your JSP?

The LiveGrid is defined inside rico.js.

Chris